diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index c12fb8f66..5fdeb8964 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -6,14 +6,11 @@ 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" const val THEME_DARK_DEFAULT = "default" - + const val THEME_DARK_BLUE = "blue" const val THEME_DARK_AMOLED = "amoled" - const val THEME_DARK_BLUE = "blue" -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index fa37c318e..a875f9601 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -54,7 +54,7 @@ class PreferencesHelper(val context: Context) { fun clear() = prefs.edit().clear().apply() - fun themeMode() = prefs.getString(Keys.themeMode, Values.THEME_MODE_LIGHT) + fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_LIGHT) fun themeDark() = prefs.getString(Keys.themeDark, Values.THEME_DARK_DEFAULT) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 1d7a792c8..7da27f88c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.system.LocaleHelper import uy.kohesive.injekt.injectLazy import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values @@ -15,12 +16,13 @@ abstract class BaseActivity : AppCompatActivity() { val preferences: PreferencesHelper by injectLazy() - private val darkTheme: Int - get() = when (preferences.themeDark()) { + private val darkTheme: Int by lazy { + when (preferences.themeDark()) { Values.THEME_DARK_DEFAULT -> R.style.Theme_Tachiyomi_Dark Values.THEME_DARK_AMOLED -> R.style.Theme_Tachiyomi_Amoled else -> R.style.Theme_Tachiyomi_DarkBlue } + } init { @Suppress("LeakingThis") @@ -28,10 +30,9 @@ abstract class BaseActivity : AppCompatActivity() { } override fun onCreate(savedInstanceState: Bundle?) { - setTheme(when (preferences.themeMode()) { - Values.THEME_MODE_LIGHT -> R.style.Theme_Tachiyomi + setTheme(when (preferences.themeMode().getOrDefault()) { Values.THEME_MODE_DARK -> darkTheme - else -> { + Values.THEME_MODE_SYSTEM -> { val mode = getSystemService(Context.UI_MODE_SERVICE) as UiModeManager if (mode.nightMode == AppCompatDelegate.MODE_NIGHT_YES) { darkTheme @@ -39,7 +40,9 @@ abstract class BaseActivity : AppCompatActivity() { R.style.Theme_Tachiyomi } } + else -> R.style.Theme_Tachiyomi }) + super.onCreate(savedInstanceState) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index de90ef357..d7427711c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting import android.os.Build import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.preference.* import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys @@ -83,17 +84,20 @@ class SettingsGeneralController : SettingsController() { titleRes = R.string.pref_theme_dark entriesRes = arrayOf( R.string.theme_dark_default, - R.string.theme_dark_amoled, - R.string.theme_dark_blue) + R.string.theme_dark_blue, + R.string.theme_dark_amoled) entryValues = arrayOf( Values.THEME_DARK_DEFAULT, - Values.THEME_DARK_AMOLED, - Values.THEME_DARK_BLUE) + Values.THEME_DARK_BLUE, + Values.THEME_DARK_AMOLED) defaultValue = Values.THEME_DARK_DEFAULT summary = "%s" + preferences.themeMode().asObservable() + .subscribeUntilDestroy { isVisible = it != Values.THEME_MODE_LIGHT } + onChange { - if (preferences.themeMode() != Values.THEME_MODE_LIGHT) { + if (preferences.themeMode().getOrDefault() != Values.THEME_MODE_LIGHT) { activity?.recreate() } true diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e6c676900..ed53ea60e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -122,10 +122,10 @@ Light Dark Follow system - Dark theme + Dark theme variant Default - AMOLED Dark blue + AMOLED black Start screen Language System default