Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Merge branch 'main' into mlykotom/optimize-startup

Tomáš Mlynaričb2c71025b5fb
diff --cc app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
index c949ba00f,599bd0b35..ecc23d80e
--- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
+++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/MainActivity.kt
@@@ -22,9 -22,10 +22,7 @@@ import androidx.activity.SystemBarStyl
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
- import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
- import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
-import androidx.compose.foundation.isSystemInDarkTheme
-import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
@@@ -132,11 -95,40 +130,10 @@@ class MainActivity : ComponentActivity(
// Keep the splash screen on-screen until the UI state is loaded. This condition is
// evaluated each time the app needs to be redrawn so it should be fast to avoid blocking
// the UI.
- splashScreen.setKeepOnScreenCondition {
- when (uiState) {
- Loading -> true
- is Success -> false
- }
- }
-
- // Turn off the decor fitting system windows, which allows us to handle insets,
- // including IME animations, and go edge-to-edge
- // This also sets up the initial system bar style based on the platform theme
- enableEdgeToEdge()
+ splashScreen.setKeepOnScreenCondition { viewModel.uiState.value.shouldKeepSplashScreen() }
setContent {
- val darkTheme = shouldUseDarkTheme(uiState)
-
- // Update the edge to edge configuration to match the theme
- // This is the same parameters as the default enableEdgeToEdge call, but we manually
- // resolve whether or not to show dark theme using uiState, since it can be different
- // than the configuration's dark theme value based on the user preference.
- DisposableEffect(darkTheme) {
- enableEdgeToEdge(
- statusBarStyle = SystemBarStyle.auto(
- android.graphics.Color.TRANSPARENT,
- android.graphics.Color.TRANSPARENT,
- ) { darkTheme },
- navigationBarStyle = SystemBarStyle.auto(
- lightScrim,
- darkScrim,
- ) { darkTheme },
- )
- onDispose {}
- }
-
val appState = rememberNiaAppState(
- windowSizeClass = calculateWindowSizeClass(this),
networkMonitor = networkMonitor,
userNewsResourceRepository = userNewsResourceRepository,
timeZoneMonitor = timeZoneMonitor,