Fix amoled theme resetting on relaunch for older devices/system light theme

This commit is contained in:
Jays2Kings 2021-07-23 18:49:38 -04:00
parent 1f11faaffd
commit f1e4669e5c
6 changed files with 29 additions and 32 deletions

View File

@ -41,10 +41,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
}
override fun getTheme(): Resources.Theme {
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
newTheme
}
return newTheme
}
}

View File

@ -36,10 +36,8 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
}
override fun getTheme(): Resources.Theme {
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
newTheme
}
return newTheme
}
}

View File

@ -26,10 +26,8 @@ abstract class BaseThemedActivity : AppCompatActivity() {
}
override fun getTheme(): Resources.Theme {
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
newTheme
}
return newTheme
}
}

View File

@ -98,12 +98,17 @@ fun AppCompatActivity.setThemeAndNight(preferences: PreferencesHelper) {
setTheme(theme.styleRes)
}
fun AppCompatActivity.getThemeWithExtras(theme: Resources.Theme, preferences: PreferencesHelper): Resources.Theme {
val prefTheme = getPrefTheme(preferences)
if ((isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES) &&
fun AppCompatActivity.getThemeWithExtras(theme: Resources.Theme, preferences: PreferencesHelper, oldTheme: Resources.Theme?): Resources.Theme {
val useAmoled = (isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES) &&
preferences.themeDarkAmoled().get()
) {
if (oldTheme != null) {
val array = oldTheme.obtainStyledAttributes(intArrayOf(android.R.attr.colorBackground))
val bg = array.getColor(0, 0)
if (bg == Color.BLACK && useAmoled) { return oldTheme }
}
if (useAmoled) {
theme.applyStyle(R.style.ThemeOverlay_Tachiyomi_Amoled, true)
val prefTheme = getPrefTheme(preferences)
if (ThemeUtil.isColoredTheme(prefTheme)) {
theme.applyStyle(R.style.ThemeOverlay_Tachiyomi_AllBlue, true)
}

View File

@ -6,18 +6,6 @@
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<!--== AMOLED theme overlay ==-->
<style name="ThemeOverlay.Tachiyomi.Amoled" parent="">
<item name="colorSecondary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryVariant">@color/colorAmoledPrimary</item>
<item name="colorOnPrimary">@color/colorAmoledPrimary</item>
<item name="android:colorBackground">@color/colorAmoledPrimary</item>
<item name="readerBackground">@color/colorAmoledPrimary</item>
<!-- Material Dialog colors -->
<item name="md_background_color">@color/colorAmoledPrimary</item>
</style>
<style name="Theme.Tachiyomi.Strawberries">
<item name="colorPrimary">@color/primaryRed</item>
<item name="colorAccent">@color/holo_red</item>

View File

@ -80,7 +80,17 @@
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<style name="ThemeOverlay.Tachiyomi.Amoled" parent=""/>
<style name="ThemeOverlay.Tachiyomi.Amoled" parent="">
<item name="colorSecondary">@color/md_black_1000</item>
<item name="colorPrimaryVariant">@color/md_black_1000</item>
<item name="colorOnPrimary">@color/md_black_1000</item>
<item name="android:colorBackground">@color/md_black_1000</item>
<item name="readerBackground">@color/md_black_1000</item>
<!-- Material Dialog colors -->
<item name="md_background_color">@color/md_black_1000</item>
</style>
<style name="Theme.Tachiyomi.FlatLime"/>