diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt index e05e1ba08..afeafec01 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/MainActivity.kt @@ -25,7 +25,6 @@ import androidx.activity.viewModels import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -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.MainScreen @@ -51,11 +50,8 @@ class MainActivity : ComponentActivity() { } @Composable -fun isDarkTheme(getTheme: () -> Theme?): Boolean { - val settingsViewModel = hiltViewModel() - val appSettings by settingsViewModel.appSettingsFlow.collectAsStateWithLifecycle(null) - +private fun isDarkTheme(getTheme: () -> Theme?): Boolean { return getTheme()?.let { - if (it == Theme.SYSTEM) isSystemInDarkTheme() else it== Theme.DARK + if (it == Theme.SYSTEM) isSystemInDarkTheme() else it == Theme.DARK } ?: isSystemInDarkTheme() } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt index a9b995fa4..4e4a316e1 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/theme/Theme.kt @@ -26,6 +26,7 @@ import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color +val LocalIsDarkMode = staticCompositionLocalOf { false } val LocalCustomTypography = staticCompositionLocalOf { Typography } val LocalCustomColorScheme: ProvidableCompositionLocal = staticCompositionLocalOf { CustomColorScheme() } val LocalWindowAdaptiveInfo = staticCompositionLocalOf { error("No WindowAdaptiveInfo provided") } @@ -41,6 +42,7 @@ fun SwissTransferTheme( LocalTextStyle provides Typography.bodyRegular, LocalCustomColorScheme provides customColors, LocalWindowAdaptiveInfo provides currentWindowAdaptiveInfo(), + LocalIsDarkMode provides isDarkTheme, ) { MaterialTheme( colorScheme = if (isDarkTheme) DarkColorScheme else LightColorScheme,