Skip to content

Commit

Permalink
Merge pull request #228 from joreilly/koin_compose_mp
Browse files Browse the repository at this point in the history
pull in Koin Compose MP update
  • Loading branch information
joreilly authored May 17, 2024
2 parents 65b19d3 + a05bcb3 commit 8d20388
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ kotlin {

api(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.composeVM)
implementation(libs.koin.test)

implementation(libs.bundles.ktor.common)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.koin.dsl.module

actual fun platformModule() = module {
single { Android.create() }
single { dataStore(get())}
single { dataStore(get()) }

single<AppDatabase> { createRoomDatabase(get()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import dev.johnoreilly.common.database.AppDatabase
import dev.johnoreilly.common.model.GameFixture
import dev.johnoreilly.common.model.PlayerPastHistory
import dev.johnoreilly.common.model.Player
import dev.johnoreilly.common.model.Team
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
Expand All @@ -30,18 +31,6 @@ class FantasyPremierLeagueRepository : KoinComponent {

val coroutineScope = CoroutineScope(Dispatchers.Default)

// private val _teamList = MutableStateFlow<List<Team>>(emptyList())
// val teamList = _teamList.asStateFlow()
//
// private val _playerList = MutableStateFlow<List<Player>>(emptyList())
// val playerList = _playerList.asStateFlow()

// private val _fixtureList = MutableStateFlow<List<GameFixture>>(emptyList())
// val fixtureList = _fixtureList.asStateFlow()

// private val _gameWeekFixtures = MutableStateFlow<Map<Int, List<GameFixture>>>(emptyMap())
// val gameWeekFixtures = _gameWeekFixtures.asStateFlow()

val leagues = appSettings.leagues

private var _currentGameweek: MutableStateFlow<Int> = MutableStateFlow(1)
Expand All @@ -62,20 +51,20 @@ class FantasyPremierLeagueRepository : KoinComponent {
// TODO surface this to UI/option to retry etc ?
println("Exception reading data: $e")
}

}


private suspend fun writeDataToDb(
bootstrapStaticInfoDto: BootstrapStaticInfoDto,
fixtures: List<FixtureDto>
) {
) {
//store current gameweek
_currentGameweek.value = bootstrapStaticInfoDto.events.firstOrNull { it.is_current }?.id ?: 1
_currentGameweek.value =
bootstrapStaticInfoDto.events.firstOrNull { it.is_current }?.id ?: 1

// store teams
val teamList = bootstrapStaticInfoDto.teams.mapIndexed { teamIndex, teamDto ->
dev.johnoreilly.common.model.Team(teamDto.id, teamIndex + 1, teamDto.name, teamDto.code)
Team(teamDto.id, teamIndex + 1, teamDto.name, teamDto.code)
}
database.fantasyPremierLeagueDao().insertTeamList(teamList)

Expand All @@ -87,7 +76,16 @@ class FantasyPremierLeagueRepository : KoinComponent {
val teamName = teamList.find { team -> team.code == playerDto.team_code }?.name ?: ""
val currentPrice = playerDto.now_cost / 10.0

Player(playerDto.id, playerName, teamName, playerImageUrl, playerDto.total_points, currentPrice, playerDto.goals_scored, playerDto.assists)
Player(
playerDto.id,
playerName,
teamName,
playerImageUrl,
playerDto.total_points,
currentPrice,
playerDto.goals_scored,
playerDto.assists
)
}
database.fantasyPremierLeagueDao().insertPlayerList(playerList)

Expand All @@ -98,12 +96,11 @@ class FantasyPremierLeagueRepository : KoinComponent {

val homeTeamName = homeTeam?.name ?: ""
val awayTeamName = awayTeam?.name ?: ""

val homeTeamPhotoUrl = "https://resources.premierleague.com/premierleague/badges/t${homeTeam?.code}.png"
val awayTeamPhotoUrl = "https://resources.premierleague.com/premierleague/badges/t${awayTeam?.code}.png"

val localKickoffTime = fixtureDto.kickoff_time.toString().toInstant()
.toLocalDateTime(TimeZone.currentSystemDefault())
.toLocalDateTime(TimeZone.currentSystemDefault())

GameFixture(
fixtureDto.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json
import org.koin.compose.viewmodel.dsl.viewModelOf
import org.koin.core.context.startKoin
import org.koin.dsl.KoinAppDeclaration
import org.koin.dsl.module
Expand All @@ -31,7 +32,7 @@ fun commonModule(enableNetworkLogs: Boolean) = module {
single { createJson() }
single { createHttpClient(get(), get(), enableNetworkLogs = enableNetworkLogs) }

single { PlayerDetailsViewModel() }
viewModelOf(::PlayerDetailsViewModel)
single { FantasyPremierLeagueRepository() }
single { FantasyPremierLeagueApi(get()) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ import dev.johnoreilly.common.model.PlayerPastHistory
import dev.johnoreilly.common.model.Player
import dev.johnoreilly.common.viewmodel.PlayerDetailsViewModel
import org.koin.compose.koinInject
import org.koin.compose.viewmodel.koinViewModel
import org.koin.core.annotation.KoinExperimentalAPI


@OptIn(KoinExperimentalAPI::class)
@Composable
fun PlayerDetailsViewShared(player: Player) {

val viewModel = koinInject<PlayerDetailsViewModel>()
val viewModel = koinViewModel<PlayerDetailsViewModel>()

var playerHistory by remember { mutableStateOf(emptyList<PlayerPastHistory>()) }
LaunchedEffect(player) {
Expand Down Expand Up @@ -244,7 +246,7 @@ private fun BarSamplePlot(
series = listOf(barChartEntries.value),
bar = { _, _, value ->
DefaultVerticalBar(
brush = SolidColor(Color(0xFF3179EA)),
brush = SolidColor(Color.Blue),
modifier = Modifier.fillMaxWidth(barWidth),
) {
HoverSurface { Text(value.yMax.toString()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dev.johnoreilly.common.data.repository.FantasyPremierLeagueRepository
import dev.johnoreilly.common.model.GameFixture
import dev.johnoreilly.common.model.Player
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
Expand Down
9 changes: 5 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ ksp = "1.9.23-1.0.19"
coroutines = "1.8.0"
kotlinxSerialization = "1.6.3"
kotlinxDateTime = "0.5.0"
androidGradlePlugin = "8.4.0"
androidGradlePlugin = "8.2.2"
koalaplot = "0.5.3"
koin = "3.6.0-alpha3"
koinCompose = "3.6.0-alpha3"
koinComposeMultiplatform = "1.2.0-alpha3"
koin = "3.6.0-Beta4"
koinCompose = "3.6.0-Beta4"
koinComposeMultiplatform = "1.2.0-Beta4"
ktor = "2.3.9"
slf4j = "2.0.12"
skie = "0.6.2"
Expand Down Expand Up @@ -71,6 +71,7 @@ koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koinCompose" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koinComposeMultiplatform" }
koin-composeVM = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koinComposeMultiplatform" }
koin-test = { module = "io.insert-koin:koin-test", version.ref = "koin" }

ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
Expand Down

0 comments on commit 8d20388

Please sign in to comment.