aboutsummaryrefslogtreecommitdiff
path: root/ui/compose
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-05-28 00:35:22 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-05-28 00:35:22 +0530
commit3266a1b0333e43ff567e9d2c7fed85cd428e69d3 (patch)
tree73fec12dbbcbe33e5f8f040fa5bff1ef5e0de1d7 /ui/compose
parent0f9540a645ef66f3cf67294f75ba2c5d9d80078e (diff)
refactor(compose): make theme decisions within `APSTheme`
Diffstat (limited to 'ui/compose')
-rw-r--r--ui/compose/build.gradle.kts1
-rw-r--r--ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt42
-rw-r--r--ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt27
3 files changed, 35 insertions, 35 deletions
diff --git a/ui/compose/build.gradle.kts b/ui/compose/build.gradle.kts
index 4996bb10..8ede9ad3 100644
--- a/ui/compose/build.gradle.kts
+++ b/ui/compose/build.gradle.kts
@@ -23,4 +23,5 @@ dependencies {
api(libs.compose.foundation.layout)
api(libs.compose.material3)
api(libs.compose.ui.core)
+ implementation(libs.androidx.core.ktx)
}
diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt
index b11aa7c1..6827e01a 100644
--- a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt
+++ b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/Theme.kt
@@ -1,10 +1,20 @@
package app.passwordstore.ui.compose.theme
-import androidx.compose.material3.ColorScheme
+import android.app.Activity
+import android.os.Build
+import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
+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.Color
+import androidx.compose.ui.graphics.toArgb
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalView
+import androidx.core.view.WindowCompat
internal val LightThemeColors =
lightColorScheme(
@@ -65,13 +75,29 @@ internal val DarkThemeColors =
@Composable
public fun APSTheme(
- colors: ColorScheme,
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ dynamicColor: Boolean = true,
content: @Composable () -> Unit,
) {
- MaterialTheme(colorScheme = colors, typography = AppTypography, content = content)
-}
-
-@Composable
-public fun APSThemePreview(content: @Composable () -> Unit) {
- MaterialTheme(colorScheme = LightThemeColors, typography = AppTypography, content = content)
+ val colorScheme =
+ when {
+ dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
+ val context = LocalContext.current
+ if (darkTheme) {
+ dynamicDarkColorScheme(context)
+ } else {
+ dynamicLightColorScheme(context)
+ }
+ }
+ else -> if (darkTheme) DarkThemeColors else LightThemeColors
+ }
+ val view = LocalView.current
+ if (!view.isInEditMode) {
+ SideEffect {
+ val window = (view.context as Activity).window
+ window.statusBarColor = Color.Transparent.toArgb()
+ WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
+ }
+ }
+ MaterialTheme(colorScheme = colorScheme, typography = AppTypography, content = content)
}
diff --git a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt b/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt
deleted file mode 100644
index 096862dc..00000000
--- a/ui/compose/src/main/kotlin/app/passwordstore/ui/compose/theme/utils.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package app.passwordstore.ui.compose.theme
-
-import android.content.Context
-import android.os.Build
-import androidx.compose.foundation.isSystemInDarkTheme
-import androidx.compose.material3.ColorScheme
-import androidx.compose.material3.dynamicDarkColorScheme
-import androidx.compose.material3.dynamicLightColorScheme
-import androidx.compose.runtime.Composable
-
-@Composable
-public fun decideColorScheme(context: Context): ColorScheme {
- val isDarkTheme = isSystemInDarkTheme()
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- if (isDarkTheme) {
- dynamicDarkColorScheme(context)
- } else {
- dynamicLightColorScheme(context)
- }
- } else {
- if (isDarkTheme) {
- DarkThemeColors
- } else {
- LightThemeColors
- }
- }
-}