diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 4eaa7136..2e2ce036 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -118,7 +118,6 @@ dependencies { implementation(compose.preview) implementation(compose.runtime) implementation(compose.foundation) - implementation(libs.accompanist.system.ui.controller) // Tooling debugImplementation(compose.uiTooling) diff --git a/androidApp/src/main/kotlin/com/mr3y/ludi/MainActivity.kt b/androidApp/src/main/kotlin/com/mr3y/ludi/MainActivity.kt index e5edcaf0..b301260e 100644 --- a/androidApp/src/main/kotlin/com/mr3y/ludi/MainActivity.kt +++ b/androidApp/src/main/kotlin/com/mr3y/ludi/MainActivity.kt @@ -1,20 +1,21 @@ package com.mr3y.ludi import android.app.Activity +import android.content.res.Configuration +import android.content.res.Resources import android.os.Bundle import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue -import androidx.compose.ui.graphics.Color import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.core.view.WindowCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.mr3y.ludi.shared.App import com.mr3y.ludi.shared.di.AndroidApplicationComponent import com.mr3y.ludi.shared.di.HostActivityComponent @@ -35,25 +36,21 @@ class MainActivity : ComponentActivity(), HostActivityComponentOwner { // Initialize the component. hostActivityComponent - WindowCompat.setDecorFitsSystemWindows(window, false) val appState = hostActivityComponent.parent.appState lifecycleScope.launch { appState.preferences.flowWithLifecycle(lifecycle, Lifecycle.State.CREATED).collect { userPreferences -> splashScreen.setKeepOnScreenCondition { userPreferences == null } } } + + goEdgeToEdge() + setContent { val userPreferences by appState.preferences.collectAsStateWithLifecycle(minActiveState = Lifecycle.State.CREATED) - val systemUiController = rememberSystemUiController() val useDarkIcons = !isSystemInDarkTheme() - DisposableEffect(systemUiController, useDarkIcons) { - // Update all of the system bar colors to be transparent, and use - // dark icons if we're in light theme - systemUiController.setSystemBarsColor( - color = Color.Transparent, - darkIcons = useDarkIcons - ) + DisposableEffect(useDarkIcons) { + goEdgeToEdge(isDarkTheme = { !useDarkIcons }) onDispose {} } @@ -61,16 +58,16 @@ class MainActivity : ComponentActivity(), HostActivityComponentOwner { App( isDarkTheme = when (userPreferences!!.theme) { Theme.Light -> { - systemUiController.setSystemBarsColor(Color.Transparent, true) + goEdgeToEdge(isDarkTheme = { false }) false } Theme.Dark -> { - systemUiController.setSystemBarsColor(Color.Transparent, false) + goEdgeToEdge(isDarkTheme = { true }) true } Theme.SystemDefault -> { val isDarkTheme = isSystemInDarkTheme() - systemUiController.setSystemBarsColor(Color.Transparent, !isDarkTheme) + goEdgeToEdge(isDarkTheme = { isDarkTheme }) isDarkTheme } }, @@ -80,6 +77,25 @@ class MainActivity : ComponentActivity(), HostActivityComponentOwner { } } } + + private fun goEdgeToEdge( + isDarkTheme: (Resources) -> Boolean = { resources -> + (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES + } + ) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto( + lightScrim = android.graphics.Color.TRANSPARENT, + darkScrim = android.graphics.Color.TRANSPARENT, + detectDarkMode = isDarkTheme + ), + navigationBarStyle = SystemBarStyle.auto( + lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF), + darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b), + detectDarkMode = isDarkTheme + ) + ) + } } private fun AndroidApplicationComponent.Companion.from(activity: Activity): AndroidApplicationComponent { diff --git a/androidApp/src/main/res/values-night/themes.xml b/androidApp/src/main/res/values-night/themes.xml index db6e20b5..705d48fa 100644 --- a/androidApp/src/main/res/values-night/themes.xml +++ b/androidApp/src/main/res/values-night/themes.xml @@ -1,9 +1,6 @@