Fix performance of pure black themes

Fixes #933
This commit is contained in:
Jays2Kings 2021-07-17 01:18:26 -04:00
parent b099524f54
commit e72356eb1e
4 changed files with 24 additions and 5 deletions

View File

@ -20,11 +20,14 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
lateinit var binding: VB
val isBindingInitialized get() = this::binding.isInitialized
private var updatedTheme: Resources.Theme? = null
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase))
}
override fun onCreate(savedInstanceState: Bundle?) {
updatedTheme = null
setThemeAndNight(preferences)
super.onCreate(savedInstanceState)
SecureActivityDelegate.setSecure(this)
@ -38,6 +41,10 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
}
override fun getTheme(): Resources.Theme {
return getThemeWithExtras(super.getTheme(), preferences)
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
updatedTheme = newTheme
newTheme
}
}
}

View File

@ -7,6 +7,7 @@ import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
import eu.kanade.tachiyomi.util.system.setThemeAndNight
import eu.kanade.tachiyomi.util.system.LocaleHelper
import eu.kanade.tachiyomi.util.system.getThemeWithExtras
import nucleus.view.NucleusAppCompatActivity
@ -16,12 +17,15 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
val scope = lifecycleScope
private val preferences by injectLazy<PreferencesHelper>()
private var updatedTheme: Resources.Theme? = null
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase))
}
override fun onCreate(savedInstanceState: Bundle?) {
updatedTheme = null
setThemeAndNight(preferences)
super.onCreate(savedInstanceState)
SecureActivityDelegate.setSecure(this)
}
@ -32,6 +36,10 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
}
override fun getTheme(): Resources.Theme {
return getThemeWithExtras(super.getTheme(), preferences)
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
updatedTheme = newTheme
newTheme
}
}
}

View File

@ -13,17 +13,23 @@ import uy.kohesive.injekt.injectLazy
abstract class BaseThemedActivity : AppCompatActivity() {
val preferences: PreferencesHelper by injectLazy()
private var updatedTheme: Resources.Theme? = null
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LocaleHelper.createLocaleWrapper(newBase))
}
override fun onCreate(savedInstanceState: Bundle?) {
updatedTheme = null
setThemeAndNight(preferences)
super.onCreate(savedInstanceState)
}
override fun getTheme(): Resources.Theme {
return getThemeWithExtras(super.getTheme(), preferences)
return updatedTheme ?: run {
val newTheme = getThemeWithExtras(super.getTheme(), preferences)
updatedTheme = newTheme
newTheme
}
}
}

View File

@ -78,7 +78,6 @@ import eu.kanade.tachiyomi.util.system.isTablet
import eu.kanade.tachiyomi.util.system.launchIO
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.setThemeAndNight
import eu.kanade.tachiyomi.util.system.spToPx
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.collapse
@ -204,7 +203,6 @@ class ReaderActivity :
* Called when the activity is created. Initializes the presenter and configuration.
*/
override fun onCreate(savedInstanceState: Bundle?) {
setThemeAndNight(preferences)
super.onCreate(savedInstanceState)
binding = ReaderActivityBinding.inflate(layoutInflater)
setContentView(binding.root)