Skip to content

Commit

Permalink
Use theme stored in realm
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Sep 23, 2024
1 parent 3c7c710 commit 472f285
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
import com.infomaniak.swisstransfer.ui.screen.main.settings.SettingsViewModel

val LocalCustomTypography = staticCompositionLocalOf { Typography }
val LocalCustomColorScheme: ProvidableCompositionLocal<CustomColorScheme> = staticCompositionLocalOf { CustomColorScheme() }

@Composable
fun SwissTransferTheme(
darkTheme: Boolean = isDarkTheme(),
settingsViewModel: SettingsViewModel = hiltViewModel<SettingsViewModel>(),
darkTheme: Boolean = isDarkTheme(settingsViewModel),
content: @Composable () -> Unit,
) {
val customColors = if (darkTheme) CustomDarkColorScheme else CustomLightColorScheme
Expand All @@ -47,10 +52,11 @@ fun SwissTransferTheme(
}

@Composable
fun isDarkTheme(): Boolean {
// rememberMutableStateOf
// TODO check in realm. If system, isSystemDark, otherwise,
return isSystemInDarkTheme()
fun isDarkTheme(settingsViewModel: SettingsViewModel): Boolean {
val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null)
return appSettings?.let {
if (it.theme == Theme.SYSTEM) isSystemInDarkTheme() else it.theme == Theme.DARK
} ?: isSystemInDarkTheme()
}

object SwissTransferTheme {
Expand Down

0 comments on commit 472f285

Please sign in to comment.