From f817ad5c66476f791dbbdeb6befde9bc00b8cc5f Mon Sep 17 00:00:00 2001 From: M3DZIK Date: Sat, 14 Oct 2023 15:44:13 +0200 Subject: [PATCH] Add Pure Black (AMOLED) theme --- .../dev/medzik/librepass/android/MainActivity.kt | 4 +++- .../dashboard/settings/SettingsAppearance.kt | 16 ++++++++-------- .../medzik/librepass/android/ui/theme/Theme.kt | 12 ++++++++++-- .../dev/medzik/librepass/android/utils/Store.kt | 3 ++- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt b/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt index 2862ee2f..6d98b593 100644 --- a/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt +++ b/app/src/main/java/dev/medzik/librepass/android/MainActivity.kt @@ -42,10 +42,12 @@ class MainActivity : FragmentActivity() { val theme = this.readKey(StoreKey.Theme) val autoTheme = theme == ThemeValues.SYSTEM.ordinal val darkTheme = theme == ThemeValues.DARK.ordinal + val blackTheme = theme == ThemeValues.BLACK.ordinal setContent { LibrePassTheme( - darkTheme = darkTheme || (autoTheme && isSystemInDarkTheme()), + darkTheme = blackTheme || darkTheme || (autoTheme && isSystemInDarkTheme()), + blackTheme = blackTheme, dynamicColor = dynamicColor ) { LibrePassNavigation() diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/screens/dashboard/settings/SettingsAppearance.kt b/app/src/main/java/dev/medzik/librepass/android/ui/screens/dashboard/settings/SettingsAppearance.kt index f1d0c842..48e8b755 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/screens/dashboard/settings/SettingsAppearance.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/screens/dashboard/settings/SettingsAppearance.kt @@ -55,6 +55,7 @@ fun SettingsAppearance(navController: NavController) { ThemeValues.SYSTEM.ordinal -> R.string.Settings_SystemDefault ThemeValues.LIGHT.ordinal -> R.string.Settings_Light ThemeValues.DARK.ordinal -> R.string.Settings_Dark + ThemeValues.BLACK.ordinal -> R.string.Settings_Black // never happens else -> throw UnsupportedOperationException() } @@ -75,9 +76,9 @@ fun SettingsAppearance(navController: NavController) { PickerDialog( state = themeDialogState, title = stringResource(R.string.Settings_Theme), - items = listOf(0, 1, 2), + items = ThemeValues.entries.toList(), onSelected = { - context.writeKey(StoreKey.Theme, it) + context.writeKey(StoreKey.Theme, it.ordinal) // restart application to apply changes ProcessPhoenix.triggerRebirth(context) @@ -90,11 +91,10 @@ fun SettingsAppearance(navController: NavController) { ) { Icon( when (it) { - ThemeValues.SYSTEM.ordinal -> Icons.Outlined.InvertColors - ThemeValues.LIGHT.ordinal -> Icons.Outlined.LightMode - ThemeValues.DARK.ordinal -> Icons.Outlined.DarkMode - // never happens - else -> throw UnsupportedOperationException() + ThemeValues.SYSTEM -> Icons.Outlined.InvertColors + ThemeValues.LIGHT -> Icons.Outlined.LightMode + ThemeValues.DARK -> Icons.Outlined.DarkMode + ThemeValues.BLACK -> Icons.Outlined.DarkMode }, contentDescription = null ) @@ -103,7 +103,7 @@ fun SettingsAppearance(navController: NavController) { modifier = Modifier .padding(start = 12.dp) .fillMaxWidth(), - text = getThemeTranslation(it) + text = getThemeTranslation(it.ordinal) ) } } diff --git a/app/src/main/java/dev/medzik/librepass/android/ui/theme/Theme.kt b/app/src/main/java/dev/medzik/librepass/android/ui/theme/Theme.kt index 545ebea1..7456822a 100644 --- a/app/src/main/java/dev/medzik/librepass/android/ui/theme/Theme.kt +++ b/app/src/main/java/dev/medzik/librepass/android/ui/theme/Theme.kt @@ -89,11 +89,12 @@ private val darkColorScheme = darkColorScheme( @Composable fun LibrePassTheme( darkTheme: Boolean, + blackTheme: Boolean, // Dynamic color is available on Android 12+ dynamicColor: Boolean, content: @Composable () -> Unit ) { - val colorScheme = when { + var colorScheme = when { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { val context = LocalContext.current if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) @@ -103,6 +104,13 @@ fun LibrePassTheme( else -> lightColorScheme } + if (blackTheme) { + colorScheme = colorScheme.copy( + surface = Color.Black, + background = Color.Black + ) + } + val systemUiController = rememberSystemUiController() val useDarkIcons = !darkTheme @@ -122,7 +130,7 @@ fun LibrePassTheme( typography = Typography, ) { Surface( - color = MaterialTheme.colorScheme.background, + color = MaterialTheme.colorScheme.surface, modifier = Modifier .fillMaxSize() .imePadding(), diff --git a/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt b/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt index 8914ad00..da0add9b 100644 --- a/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt +++ b/app/src/main/java/dev/medzik/librepass/android/utils/Store.kt @@ -59,7 +59,8 @@ sealed class StoreKey( enum class ThemeValues { SYSTEM, LIGHT, - DARK + DARK, + BLACK } enum class VaultTimeoutValues(val seconds: Int) { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 679e0c9a..08fa3064 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -64,6 +64,7 @@ Systemstandard Hell Dunkel + Reines Schwarz (AMOLED) Sicherheit Entsperren mit Biometrie Tresor-Zeitlimit diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index f1fe80f2..e613c00e 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -64,6 +64,7 @@ Ustawiania systemowe Jasny Ciemny + Czysta czerń (AMOLED) Zabezpieczenia Odblokowanie biometryczne Limit czasu sejfu diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1e8b8310..0758da4b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,6 +66,7 @@ System default Light Dark + Pure black (AMOLED) Material You (Android 12+) Security Unlock with biometrics