@@ -35,6 +35,7 @@ import androidx.lifecycle.lifecycleScope
35
35
import androidx.lifecycle.repeatOnLifecycle
36
36
import androidx.metrics.performance.JankStats
37
37
import androidx.tracing.trace
38
+ import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading
38
39
import com.google.samples.apps.nowinandroid.core.analytics.AnalyticsHelper
39
40
import com.google.samples.apps.nowinandroid.core.analytics.LocalAnalyticsHelper
40
41
import com.google.samples.apps.nowinandroid.core.data.repository.UserNewsResourceRepository
@@ -48,6 +49,8 @@ import com.google.samples.apps.nowinandroid.util.isSystemInDarkTheme
48
49
import dagger.hilt.android.AndroidEntryPoint
49
50
import kotlinx.coroutines.flow.combine
50
51
import kotlinx.coroutines.flow.distinctUntilChanged
52
+ import kotlinx.coroutines.flow.map
53
+ import kotlinx.coroutines.flow.onEach
51
54
import kotlinx.coroutines.launch
52
55
import javax.inject.Inject
53
56
@@ -83,8 +86,8 @@ class MainActivity : ComponentActivity() {
83
86
var themeSettings by mutableStateOf(
84
87
ThemeSettings (
85
88
darkTheme = resources.configuration.isSystemInDarkTheme,
86
- androidTheme = false ,
87
- disableDynamicTheming = true ,
89
+ androidTheme = Loading .shouldUseAndroidTheme ,
90
+ disableDynamicTheming = Loading .shouldDisableDynamicTheming ,
88
91
),
89
92
)
90
93
@@ -101,8 +104,10 @@ class MainActivity : ComponentActivity() {
101
104
disableDynamicTheming = uiState.shouldDisableDynamicTheming,
102
105
)
103
106
}
107
+ .onEach { themeSettings = it }
108
+ .map { it.darkTheme }
104
109
.distinctUntilChanged()
105
- .collect { newThemeSettings ->
110
+ .collect { darkTheme ->
106
111
trace(" niaEdgeToEdge" ) {
107
112
// Turn off the decor fitting system windows, which allows us to handle insets,
108
113
// including IME animations, and go edge-to-edge.
@@ -113,15 +118,14 @@ class MainActivity : ComponentActivity() {
113
118
statusBarStyle = SystemBarStyle .auto(
114
119
lightScrim = android.graphics.Color .TRANSPARENT ,
115
120
darkScrim = android.graphics.Color .TRANSPARENT ,
116
- ) { newThemeSettings. darkTheme },
121
+ ) { darkTheme },
117
122
navigationBarStyle = SystemBarStyle .auto(
118
123
lightScrim = lightScrim,
119
124
darkScrim = darkScrim,
120
- ) { newThemeSettings. darkTheme },
125
+ ) { darkTheme },
121
126
)
122
127
}
123
128
124
- themeSettings = newThemeSettings
125
129
}
126
130
}
127
131
}
0 commit comments