From 3f98f7d54ad2e2636db83cdfe7b69aa9c48a837a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 12 Jul 2022 18:59:21 +0200 Subject: [PATCH] fix themes --- .../preferences/AppearanceSettings.kt | 2 +- .../com/github/libretube/util/ThemeHelper.kt | 44 +++++++++++-------- app/src/main/res/values-night/themes.xml | 42 ++++++++++++++++++ app/src/main/res/values/style.xml | 10 ----- app/src/main/res/xml/appearance_settings.xml | 2 +- 5 files changed, 69 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt index 2658cb852..dfe9003dc 100644 --- a/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt +++ b/app/src/main/java/com/github/libretube/preferences/AppearanceSettings.kt @@ -18,7 +18,7 @@ class AppearanceSettings : PreferenceFragmentCompat() { val settingsActivity = activity as SettingsActivity settingsActivity.changeTopBarText(getString(R.string.appearance)) - val themeToggle = findPreference("theme_togglee") + val themeToggle = findPreference("theme_toggle") themeToggle?.setOnPreferenceChangeListener { _, _ -> val restartDialog = RequireRestartDialog() restartDialog.show(childFragmentManager, "RequireRestartDialog") diff --git a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt index 3b50103b4..8fa3bbb68 100644 --- a/app/src/main/java/com/github/libretube/util/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ThemeHelper.kt @@ -17,11 +17,17 @@ import com.google.android.material.color.DynamicColors object ThemeHelper { fun updateTheme(activity: AppCompatActivity) { - updateAccentColor(activity) - updateThemeMode(activity) + val themeMode = PreferenceHelper.getString(activity, "theme_toggle", "A")!! + val blackModeEnabled = themeMode == "O" + + updateAccentColor(activity, blackModeEnabled) + updateThemeMode(themeMode) } - private fun updateAccentColor(activity: AppCompatActivity) { + private fun updateAccentColor( + activity: AppCompatActivity, + blackThemeEnabled: Boolean + ) { val theme = when ( PreferenceHelper.getString( activity, @@ -31,14 +37,15 @@ object ThemeHelper { ) { "my" -> { applyDynamicColors(activity) - R.style.MaterialYou + if (blackThemeEnabled) R.style.MaterialYou_Black + else R.style.MaterialYou } - "red" -> R.style.Theme_Red - "blue" -> R.style.Theme_Blue - "yellow" -> R.style.Theme_Yellow - "green" -> R.style.Theme_Green - "purple" -> R.style.Theme_Purple - else -> R.style.Theme_Purple + "red" -> if (blackThemeEnabled) R.style.Theme_Red_Black else R.style.Theme_Red + "blue" -> if (blackThemeEnabled) R.style.Theme_Blue_Black else R.style.Theme_Blue + "yellow" -> if (blackThemeEnabled) R.style.Theme_Yellow_Black else R.style.Theme_Yellow + "green" -> if (blackThemeEnabled) R.style.Theme_Green_Black else R.style.Theme_Green + "purple" -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple + else -> if (blackThemeEnabled) R.style.Theme_Purple_Black else R.style.Theme_Purple } activity.setTheme(theme) } @@ -50,16 +57,15 @@ object ThemeHelper { DynamicColors.applyToActivityIfAvailable(activity) } - private fun updateThemeMode(context: Context) { - when (PreferenceHelper.getString(context, "theme_togglee", "A")) { - "A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) - "L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) - "D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - "O" -> { - context.setTheme(R.style.Black) - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) - } + private fun updateThemeMode(themeMode: String) { + val mode = when (themeMode) { + "A" -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + "L" -> AppCompatDelegate.MODE_NIGHT_NO + "D" -> AppCompatDelegate.MODE_NIGHT_YES + "O" -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM } + AppCompatDelegate.setDefaultNightMode(mode) } fun changeIcon(context: Context, newLogoActivityAlias: String) { diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 65983e430..2efaffbdd 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -8,6 +8,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index 3774f77c7..b40cc63da 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -15,16 +15,6 @@ - -