add black background option

This commit is contained in:
qimiko committed 2024-01-08 01:32:43 -07:00
1 parent 3843d2c94e
commit 4c44b30df0
5 files changed
+21 -5

No files matched your search

@@ -54,8 +54,10 @@ class MainActivity : ComponentActivity() {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME) val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
val theme = Theme.fromInt(themeOption) val theme = Theme.fromInt(themeOption)
val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)
CompositionLocalProvider(LocalTheme provides theme) { CompositionLocalProvider(LocalTheme provides theme) {
GeodeLauncherTheme(theme = theme) { GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
Surface( Surface(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
@@ -58,8 +58,10 @@ class SettingsActivity : ComponentActivity() {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME) val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
val theme = Theme.fromInt(themeOption) val theme = Theme.fromInt(themeOption)
val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)
CompositionLocalProvider(LocalTheme provides theme) { CompositionLocalProvider(LocalTheme provides theme) {
GeodeLauncherTheme(theme = theme) { GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
Surface( Surface(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background color = MaterialTheme.colorScheme.background
@@ -265,6 +267,10 @@ fun SettingsScreen(
toLabel = { themeToKey(it) }, toLabel = { themeToKey(it) },
extraSelectBehavior = { updateTheme(context, it) } extraSelectBehavior = { updateTheme(context, it) }
) )
SettingsCard(
title = stringResource(R.string.preference_black_background_name),
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
)
SettingsCard( SettingsCard(
title = context.getString(R.string.preference_load_testing_name), title = context.getString(R.string.preference_load_testing_name),
preferenceKey = PreferenceUtils.Key.LOAD_TESTING, preferenceKey = PreferenceUtils.Key.LOAD_TESTING,
@@ -60,16 +60,21 @@ fun GeodeLauncherTheme(
theme: Theme = Theme.fromInt(0), theme: Theme = Theme.fromInt(0),
// Dynamic color is available on Android 12+ // Dynamic color is available on Android 12+
dynamicColor: Boolean = true, dynamicColor: Boolean = true,
blackBackground: Boolean = false,
content: @Composable () -> Unit content: @Composable () -> Unit
) { ) {
val colorScheme = when { val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current val context = LocalContext.current
when (theme) { when {
Theme.DARK -> dynamicDarkColorScheme(context) theme == Theme.DARK && blackBackground ->
dynamicDarkColorScheme(context).copy(surface = Color.Black, background = Color.Black)
theme == Theme.DARK -> dynamicDarkColorScheme(context)
else -> dynamicLightColorScheme(context) else -> dynamicLightColorScheme(context)
} }
} }
theme == Theme.DARK && blackBackground ->
DarkColorScheme.copy(surface = Color.Black, background = Color.Black)
theme == Theme.DARK -> DarkColorScheme theme == Theme.DARK -> DarkColorScheme
else -> LightColorScheme else -> LightColorScheme
} }
@@ -95,7 +95,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
RELEASE_CHANNEL, RELEASE_CHANNEL,
CURRENT_VERSION_TAG, CURRENT_VERSION_TAG,
CURRENT_VERSION_TIMESTAMP, CURRENT_VERSION_TIMESTAMP,
THEME THEME,
BLACK_BACKGROUND,
} }
private fun defaultValueForBooleanKey(key: Key): Boolean { private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -114,6 +115,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.CURRENT_VERSION_TAG -> "PreferenceCurrentVersionName" Key.CURRENT_VERSION_TAG -> "PreferenceCurrentVersionName"
Key.CURRENT_VERSION_TIMESTAMP -> "PreferenceCurrentVersionDescriptor" Key.CURRENT_VERSION_TIMESTAMP -> "PreferenceCurrentVersionDescriptor"
Key.THEME -> "PreferenceTheme" Key.THEME -> "PreferenceTheme"
Key.BLACK_BACKGROUND -> "PreferenceBlackBackground"
} }
} }
+1
View File
@@ -52,6 +52,7 @@
<string name="preference_theme_default">System default</string> <string name="preference_theme_default">System default</string>
<string name="preference_theme_light">Light</string> <string name="preference_theme_light">Light</string>
<string name="preference_theme_dark">Dark</string> <string name="preference_theme_dark">Dark</string>
<string name="preference_black_background_name">Black background in dark theme</string>
<string name="preference_category_updater">Updates</string> <string name="preference_category_updater">Updates</string>
<string name="preference_update_automatically_name">Enable automatic updates</string> <string name="preference_update_automatically_name">Enable automatic updates</string>