From 400f3b8a65ed4b5849079c863b208a9f2c3c7ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Mlynari=C4=8D?= Date: Thu, 11 Apr 2024 10:41:34 +0200 Subject: [PATCH] Fix default value Change-Id: I6b77e1c23ad91c1c97f31a705161d444be7913c0 --- .../samples/apps/nowinandroid/MainActivity.kt | 16 ++++++++++------ .../apps/nowinandroid/MainActivityViewModel.kt | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt index 5b10f7ec2..6aef4edf7 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt @@ -35,6 +35,7 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.metrics.performance.JankStats import androidx.tracing.trace +import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository @@ -48,6 +49,8 @@ import com.google.samples.apps.nowinandroid.util.isSystemInDarkTheme import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import javax.inject.Inject @@ -83,8 +86,8 @@ class MainActivity : ComponentActivity() { var themeSettings by mutableStateOf( ThemeSettings( darkTheme = resources.configuration.isSystemInDarkTheme, - androidTheme = false, - disableDynamicTheming = true, + androidTheme = Loading.shouldUseAndroidTheme, + disableDynamicTheming = Loading.shouldDisableDynamicTheming, ), ) @@ -101,8 +104,10 @@ class MainActivity : ComponentActivity() { disableDynamicTheming = uiState.shouldDisableDynamicTheming, ) } + .onEach { themeSettings = it } + .map { it.darkTheme } .distinctUntilChanged() - .collect { newThemeSettings -> + .collect { darkTheme -> trace("niaEdgeToEdge") { // Turn off the decor fitting system windows, which allows us to handle insets, // including IME animations, and go edge-to-edge. @@ -113,15 +118,14 @@ class MainActivity : ComponentActivity() { statusBarStyle = SystemBarStyle.auto( lightScrim = android.graphics.Color.TRANSPARENT, darkScrim = android.graphics.Color.TRANSPARENT, - ) { newThemeSettings.darkTheme }, + ) { darkTheme }, navigationBarStyle = SystemBarStyle.auto( lightScrim = lightScrim, darkScrim = darkScrim, - ) { newThemeSettings.darkTheme }, + ) { darkTheme }, ) } - themeSettings = newThemeSettings } } } diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt index 3715bb8b4..2d22b7d9c 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivityViewModel.kt @@ -71,7 +71,7 @@ sealed interface MainActivityUiState { /** * Returns `true` if the dynamic color is disabled. */ - val shouldDisableDynamicTheming: Boolean get() = false + val shouldDisableDynamicTheming: Boolean get() = true /** * Returns `true` if the Android theme should be used.