From f430b6f853cb61734d4c31d84be970aad94d1639 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 25 May 2020 15:13:30 -0400 Subject: [PATCH] Use getEnum for theme preferences too --- .../data/preference/PreferenceValues.kt | 25 +++++++------ .../data/preference/PreferencesHelper.kt | 6 ++-- .../ui/base/activity/BaseActivity.kt | 10 +++--- .../ui/setting/SettingsGeneralController.kt | 36 +++++++++---------- 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index a9519335cd..312544684d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -5,21 +5,24 @@ package eu.kanade.tachiyomi.data.preference */ object PreferenceValues { - enum class ThemeMode(val value: String) { - LIGHT("light"), - DARK("dark"), - SYSTEM("system"), + // Keys are lowercase to match legacy string values + enum class ThemeMode { + light, + dark, + system, } - enum class LightThemeVariant(val value: String) { - DEFAULT("default"), - BLUE("blue"), + // Keys are lowercase to match legacy string values + enum class LightThemeVariant { + default, + blue, } - enum class DarkThemeVariant(val value: String) { - DEFAULT("default"), - BLUE("blue"), - AMOLED("amoled"), + // Keys are lowercase to match legacy string values + enum class DarkThemeVariant { + default, + blue, + amoled, } enum class DisplayMode { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 3baa708be8..3e53a9e9d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -69,11 +69,11 @@ class PreferencesHelper(val context: Context) { fun clear() = prefs.edit().clear().apply() - fun themeMode() = flowPrefs.getString(Keys.themeMode, Values.ThemeMode.SYSTEM.value) + fun themeMode() = flowPrefs.getEnum(Keys.themeMode, Values.ThemeMode.system) - fun themeLight() = flowPrefs.getString(Keys.themeLight, Values.LightThemeVariant.DEFAULT.value) + fun themeLight() = flowPrefs.getEnum(Keys.themeLight, Values.LightThemeVariant.default) - fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.DarkThemeVariant.DEFAULT.value) + fun themeDark() = flowPrefs.getEnum(Keys.themeDark, Values.DarkThemeVariant.default) fun rotation() = flowPrefs.getInt(Keys.rotation, 1) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 48f0d76252..0ecde8b1d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -25,7 +25,7 @@ abstract class BaseActivity : AppCompatActivity() { private val lightTheme: Int by lazy { when (preferences.themeLight().get()) { - Values.LightThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_LightBlue + Values.LightThemeVariant.blue -> R.style.Theme_Tachiyomi_LightBlue else -> { when { // Light status + navigation bar @@ -47,8 +47,8 @@ abstract class BaseActivity : AppCompatActivity() { private val darkTheme: Int by lazy { when (preferences.themeDark().get()) { - Values.DarkThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_DarkBlue - Values.DarkThemeVariant.AMOLED.value -> R.style.Theme_Tachiyomi_Amoled + Values.DarkThemeVariant.blue -> R.style.Theme_Tachiyomi_DarkBlue + Values.DarkThemeVariant.amoled -> R.style.Theme_Tachiyomi_Amoled else -> R.style.Theme_Tachiyomi_Dark } } @@ -61,14 +61,14 @@ abstract class BaseActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { setTheme( when (preferences.themeMode().get()) { - Values.ThemeMode.SYSTEM.value -> { + Values.ThemeMode.system -> { if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) { darkTheme } else { lightTheme } } - Values.ThemeMode.DARK.value -> darkTheme + Values.ThemeMode.dark -> darkTheme else -> lightTheme } ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index 0ea90ad399..c2f8d54fd0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -118,21 +118,21 @@ class SettingsGeneralController : SettingsController() { R.string.theme_dark ) entryValues = arrayOf( - Values.ThemeMode.SYSTEM.value, - Values.ThemeMode.LIGHT.value, - Values.ThemeMode.DARK.value + Values.ThemeMode.system.name, + Values.ThemeMode.light.name, + Values.ThemeMode.dark.name ) - defaultValue = Values.ThemeMode.SYSTEM.value + defaultValue = Values.ThemeMode.system.name } else { entriesRes = arrayOf( R.string.theme_light, R.string.theme_dark ) entryValues = arrayOf( - Values.ThemeMode.LIGHT.value, - Values.ThemeMode.DARK.value + Values.ThemeMode.light.name, + Values.ThemeMode.dark.name ) - defaultValue = Values.ThemeMode.LIGHT.value + defaultValue = Values.ThemeMode.light.name } summary = "%s" @@ -150,17 +150,17 @@ class SettingsGeneralController : SettingsController() { R.string.theme_light_blue ) entryValues = arrayOf( - Values.LightThemeVariant.DEFAULT.value, - Values.LightThemeVariant.BLUE.value + Values.LightThemeVariant.default.name, + Values.LightThemeVariant.blue.name ) - defaultValue = Values.LightThemeVariant.DEFAULT.value + defaultValue = Values.LightThemeVariant.default.name summary = "%s" - preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.DARK.value } + preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.dark } .launchIn(scope) onChange { - if (preferences.themeMode().get() != Values.ThemeMode.DARK.value) { + if (preferences.themeMode().get() != Values.ThemeMode.dark) { activity?.recreate() } true @@ -175,18 +175,18 @@ class SettingsGeneralController : SettingsController() { R.string.theme_dark_amoled ) entryValues = arrayOf( - Values.DarkThemeVariant.DEFAULT.value, - Values.DarkThemeVariant.BLUE.value, - Values.DarkThemeVariant.AMOLED.value + Values.DarkThemeVariant.default.name, + Values.DarkThemeVariant.blue.name, + Values.DarkThemeVariant.amoled.name ) - defaultValue = Values.DarkThemeVariant.DEFAULT.value + defaultValue = Values.DarkThemeVariant.default.name summary = "%s" - preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.LIGHT.value } + preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light } .launchIn(scope) onChange { - if (preferences.themeMode().get() != Values.ThemeMode.LIGHT.value) { + if (preferences.themeMode().get() != Values.ThemeMode.light) { activity?.recreate() } true