mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
Update app theme preference UI
Heavily influenced by TachiyomiJ2K.
This commit is contained in:
@@ -18,8 +18,13 @@ abstract class BaseThemedActivity : AppCompatActivity() {
|
||||
|
||||
companion object {
|
||||
fun AppCompatActivity.applyAppTheme(preferences: PreferencesHelper) {
|
||||
getThemeResIds(preferences.appTheme().get(), preferences.themeDarkAmoled().get())
|
||||
.forEach { setTheme(it) }
|
||||
}
|
||||
|
||||
fun getThemeResIds(appTheme: PreferenceValues.AppTheme, isAmoled: Boolean): List<Int> {
|
||||
val resIds = mutableListOf<Int>()
|
||||
when (preferences.appTheme().get()) {
|
||||
when (appTheme) {
|
||||
PreferenceValues.AppTheme.MONET -> {
|
||||
resIds += R.style.Theme_Tachiyomi_Monet
|
||||
}
|
||||
@@ -53,13 +58,11 @@ abstract class BaseThemedActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
if (preferences.themeDarkAmoled().get()) {
|
||||
if (isAmoled) {
|
||||
resIds += R.style.ThemeOverlay_Tachiyomi_Amoled
|
||||
}
|
||||
|
||||
resIds.forEach {
|
||||
setTheme(it)
|
||||
}
|
||||
return resIds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||
import eu.kanade.tachiyomi.util.preference.entriesRes
|
||||
import eu.kanade.tachiyomi.util.preference.initThenAdd
|
||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||
import eu.kanade.tachiyomi.util.preference.listPreference
|
||||
import eu.kanade.tachiyomi.util.preference.onChange
|
||||
@@ -17,6 +18,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.isTablet
|
||||
import eu.kanade.tachiyomi.widget.preference.ThemesPreference
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import java.util.Date
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
@@ -146,7 +148,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
|
||||
summary = "%s"
|
||||
}
|
||||
listPreference {
|
||||
initThenAdd(ThemesPreference(context)) {
|
||||
key = Keys.appTheme
|
||||
titleRes = R.string.pref_app_theme
|
||||
|
||||
@@ -158,10 +160,8 @@ class SettingsGeneralController : SettingsController() {
|
||||
}
|
||||
it.titleResId != null && monetFilter
|
||||
}
|
||||
entriesRes = appThemes.map { it.titleResId!! }.toTypedArray()
|
||||
entryValues = appThemes.map { it.name }.toTypedArray()
|
||||
entries = appThemes
|
||||
defaultValue = appThemes[0].name
|
||||
summary = "%s"
|
||||
|
||||
onChange {
|
||||
activity?.recreate()
|
||||
|
||||
Reference in New Issue
Block a user