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 612efe9d2a..df03654e59 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.base.activity import android.content.Context +import android.content.res.Resources import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.viewbinding.ViewBinding @@ -9,6 +10,7 @@ import eu.kanade.tachiyomi.ui.main.SearchActivity import eu.kanade.tachiyomi.ui.security.BiometricActivity import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.system.getThemeWithExtras import eu.kanade.tachiyomi.util.system.setThemeAndNight import uy.kohesive.injekt.injectLazy @@ -34,4 +36,8 @@ abstract class BaseActivity : AppCompatActivity() { SecureActivityDelegate.promptLockIfNeeded(this) } } + + override fun getTheme(): Resources.Theme { + return getThemeWithExtras(super.getTheme(), preferences) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt index 2360b07495..eb100a8e0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt @@ -1,11 +1,13 @@ package eu.kanade.tachiyomi.ui.base.activity import android.content.Context +import android.content.res.Resources import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.setThemeAndNight import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.system.getThemeWithExtras import uy.kohesive.injekt.injectLazy abstract class BaseThemedActivity : AppCompatActivity() { @@ -20,4 +22,8 @@ abstract class BaseThemedActivity : AppCompatActivity() { setThemeAndNight(preferences) super.onCreate(savedInstanceState) } + + override fun getTheme(): Resources.Theme { + return getThemeWithExtras(super.getTheme(), preferences) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt index 40851203f3..974cf65a60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt @@ -1,10 +1,10 @@ package eu.kanade.tachiyomi.util.system import android.content.Context +import android.content.res.Resources import android.graphics.Color import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate -import androidx.lifecycle.coroutineScope import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import uy.kohesive.injekt.injectLazy @@ -59,22 +59,22 @@ fun AppCompatActivity.setThemeAndNight(preferences: PreferencesHelper) { if (preferences.nightMode().isNotSet()) { ThemeUtil.convertTheme(preferences, preferences.oldTheme()) } + if (AppCompatDelegate.getDefaultNightMode() != preferences.nightMode().get()) { + AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get()) + } val theme = getPrefTheme(preferences) setTheme(theme.styleRes) +} - if (theme.isDarkTheme && preferences.themeDarkAmoled().get()) { - setTheme(R.style.ThemeOverlay_Tachiyomi_Amoled) - if (ThemeUtil.isColoredTheme(theme)) { - setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue) - } - if (!isInNightMode()) { - lifecycle.coroutineScope.launchWhenCreated { - AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get()) - } - return +fun AppCompatActivity.getThemeWithExtras(theme: Resources.Theme, preferences: PreferencesHelper): Resources.Theme { + val prefTheme = getPrefTheme(preferences) + if (prefTheme.isDarkTheme && preferences.themeDarkAmoled().get()) { + theme.applyStyle(R.style.ThemeOverlay_Tachiyomi_Amoled, true) + if (ThemeUtil.isColoredTheme(prefTheme)) { + theme.applyStyle(R.style.ThemeOverlay_Tachiyomi_AllBlue, true) } } - AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get()) + return theme } fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {