Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Add Pure Black (AMOLED) theme
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Oct 14, 2023
1 parent 7e70216 commit f817ad5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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)
Expand All @@ -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
)
Expand All @@ -103,7 +103,7 @@ fun SettingsAppearance(navController: NavController) {
modifier = Modifier
.padding(start = 12.dp)
.fillMaxWidth(),
text = getThemeTranslation(it)
text = getThemeTranslation(it.ordinal)
)
}
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/dev/medzik/librepass/android/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -122,7 +130,7 @@ fun LibrePassTheme(
typography = Typography,
) {
Surface(
color = MaterialTheme.colorScheme.background,
color = MaterialTheme.colorScheme.surface,
modifier = Modifier
.fillMaxSize()
.imePadding(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ sealed class StoreKey<T>(
enum class ThemeValues {
SYSTEM,
LIGHT,
DARK
DARK,
BLACK
}

enum class VaultTimeoutValues(val seconds: Int) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<string name="Settings_SystemDefault">Systemstandard</string>
<string name="Settings_Light">Hell</string>
<string name="Settings_Dark">Dunkel</string>
<string name="Settings_Black">Reines Schwarz (AMOLED)</string>
<string name="Settings_Group_Security">Sicherheit</string>
<string name="Settings_BiometricUnlock">Entsperren mit Biometrie</string>
<string name="Settings_Vault_Timeout_Modal_Title">Tresor-Zeitlimit</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<string name="Settings_SystemDefault">Ustawiania systemowe</string>
<string name="Settings_Light">Jasny</string>
<string name="Settings_Dark">Ciemny</string>
<string name="Settings_Black">Czysta czerń (AMOLED)</string>
<string name="Settings_Group_Security">Zabezpieczenia</string>
<string name="Settings_BiometricUnlock">Odblokowanie biometryczne</string>
<string name="Settings_Vault_Timeout_Modal_Title">Limit czasu sejfu</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<string name="Settings_SystemDefault">System default</string>
<string name="Settings_Light">Light</string>
<string name="Settings_Dark">Dark</string>
<string name="Settings_Black">Pure black (AMOLED)</string>
<string name="Settings_MaterialYou" translatable="false">Material You (Android 12+)</string>
<string name="Settings_Group_Security">Security</string>
<string name="Settings_BiometricUnlock">Unlock with biometrics</string>
Expand Down

0 comments on commit f817ad5

Please sign in to comment.