Use enums for other PreferenceValues
This commit is contained in:
parent
0af81c7d05
commit
a0f5633094
@ -5,16 +5,22 @@ package eu.kanade.tachiyomi.data.preference
|
|||||||
*/
|
*/
|
||||||
object PreferenceValues {
|
object PreferenceValues {
|
||||||
|
|
||||||
const val THEME_MODE_LIGHT = "light"
|
enum class ThemeMode(val value: String) {
|
||||||
const val THEME_MODE_DARK = "dark"
|
LIGHT("light"),
|
||||||
const val THEME_MODE_SYSTEM = "system"
|
DARK("dark"),
|
||||||
|
SYSTEM("system"),
|
||||||
|
}
|
||||||
|
|
||||||
const val THEME_LIGHT_DEFAULT = "default"
|
enum class LightThemeVariant(val value: String) {
|
||||||
const val THEME_LIGHT_BLUE = "blue"
|
DEFAULT("default"),
|
||||||
|
BLUE("blue"),
|
||||||
|
}
|
||||||
|
|
||||||
const val THEME_DARK_DEFAULT = "default"
|
enum class DarkThemeVariant(val value: String) {
|
||||||
const val THEME_DARK_BLUE = "blue"
|
DEFAULT("default"),
|
||||||
const val THEME_DARK_AMOLED = "amoled"
|
BLUE("blue"),
|
||||||
|
AMOLED("amoled"),
|
||||||
|
}
|
||||||
|
|
||||||
enum class DisplayMode(val value: Int) {
|
enum class DisplayMode(val value: Int) {
|
||||||
COMPACT_GRID(0),
|
COMPACT_GRID(0),
|
||||||
|
@ -69,11 +69,11 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun clear() = prefs.edit().clear().apply()
|
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)
|
fun rotation() = flowPrefs.getInt(Keys.rotation, 1)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
|
|
||||||
private val lightTheme: Int by lazy {
|
private val lightTheme: Int by lazy {
|
||||||
when (preferences.themeLight().get()) {
|
when (preferences.themeLight().get()) {
|
||||||
Values.THEME_LIGHT_BLUE -> R.style.Theme_Tachiyomi_LightBlue
|
Values.LightThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_LightBlue
|
||||||
else -> {
|
else -> {
|
||||||
when {
|
when {
|
||||||
// Light status + navigation bar
|
// Light status + navigation bar
|
||||||
@ -47,8 +47,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
|
|
||||||
private val darkTheme: Int by lazy {
|
private val darkTheme: Int by lazy {
|
||||||
when (preferences.themeDark().get()) {
|
when (preferences.themeDark().get()) {
|
||||||
Values.THEME_DARK_BLUE -> R.style.Theme_Tachiyomi_DarkBlue
|
Values.DarkThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_DarkBlue
|
||||||
Values.THEME_DARK_AMOLED -> R.style.Theme_Tachiyomi_Amoled
|
Values.DarkThemeVariant.AMOLED.value -> R.style.Theme_Tachiyomi_Amoled
|
||||||
else -> R.style.Theme_Tachiyomi_Dark
|
else -> R.style.Theme_Tachiyomi_Dark
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,14 +61,14 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setTheme(
|
setTheme(
|
||||||
when (preferences.themeMode().get()) {
|
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) {
|
if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) {
|
||||||
darkTheme
|
darkTheme
|
||||||
} else {
|
} else {
|
||||||
lightTheme
|
lightTheme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Values.THEME_MODE_DARK -> darkTheme
|
Values.ThemeMode.DARK.value -> darkTheme
|
||||||
else -> lightTheme
|
else -> lightTheme
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -118,21 +118,21 @@ class SettingsGeneralController : SettingsController() {
|
|||||||
R.string.theme_dark
|
R.string.theme_dark
|
||||||
)
|
)
|
||||||
entryValues = arrayOf(
|
entryValues = arrayOf(
|
||||||
Values.THEME_MODE_SYSTEM,
|
Values.ThemeMode.SYSTEM.value,
|
||||||
Values.THEME_MODE_LIGHT,
|
Values.ThemeMode.LIGHT.value,
|
||||||
Values.THEME_MODE_DARK
|
Values.ThemeMode.DARK.value
|
||||||
)
|
)
|
||||||
defaultValue = Values.THEME_MODE_SYSTEM
|
defaultValue = Values.ThemeMode.SYSTEM.value
|
||||||
} else {
|
} else {
|
||||||
entriesRes = arrayOf(
|
entriesRes = arrayOf(
|
||||||
R.string.theme_light,
|
R.string.theme_light,
|
||||||
R.string.theme_dark
|
R.string.theme_dark
|
||||||
)
|
)
|
||||||
entryValues = arrayOf(
|
entryValues = arrayOf(
|
||||||
Values.THEME_MODE_LIGHT,
|
Values.ThemeMode.LIGHT.value,
|
||||||
Values.THEME_MODE_DARK
|
Values.ThemeMode.DARK.value
|
||||||
)
|
)
|
||||||
defaultValue = Values.THEME_MODE_LIGHT
|
defaultValue = Values.ThemeMode.LIGHT.value
|
||||||
}
|
}
|
||||||
|
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
@ -150,17 +150,17 @@ class SettingsGeneralController : SettingsController() {
|
|||||||
R.string.theme_light_blue
|
R.string.theme_light_blue
|
||||||
)
|
)
|
||||||
entryValues = arrayOf(
|
entryValues = arrayOf(
|
||||||
Values.THEME_LIGHT_DEFAULT,
|
Values.LightThemeVariant.DEFAULT.value,
|
||||||
Values.THEME_LIGHT_BLUE
|
Values.LightThemeVariant.BLUE.value
|
||||||
)
|
)
|
||||||
defaultValue = Values.THEME_LIGHT_DEFAULT
|
defaultValue = Values.LightThemeVariant.DEFAULT.value
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
preferences.themeMode().asImmediateFlow { isVisible = it != Values.THEME_MODE_DARK }
|
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.DARK.value }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
onChange {
|
onChange {
|
||||||
if (preferences.themeMode().get() != Values.THEME_MODE_DARK) {
|
if (preferences.themeMode().get() != Values.ThemeMode.DARK.value) {
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@ -175,18 +175,18 @@ class SettingsGeneralController : SettingsController() {
|
|||||||
R.string.theme_dark_amoled
|
R.string.theme_dark_amoled
|
||||||
)
|
)
|
||||||
entryValues = arrayOf(
|
entryValues = arrayOf(
|
||||||
Values.THEME_DARK_DEFAULT,
|
Values.DarkThemeVariant.DEFAULT.value,
|
||||||
Values.THEME_DARK_BLUE,
|
Values.DarkThemeVariant.BLUE.value,
|
||||||
Values.THEME_DARK_AMOLED
|
Values.DarkThemeVariant.AMOLED.value
|
||||||
)
|
)
|
||||||
defaultValue = Values.THEME_DARK_DEFAULT
|
defaultValue = Values.DarkThemeVariant.DEFAULT.value
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
preferences.themeMode().asImmediateFlow { isVisible = it != Values.THEME_MODE_LIGHT }
|
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.LIGHT.value }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
onChange {
|
onChange {
|
||||||
if (preferences.themeMode().get() != Values.THEME_MODE_LIGHT) {
|
if (preferences.themeMode().get() != Values.ThemeMode.LIGHT.value) {
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
Loading…
Reference in New Issue
Block a user