Skip to content

Commit

Permalink
Fix amoled theme resetting on relaunch for older devices/system light…
Browse files Browse the repository at this point in the history
… theme
  • Loading branch information
Jays2Kings committed Jul 23, 2021
1 parent 1f11faa commit f1e4669
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
}

override fun getTheme(): Resources.Theme {
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
updatedTheme = newTheme
newTheme
}
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
return newTheme
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
updatedTheme = newTheme
newTheme
}
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
return newTheme
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ abstract class BaseThemedActivity : AppCompatActivity() {
}

override fun getTheme(): Resources.Theme {
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
updatedTheme = newTheme
newTheme
}
val newTheme = getThemeWithExtras(super.getTheme(), preferences, updatedTheme)
updatedTheme = newTheme
return newTheme
}
}
13 changes: 9 additions & 4 deletions app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand Down

0 comments on commit f1e4669

Please sign in to comment.