Skip to content

Commit

Permalink
add black background option
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 8, 2024
1 parent 3843d2c commit 4c44b30
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/geode/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ class MainActivity : ComponentActivity() {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
val theme = Theme.fromInt(themeOption)

val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)

CompositionLocalProvider(LocalTheme provides theme) {
GeodeLauncherTheme(theme = theme) {
GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/geode/launcher/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class SettingsActivity : ComponentActivity() {
val themeOption by PreferenceUtils.useIntPreference(PreferenceUtils.Key.THEME)
val theme = Theme.fromInt(themeOption)

val backgroundOption by PreferenceUtils.useBooleanPreference(PreferenceUtils.Key.BLACK_BACKGROUND)

CompositionLocalProvider(LocalTheme provides theme) {
GeodeLauncherTheme(theme = theme) {
GeodeLauncherTheme(theme = theme, blackBackground = backgroundOption) {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
Expand Down Expand Up @@ -265,6 +267,10 @@ fun SettingsScreen(
toLabel = { themeToKey(it) },
extraSelectBehavior = { updateTheme(context, it) }
)
SettingsCard(
title = stringResource(R.string.preference_black_background_name),
preferenceKey = PreferenceUtils.Key.BLACK_BACKGROUND
)
SettingsCard(
title = context.getString(R.string.preference_load_testing_name),
preferenceKey = PreferenceUtils.Key.LOAD_TESTING,
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/geode/launcher/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@ fun GeodeLauncherTheme(
theme: Theme = Theme.fromInt(0),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
blackBackground: Boolean = false,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
when (theme) {
Theme.DARK -> dynamicDarkColorScheme(context)
when {
theme == Theme.DARK && blackBackground ->
dynamicDarkColorScheme(context).copy(surface = Color.Black, background = Color.Black)
theme == Theme.DARK -> dynamicDarkColorScheme(context)
else -> dynamicLightColorScheme(context)
}
}
theme == Theme.DARK && blackBackground ->
DarkColorScheme.copy(surface = Color.Black, background = Color.Black)
theme == Theme.DARK -> DarkColorScheme
else -> LightColorScheme
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
RELEASE_CHANNEL,
CURRENT_VERSION_TAG,
CURRENT_VERSION_TIMESTAMP,
THEME
THEME,
BLACK_BACKGROUND,
}

private fun defaultValueForBooleanKey(key: Key): Boolean {
Expand All @@ -114,6 +115,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.CURRENT_VERSION_TAG -> "PreferenceCurrentVersionName"
Key.CURRENT_VERSION_TIMESTAMP -> "PreferenceCurrentVersionDescriptor"
Key.THEME -> "PreferenceTheme"
Key.BLACK_BACKGROUND -> "PreferenceBlackBackground"
}
}

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 @@ -52,6 +52,7 @@
<string name="preference_theme_default">System default</string>
<string name="preference_theme_light">Light</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_update_automatically_name">Enable automatic updates</string>
Expand Down

0 comments on commit 4c44b30

Please sign in to comment.