Skip to content

Commit

Permalink
added dynamic color change
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 30, 2024
1 parent 24e3b42 commit 0480268
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
5 changes: 3 additions & 2 deletions composeApp/src/commonMain/kotlin/dev/datlag/aniflow/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ internal fun App(
appSettings.color
}.collectAsStateWithLifecycle(null)
val seedColor = remember(savedColor) { savedColor?.toComposeColor() }
val allLoading by StateSaver.Home.isAllLoading.collectAsStateWithLifecycle(true)
val allLoading by StateSaver.Home.isAllLoading.collectAsStateWithLifecycle(StateSaver.Home.currentAllLoading)
val tempColor by StateSaver.temporaryColor.collectAsStateWithLifecycle()

DynamicMaterialTheme(
seedColor = seedColor,
seedColor = tempColor?.toComposeColor() ?: seedColor,
animate = !allLoading
) {
CommonSchemeTheme(animate = !allLoading) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package dev.datlag.aniflow.other

import androidx.compose.ui.graphics.Color
import dev.datlag.aniflow.anilist.AiringTodayStateMachine
import dev.datlag.aniflow.anilist.PopularNextSeasonStateMachine
import dev.datlag.aniflow.anilist.PopularSeasonStateMachine
import dev.datlag.aniflow.anilist.TrendingAnimeStateMachine
import dev.datlag.aniflow.anilist.state.SeasonState
import dev.datlag.aniflow.settings.model.AppSettings
import dev.datlag.tooling.compose.ioDispatcher
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlin.time.Duration.Companion.milliseconds

data object StateSaver {
var sekretLibraryLoaded: Boolean = false
val temporaryColor = MutableStateFlow<AppSettings.Color?>(null)

fun updateTemporaryColor(value: AppSettings.Color?) = temporaryColor.update { value }

data object List {
var homeOverview: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import androidx.compose.material3.*
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand Down Expand Up @@ -48,6 +45,8 @@ import dev.datlag.aniflow.settings.model.AppSettings
import dev.datlag.tooling.compose.onClick
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.stringResource
import io.github.aakira.napier.Napier
import kotlinx.coroutines.flow.update

@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3WindowSizeClassApi::class, ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -105,7 +104,18 @@ fun SettingsScreen(component: SettingsComponent) {
}
item {
val selectedColor by component.selectedColor.collectAsStateWithLifecycle(null)
val useCase = rememberUseCaseState()
val temporaryColor by StateSaver.temporaryColor.collectAsStateWithLifecycle()
val useCase = rememberUseCaseState(
onFinishedRequest = {
StateSaver.updateTemporaryColor(null)
},
onCloseRequest = {
StateSaver.updateTemporaryColor(null)
},
onDismissRequest = {
StateSaver.updateTemporaryColor(null)
}
)
val colors = remember { AppSettings.Color.all.toList() }

OptionDialog(
Expand All @@ -117,8 +127,15 @@ fun SettingsScreen(component: SettingsComponent) {
imageVector = Icons.Filled.Circle,
tint = it.toComposeColor()
),
selected = it == selectedColor,
titleText = stringResource(it.toComposeString())
selected = if (temporaryColor != null) {
it == temporaryColor
} else {
it == selectedColor
},
titleText = stringResource(it.toComposeString()),
onClick = {
StateSaver.updateTemporaryColor(it)
}
)
},
onSelectOption = { option, _ ->
Expand Down

0 comments on commit 0480268

Please sign in to comment.