app: remove deprecated SystemUIController from accompanist by migrating to EdgeToEdge
This commit is contained in:
parent
7c2e6d0a2f
commit
42e3972b30
|
|
@ -66,9 +66,6 @@ dependencies {
|
|||
implementation(libs.bundles.hilt)
|
||||
implementation(libs.bundles.retrofit)
|
||||
|
||||
// Individual dependencies
|
||||
implementation(libs.accompanist.systemuicontroller)
|
||||
|
||||
// Subproject
|
||||
implementation(project(":lib"))
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import android.content.ActivityNotFoundException
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
|
|
@ -18,6 +20,7 @@ import androidx.compose.material3.SnackbarResult
|
|||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
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.SettingsGeneralScreen
|
||||
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.ConversationViewModel
|
||||
import com.arm.aiplayground.viewmodel.MainViewModel
|
||||
|
|
@ -70,7 +76,22 @@ class MainActivity : ComponentActivity() {
|
|||
val colorThemeMode by settingsViewModel.colorThemeMode.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(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.arm.aiplayground.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
|
|
@ -9,16 +8,11 @@ import androidx.compose.material3.dynamicDarkColorScheme
|
|||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
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.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.arm.aiplayground.data.source.prefs.ColorThemeMode
|
||||
import com.arm.aiplayground.data.source.prefs.DarkThemeMode
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
// -------------------- ColorScheme --------------------
|
||||
// -------------------- Color Schemes --------------------
|
||||
internal val armLightColorScheme: ColorScheme = lightColorScheme(
|
||||
primary = md_theme_light_primary,
|
||||
onPrimary = md_theme_light_onPrimary,
|
||||
|
|
@ -79,7 +73,6 @@ internal val armLightColorScheme: ColorScheme = lightColorScheme(
|
|||
onTertiaryFixedVariant = md_theme_light_onTertiaryFixedVariant,
|
||||
)
|
||||
|
||||
|
||||
internal val armDarkColorScheme: ColorScheme = darkColorScheme(
|
||||
primary = md_theme_dark_primary,
|
||||
onPrimary = md_theme_dark_onPrimary,
|
||||
|
|
@ -141,38 +134,25 @@ internal val armDarkColorScheme: ColorScheme = darkColorScheme(
|
|||
)
|
||||
|
||||
@Composable
|
||||
fun LlamaTheme(
|
||||
colorThemeMode: ColorThemeMode,
|
||||
darkThemeMode: DarkThemeMode,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
||||
val darkTheme = when (darkThemeMode) {
|
||||
fun isDarkTheme(darkThemeMode: DarkThemeMode) =
|
||||
when (darkThemeMode) {
|
||||
DarkThemeMode.AUTO -> isSystemInDarkTheme()
|
||||
DarkThemeMode.LIGHT -> false
|
||||
DarkThemeMode.DARK -> true
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LlamaTheme(
|
||||
colorThemeMode: ColorThemeMode,
|
||||
isDarkTheme: Boolean,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val colorScheme = when(colorThemeMode) {
|
||||
ColorThemeMode.ARM -> if (darkTheme) armDarkColorScheme else armLightColorScheme
|
||||
ColorThemeMode.ARM ->
|
||||
if (isDarkTheme) armDarkColorScheme else armLightColorScheme
|
||||
ColorThemeMode.MATERIAL ->
|
||||
if (darkTheme) 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
|
||||
)
|
||||
}
|
||||
if (isDarkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
|
|
|
|||
|
|
@ -28,9 +28,6 @@ compose-material-icons = "1.7.8"
|
|||
compose-material3 = "1.4.0-rc01"
|
||||
compose-ui = "1.9.1"
|
||||
|
||||
# Accompanist
|
||||
accompanist = "0.36.0"
|
||||
|
||||
# Testing
|
||||
espresso-core = "3.7.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-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-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" }
|
||||
|
|
|
|||
Loading…
Reference in New Issue