app: remove deprecated SystemUIController from accompanist by migrating to EdgeToEdge

This commit is contained in:
Han Yin 2025-09-19 14:30:56 -07:00
parent 7c2e6d0a2f
commit 42e3972b30
4 changed files with 36 additions and 44 deletions

View File

@ -66,9 +66,6 @@ dependencies {
implementation(libs.bundles.hilt) implementation(libs.bundles.hilt)
implementation(libs.bundles.retrofit) implementation(libs.bundles.retrofit)
// Individual dependencies
implementation(libs.accompanist.systemuicontroller)
// Subproject // Subproject
implementation(project(":lib")) implementation(project(":lib"))

View File

@ -5,8 +5,10 @@ import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -18,6 +20,7 @@ import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.rememberDrawerState import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -49,6 +52,9 @@ import com.arm.aiplayground.ui.screens.ModelLoadingScreen
import com.arm.aiplayground.ui.screens.ModelsScreen import com.arm.aiplayground.ui.screens.ModelsScreen
import com.arm.aiplayground.ui.screens.SettingsGeneralScreen import com.arm.aiplayground.ui.screens.SettingsGeneralScreen
import com.arm.aiplayground.ui.theme.LlamaTheme import com.arm.aiplayground.ui.theme.LlamaTheme
import com.arm.aiplayground.ui.theme.isDarkTheme
import com.arm.aiplayground.ui.theme.md_theme_dark_scrim
import com.arm.aiplayground.ui.theme.md_theme_light_scrim
import com.arm.aiplayground.viewmodel.BenchmarkViewModel import com.arm.aiplayground.viewmodel.BenchmarkViewModel
import com.arm.aiplayground.viewmodel.ConversationViewModel import com.arm.aiplayground.viewmodel.ConversationViewModel
import com.arm.aiplayground.viewmodel.MainViewModel import com.arm.aiplayground.viewmodel.MainViewModel
@ -70,7 +76,22 @@ class MainActivity : ComponentActivity() {
val colorThemeMode by settingsViewModel.colorThemeMode.collectAsState() val colorThemeMode by settingsViewModel.colorThemeMode.collectAsState()
val darkThemeMode by settingsViewModel.darkThemeMode.collectAsState() val darkThemeMode by settingsViewModel.darkThemeMode.collectAsState()
LlamaTheme(colorThemeMode = colorThemeMode, darkThemeMode = darkThemeMode) { val isDarkTheme = isDarkTheme(darkThemeMode)
LlamaTheme(colorThemeMode = colorThemeMode, isDarkTheme = isDarkTheme) {
DisposableEffect(darkThemeMode) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
android.graphics.Color.TRANSPARENT,
android.graphics.Color.TRANSPARENT,
) { isDarkTheme },
navigationBarStyle = SystemBarStyle.auto(
md_theme_light_scrim.value.toInt(),
md_theme_dark_scrim.value.toInt(),
) { isDarkTheme },
)
onDispose {}
}
Surface( Surface(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background

View File

@ -1,6 +1,5 @@
package com.arm.aiplayground.ui.theme package com.arm.aiplayground.ui.theme
import android.app.Activity
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@ -9,16 +8,11 @@ import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import com.arm.aiplayground.data.source.prefs.ColorThemeMode import com.arm.aiplayground.data.source.prefs.ColorThemeMode
import com.arm.aiplayground.data.source.prefs.DarkThemeMode import com.arm.aiplayground.data.source.prefs.DarkThemeMode
import com.google.accompanist.systemuicontroller.rememberSystemUiController
// -------------------- ColorScheme -------------------- // -------------------- Color Schemes --------------------
internal val armLightColorScheme: ColorScheme = lightColorScheme( internal val armLightColorScheme: ColorScheme = lightColorScheme(
primary = md_theme_light_primary, primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary, onPrimary = md_theme_light_onPrimary,
@ -79,7 +73,6 @@ internal val armLightColorScheme: ColorScheme = lightColorScheme(
onTertiaryFixedVariant = md_theme_light_onTertiaryFixedVariant, onTertiaryFixedVariant = md_theme_light_onTertiaryFixedVariant,
) )
internal val armDarkColorScheme: ColorScheme = darkColorScheme( internal val armDarkColorScheme: ColorScheme = darkColorScheme(
primary = md_theme_dark_primary, primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary, onPrimary = md_theme_dark_onPrimary,
@ -141,38 +134,25 @@ internal val armDarkColorScheme: ColorScheme = darkColorScheme(
) )
@Composable @Composable
fun LlamaTheme( fun isDarkTheme(darkThemeMode: DarkThemeMode) =
colorThemeMode: ColorThemeMode, when (darkThemeMode) {
darkThemeMode: DarkThemeMode,
content: @Composable () -> Unit
) {
val context = LocalContext.current
val darkTheme = when (darkThemeMode) {
DarkThemeMode.AUTO -> isSystemInDarkTheme() DarkThemeMode.AUTO -> isSystemInDarkTheme()
DarkThemeMode.LIGHT -> false DarkThemeMode.LIGHT -> false
DarkThemeMode.DARK -> true DarkThemeMode.DARK -> true
} }
@Composable
fun LlamaTheme(
colorThemeMode: ColorThemeMode,
isDarkTheme: Boolean,
content: @Composable () -> Unit
) {
val context = LocalContext.current
val colorScheme = when(colorThemeMode) { val colorScheme = when(colorThemeMode) {
ColorThemeMode.ARM -> if (darkTheme) armDarkColorScheme else armLightColorScheme ColorThemeMode.ARM ->
if (isDarkTheme) armDarkColorScheme else armLightColorScheme
ColorThemeMode.MATERIAL -> ColorThemeMode.MATERIAL ->
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) if (isDarkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
val view = LocalView.current
if (!view.isInEditMode) {
val systemUiController = rememberSystemUiController()
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.background.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
// Set status bar and navigation bar colors
systemUiController.setSystemBarsColor(
color = colorScheme.background,
darkIcons = !darkTheme
)
}
} }
MaterialTheme( MaterialTheme(

View File

@ -28,9 +28,6 @@ compose-material-icons = "1.7.8"
compose-material3 = "1.4.0-rc01" compose-material3 = "1.4.0-rc01"
compose-ui = "1.9.1" compose-ui = "1.9.1"
# Accompanist
accompanist = "0.36.0"
# Testing # Testing
espresso-core = "3.7.0" espresso-core = "3.7.0"
androidx-junit = "1.3.0" androidx-junit = "1.3.0"
@ -79,9 +76,6 @@ compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-mani
compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose-ui" } compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose-ui" }
compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose-ui" } compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview", version.ref = "compose-ui" }
# Accompanist
accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" }
# Hilt # Hilt
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "dagger-hilt" } hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "dagger-hilt" }
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "dagger-hilt" } hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "dagger-hilt" }