mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-23 21:55:57 +03:00
Use getEnum for theme preferences too
This commit is contained in:
parent
78a352541a
commit
f430b6f853
4 changed files with 40 additions and 37 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ abstract class BaseActivity<VB : ViewBinding> : 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<VB : ViewBinding> : 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<VB : ViewBinding> : 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
|
||||
}
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue