mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 11:17:25 +01:00
Use getEnum for theme preferences too
This commit is contained in:
parent
78a352541a
commit
f430b6f853
@ -5,21 +5,24 @@ package eu.kanade.tachiyomi.data.preference
|
|||||||
*/
|
*/
|
||||||
object PreferenceValues {
|
object PreferenceValues {
|
||||||
|
|
||||||
enum class ThemeMode(val value: String) {
|
// Keys are lowercase to match legacy string values
|
||||||
LIGHT("light"),
|
enum class ThemeMode {
|
||||||
DARK("dark"),
|
light,
|
||||||
SYSTEM("system"),
|
dark,
|
||||||
|
system,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class LightThemeVariant(val value: String) {
|
// Keys are lowercase to match legacy string values
|
||||||
DEFAULT("default"),
|
enum class LightThemeVariant {
|
||||||
BLUE("blue"),
|
default,
|
||||||
|
blue,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DarkThemeVariant(val value: String) {
|
// Keys are lowercase to match legacy string values
|
||||||
DEFAULT("default"),
|
enum class DarkThemeVariant {
|
||||||
BLUE("blue"),
|
default,
|
||||||
AMOLED("amoled"),
|
blue,
|
||||||
|
amoled,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DisplayMode {
|
enum class DisplayMode {
|
||||||
|
@ -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.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)
|
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.LightThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_LightBlue
|
Values.LightThemeVariant.blue -> 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.DarkThemeVariant.BLUE.value -> R.style.Theme_Tachiyomi_DarkBlue
|
Values.DarkThemeVariant.blue -> R.style.Theme_Tachiyomi_DarkBlue
|
||||||
Values.DarkThemeVariant.AMOLED.value -> R.style.Theme_Tachiyomi_Amoled
|
Values.DarkThemeVariant.amoled -> 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.ThemeMode.SYSTEM.value -> {
|
Values.ThemeMode.system -> {
|
||||||
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.ThemeMode.DARK.value -> darkTheme
|
Values.ThemeMode.dark -> 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.ThemeMode.SYSTEM.value,
|
Values.ThemeMode.system.name,
|
||||||
Values.ThemeMode.LIGHT.value,
|
Values.ThemeMode.light.name,
|
||||||
Values.ThemeMode.DARK.value
|
Values.ThemeMode.dark.name
|
||||||
)
|
)
|
||||||
defaultValue = Values.ThemeMode.SYSTEM.value
|
defaultValue = Values.ThemeMode.system.name
|
||||||
} 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.ThemeMode.LIGHT.value,
|
Values.ThemeMode.light.name,
|
||||||
Values.ThemeMode.DARK.value
|
Values.ThemeMode.dark.name
|
||||||
)
|
)
|
||||||
defaultValue = Values.ThemeMode.LIGHT.value
|
defaultValue = Values.ThemeMode.light.name
|
||||||
}
|
}
|
||||||
|
|
||||||
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.LightThemeVariant.DEFAULT.value,
|
Values.LightThemeVariant.default.name,
|
||||||
Values.LightThemeVariant.BLUE.value
|
Values.LightThemeVariant.blue.name
|
||||||
)
|
)
|
||||||
defaultValue = Values.LightThemeVariant.DEFAULT.value
|
defaultValue = Values.LightThemeVariant.default.name
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.DARK.value }
|
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.dark }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
onChange {
|
onChange {
|
||||||
if (preferences.themeMode().get() != Values.ThemeMode.DARK.value) {
|
if (preferences.themeMode().get() != Values.ThemeMode.dark) {
|
||||||
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.DarkThemeVariant.DEFAULT.value,
|
Values.DarkThemeVariant.default.name,
|
||||||
Values.DarkThemeVariant.BLUE.value,
|
Values.DarkThemeVariant.blue.name,
|
||||||
Values.DarkThemeVariant.AMOLED.value
|
Values.DarkThemeVariant.amoled.name
|
||||||
)
|
)
|
||||||
defaultValue = Values.DarkThemeVariant.DEFAULT.value
|
defaultValue = Values.DarkThemeVariant.default.name
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.LIGHT.value }
|
preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light }
|
||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
|
|
||||||
onChange {
|
onChange {
|
||||||
if (preferences.themeMode().get() != Values.ThemeMode.LIGHT.value) {
|
if (preferences.themeMode().get() != Values.ThemeMode.light) {
|
||||||
activity?.recreate()
|
activity?.recreate()
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
|
Loading…
Reference in New Issue
Block a user