mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 05:19:16 +01:00
Refactor amoled theme configuration
Because I'm tired of being flashed and the double fingerprint popup and other issues Fixes #924
This commit is contained in:
parent
ef166dd712
commit
f56fe25010
@ -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<VB : ViewBinding> : AppCompatActivity() {
|
||||
SecureActivityDelegate.promptLockIfNeeded(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTheme(): Resources.Theme {
|
||||
return getThemeWithExtras(super.getTheme(), preferences)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user