Fix default value

Change-Id: I6b77e1c23ad91c1c97f31a705161d444be7913c0
mlykotom/optimize-startup
Tomáš Mlynarič 7 months ago
parent bd508c477a
commit 400f3b8a65

@ -35,6 +35,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import androidx.metrics.performance.JankStats import androidx.metrics.performance.JankStats
import androidx.tracing.trace 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.AnalyticsHelper
import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository 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 dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@ -83,8 +86,8 @@ class MainActivity : ComponentActivity() {
var themeSettings by mutableStateOf( var themeSettings by mutableStateOf(
ThemeSettings( ThemeSettings(
darkTheme = resources.configuration.isSystemInDarkTheme, darkTheme = resources.configuration.isSystemInDarkTheme,
androidTheme = false, androidTheme = Loading.shouldUseAndroidTheme,
disableDynamicTheming = true, disableDynamicTheming = Loading.shouldDisableDynamicTheming,
), ),
) )
@ -101,8 +104,10 @@ class MainActivity : ComponentActivity() {
disableDynamicTheming = uiState.shouldDisableDynamicTheming, disableDynamicTheming = uiState.shouldDisableDynamicTheming,
) )
} }
.onEach { themeSettings = it }
.map { it.darkTheme }
.distinctUntilChanged() .distinctUntilChanged()
.collect { newThemeSettings -> .collect { darkTheme ->
trace("niaEdgeToEdge") { trace("niaEdgeToEdge") {
// Turn off the decor fitting system windows, which allows us to handle insets, // Turn off the decor fitting system windows, which allows us to handle insets,
// including IME animations, and go edge-to-edge. // including IME animations, and go edge-to-edge.
@ -113,15 +118,14 @@ class MainActivity : ComponentActivity() {
statusBarStyle = SystemBarStyle.auto( statusBarStyle = SystemBarStyle.auto(
lightScrim = android.graphics.Color.TRANSPARENT, lightScrim = android.graphics.Color.TRANSPARENT,
darkScrim = android.graphics.Color.TRANSPARENT, darkScrim = android.graphics.Color.TRANSPARENT,
) { newThemeSettings.darkTheme }, ) { darkTheme },
navigationBarStyle = SystemBarStyle.auto( navigationBarStyle = SystemBarStyle.auto(
lightScrim = lightScrim, lightScrim = lightScrim,
darkScrim = darkScrim, darkScrim = darkScrim,
) { newThemeSettings.darkTheme }, ) { darkTheme },
) )
} }
themeSettings = newThemeSettings
} }
} }
} }

@ -71,7 +71,7 @@ sealed interface MainActivityUiState {
/** /**
* Returns `true` if the dynamic color is disabled. * 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. * Returns `true` if the Android theme should be used.

Loading…
Cancel
Save