fix: Status bar and navbar is not updated upon changing from light to dark theme

Also figured out why status bar is always dark
This commit is contained in:
ziro 2024-02-09 14:54:17 +07:00
parent 07a988157d
commit 0ab2a929e4
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 11 additions and 8 deletions

View file

@ -6,6 +6,7 @@ import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.core.view.WindowInsetsControllerCompat
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
@ -57,12 +58,13 @@ object ThemeUtil {
fun AppCompatActivity.setThemeByPref(preferences: PreferencesHelper) {
setTheme(getPrefTheme(preferences).styleRes)
val wic = WindowInsetsControllerCompat(window, window.decorView)
wic.isAppearanceLightStatusBars = preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_NO
wic.isAppearanceLightNavigationBars = preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_NO
}
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()
val useAmoled = isDarkMode(preferences) && preferences.themeDarkAmoled().get()
if (oldTheme != null && useAmoled) {
val array = oldTheme.obtainStyledAttributes(intArrayOf(R.attr.background))
val bg = array.getColor(0, 0)
@ -76,13 +78,14 @@ fun AppCompatActivity.getThemeWithExtras(theme: Resources.Theme, preferences: Pr
return theme
}
fun Context.isDarkMode(preferences: PreferencesHelper) =
applicationContext.isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES
fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {
// Using a try catch in case I start to remove themes
return try {
(
if ((applicationContext.isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES) &&
preferences.nightMode().get() != AppCompatDelegate.MODE_NIGHT_NO
) {
if (isDarkMode(preferences) && preferences.nightMode().get() != AppCompatDelegate.MODE_NIGHT_NO) {
preferences.darkTheme()
} else {
preferences.lightTheme()

View file

@ -224,8 +224,8 @@
<item name="postSplashScreenTheme">@style/Theme.Tachiyomi</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
</style>
<style name="Theme.OSS" parent="Theme.Tachiyomi.Monet">