From a0f56330946a03ce3560e86be77a75145269da1d Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 25 May 2020 14:07:12 -0400 Subject: [PATCH] Use enums for other PreferenceValues --- .../data/preference/PreferenceValues.kt | 22 +++++++----- .../data/preference/PreferencesHelper.kt | 6 ++-- .../ui/base/activity/BaseActivity.kt | 10 +++--- .../ui/setting/SettingsGeneralController.kt | 36 +++++++++---------- 4 files changed, 40 insertions(+), 34 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 70c1e71b75..dba9adc004 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,16 +5,22 @@ package eu.kanade.tachiyomi.data.preference */ object PreferenceValues { - const val THEME_MODE_LIGHT = "light" - const val THEME_MODE_DARK = "dark" - const val THEME_MODE_SYSTEM = "system" + enum class ThemeMode(val value: String) { + LIGHT("light"), + DARK("dark"), + SYSTEM("system"), + } - const val THEME_LIGHT_DEFAULT = "default" - const val THEME_LIGHT_BLUE = "blue" + enum class LightThemeVariant(val value: String) { + DEFAULT("default"), + BLUE("blue"), + } - const val THEME_DARK_DEFAULT = "default" - const val THEME_DARK_BLUE = "blue" - const val THEME_DARK_AMOLED = "amoled" + enum class DarkThemeVariant(val value: String) { + DEFAULT("default"), + BLUE("blue"), + AMOLED("amoled"), + } enum class DisplayMode(val value: Int) { COMPACT_GRID(0), 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 801d8b7ebb..cafef465c8 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.THEME_MODE_SYSTEM) + fun themeMode() = flowPrefs.getString(Keys.themeMode, Values.ThemeMode.SYSTEM.value) - fun themeLight() = flowPrefs.getString(Keys.themeLight, Values.THEME_LIGHT_DEFAULT) + fun themeLight() = flowPrefs.getString(Keys.themeLight, Values.LightThemeVariant.DEFAULT.value) - fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.THEME_DARK_DEFAULT) + fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.DarkThemeVariant.DEFAULT.value) 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 11c86bf184..48f0d76252 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.THEME_LIGHT_BLUE -> R.style.Theme_Tachiyomi_LightBlue + Values.LightThemeVariant.BLUE.value -> 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.THEME_DARK_BLUE -> R.style.Theme_Tachiyomi_DarkBlue - Values.THEME_DARK_AMOLED -> R.style.Theme_Tachiyomi_Amoled + Values.DarkThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_DarkBlue + Values.DarkThemeVariant.AMOLED.value -> 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.THEME_MODE_SYSTEM -> { + Values.ThemeMode.SYSTEM.value -> { if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) { darkTheme } else { lightTheme } } - Values.THEME_MODE_DARK -> darkTheme + Values.ThemeMode.DARK.value -> 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 3bd2ec83b5..0ea90ad399 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.THEME_MODE_SYSTEM, - Values.THEME_MODE_LIGHT, - Values.THEME_MODE_DARK + Values.ThemeMode.SYSTEM.value, + Values.ThemeMode.LIGHT.value, + Values.ThemeMode.DARK.value ) - defaultValue = Values.THEME_MODE_SYSTEM + defaultValue = Values.ThemeMode.SYSTEM.value } else { entriesRes = arrayOf( R.string.theme_light, R.string.theme_dark ) entryValues = arrayOf( - Values.THEME_MODE_LIGHT, - Values.THEME_MODE_DARK + Values.ThemeMode.LIGHT.value, + Values.ThemeMode.DARK.value ) - defaultValue = Values.THEME_MODE_LIGHT + defaultValue = Values.ThemeMode.LIGHT.value } summary = "%s" @@ -150,17 +150,17 @@ class SettingsGeneralController : SettingsController() { R.string.theme_light_blue ) entryValues = arrayOf( - Values.THEME_LIGHT_DEFAULT, - Values.THEME_LIGHT_BLUE + Values.LightThemeVariant.DEFAULT.value, + Values.LightThemeVariant.BLUE.value ) - defaultValue = Values.THEME_LIGHT_DEFAULT + defaultValue = Values.LightThemeVariant.DEFAULT.value summary = "%s" - preferences.themeMode().asImmediateFlow { isVisible = it != Values.THEME_MODE_DARK } + preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.DARK.value } .launchIn(scope) onChange { - if (preferences.themeMode().get() != Values.THEME_MODE_DARK) { + if (preferences.themeMode().get() != Values.ThemeMode.DARK.value) { activity?.recreate() } true @@ -175,18 +175,18 @@ class SettingsGeneralController : SettingsController() { R.string.theme_dark_amoled ) entryValues = arrayOf( - Values.THEME_DARK_DEFAULT, - Values.THEME_DARK_BLUE, - Values.THEME_DARK_AMOLED + Values.DarkThemeVariant.DEFAULT.value, + Values.DarkThemeVariant.BLUE.value, + Values.DarkThemeVariant.AMOLED.value ) - defaultValue = Values.THEME_DARK_DEFAULT + defaultValue = Values.DarkThemeVariant.DEFAULT.value summary = "%s" - preferences.themeMode().asImmediateFlow { isVisible = it != Values.THEME_MODE_LIGHT } + preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.LIGHT.value } .launchIn(scope) onChange { - if (preferences.themeMode().get() != Values.THEME_MODE_LIGHT) { + if (preferences.themeMode().get() != Values.ThemeMode.LIGHT.value) { activity?.recreate() } true