Use enums for other PreferenceValues

This commit is contained in:
arkon 2020-05-25 14:07:12 -04:00
parent 0af81c7d05
commit a0f5633094
4 changed files with 40 additions and 34 deletions

View file

@ -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),

View file

@ -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)

View file

@ -25,7 +25,7 @@ abstract class BaseActivity<VB : ViewBinding> : 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<VB : ViewBinding> : 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<VB : ViewBinding> : 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
}
)

View file

@ -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