Skip to content

Commit

Permalink
Initialize the actual list pane for achievements UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Omico committed Jun 7, 2024
1 parent 3cc5362 commit d40ee42
Show file tree
Hide file tree
Showing 23 changed files with 301 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ plugins {

kotlin {
sourceSets {
all {
languageSettings {
enableLanguageFeature("ContextReceivers")
}
}
commonMain {
dependencies {
implementation(project(":wwm-core-resources"))
implementation(project(":wwm-core-ui"))
}
}
Expand Down
2 changes: 0 additions & 2 deletions wwm/core/application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api(project(":wwm-core-data"))
api(project(":wwm-core-feature-achievements"))
api(project(":wwm-core-resources"))
api(project(":wwm-core-ui"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package dev.omico.wwm.application

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import dev.omico.wwm.feature.achievements.AchievementsScreen
import dev.omico.wwm.ui.WwmContainer

@Composable
fun WwmApp() {
MaterialTheme {
WwmContainer(
circuit = wwmCircuit,
component = remember(::WwmApplicationComponent),
initialScreen = AchievementsScreen,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 Omico. All Rights Reserved.
*/
package dev.omico.wwm.application

import com.slack.circuit.foundation.Circuit
import dev.omico.wwm.data.AchievementsRepository
import dev.omico.wwm.feature.achievements.addAchievementsFeature
import dev.omico.wwm.ui.WwmUiComponent

class WwmApplicationComponent : WwmUiComponent {
override val circuit: Circuit by lazy(::provideCircuit)

override fun provideCircuit(): Circuit =
Circuit.Builder()
.addAchievementsFeature()
.build()

override val achievementsRepository: AchievementsRepository by lazy(::provideAchievementsRepository)
}

This file was deleted.

11 changes: 11 additions & 0 deletions wwm/core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
plugins {
id("wwm.kotlin.multiplatform")
}

kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":wwm-core-foundation"))
implementation(project(":wwm-core-resources"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2024 Omico. All Rights Reserved.
*/
package dev.omico.wwm.data

import dev.omico.wwm.resources.model.game.WwLocale
import kotlinx.coroutines.flow.Flow

interface AchievementsRepository {
val achievements: Flow<WwmAchievements>
suspend fun load()
suspend fun reloadAchievements()
suspend fun reloadAchievementCategories()
suspend fun reloadAchievementGroups()
suspend fun reloadMultiText(locale: WwLocale)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 Omico. All Rights Reserved.
*/
package dev.omico.wwm.data

import dev.omico.wwm.resources.model.game.WwAchievementCategories
import dev.omico.wwm.resources.model.game.WwAchievementGroups
import dev.omico.wwm.resources.model.game.WwAchievements
import dev.omico.wwm.resources.model.game.WwMultiText

data class WwmAchievements(
val achievements: WwAchievements = emptyList(),
val achievementCategories: WwAchievementCategories = emptyList(),
val achievementGroups: WwAchievementGroups = emptyList(),
val multiText: WwMultiText = emptyList(),
) {
companion object {
val Empty: WwmAchievements = WwmAchievements()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2024 Omico. All Rights Reserved.
*/
package dev.omico.wwm.data

import dev.omico.wwm.data.internal.AchievementsRepositoryImpl

interface WwmDataComponent {
val achievementsRepository: AchievementsRepository
fun provideAchievementsRepository(): AchievementsRepository = AchievementsRepositoryImpl()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2024 Omico. All Rights Reserved.
*/
package dev.omico.wwm.data.internal

import dev.omico.wwm.data.AchievementsRepository
import dev.omico.wwm.data.WwmAchievements
import dev.omico.wwm.resources.WwmResources
import dev.omico.wwm.resources.model.game.WwAchievementCategories
import dev.omico.wwm.resources.model.game.WwAchievementGroups
import dev.omico.wwm.resources.model.game.WwAchievements
import dev.omico.wwm.resources.model.game.WwLocale
import dev.omico.wwm.resources.model.game.WwMultiText
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine

internal class AchievementsRepositoryImpl : AchievementsRepository {
private val wwAchievements: MutableStateFlow<WwAchievements> = MutableStateFlow(emptyList())
private val wwAchievementCategories: MutableStateFlow<WwAchievementCategories> = MutableStateFlow(emptyList())
private val wwAchievementGroups: MutableStateFlow<WwAchievementGroups> = MutableStateFlow(emptyList())
private val wwMultiText: MutableStateFlow<WwMultiText> = MutableStateFlow(emptyList())

override val achievements: Flow<WwmAchievements> =
combine(
wwAchievements,
wwAchievementCategories,
wwAchievementGroups,
wwMultiText,
::WwmAchievements,
)

override suspend fun load() {
reloadAchievements()
reloadAchievementCategories()
reloadAchievementGroups()
}

override suspend fun reloadAchievements(): Unit = wwAchievements.emit(WwmResources.loadAchievements())

override suspend fun reloadAchievementCategories(): Unit =
wwAchievementCategories.emit(WwmResources.loadAchievementCategories())

override suspend fun reloadAchievementGroups(): Unit =
wwAchievementGroups.emit(WwmResources.loadAchievementGroups())

override suspend fun reloadMultiText(locale: WwLocale): Unit = wwMultiText.emit(WwmResources.loadMultiText(locale))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@
package dev.omico.wwm.feature.achievements

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.slack.circuit.retained.collectAsRetainedState
import dev.omico.wwm.data.WwmAchievements
import dev.omico.wwm.resources.model.game.WwLocale
import dev.omico.wwm.ui.WwmUiComponent

context(WwmUiComponent)
@Composable
internal fun produceAchievementsUiState(): AchievementsUiState {
return AchievementsUiState()
var locale by remember { mutableStateOf(WwLocale.ZH_HANS) }
val achievements by achievementsRepository.achievements.collectAsRetainedState(initial = WwmAchievements.Empty)
LaunchedEffect(Unit) { achievementsRepository.load() }
LaunchedEffect(locale) { achievementsRepository.reloadMultiText(locale) }
return AchievementsUiState(
achievements = achievements,
eventSink = { event ->
when (event) {
is AchievementsUiEvent.ChangeLocale -> locale = event.locale
}
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dev.omico.wwm.feature.achievements
import com.slack.circuit.foundation.Circuit
import com.slack.circuit.runtime.presenter.presenterOf
import com.slack.circuit.runtime.screen.Screen
import dev.omico.wwm.ui.LocalWwmUiComponent

object AchievementsScreen : Screen

Expand All @@ -19,7 +20,9 @@ fun Circuit.Builder.addAchievementsFeature(): Circuit.Builder =
}
addPresenter<AchievementsScreen, AchievementsUiState> { _, _, _ ->
presenterOf {
produceAchievementsUiState()
with(LocalWwmUiComponent.current) {
produceAchievementsUiState()
}
}
}
}
Loading

0 comments on commit d40ee42

Please sign in to comment.