Fix amoled themes not showing correctly

Fixes #886
This commit is contained in:
Jays2Kings 2021-07-05 20:15:30 -04:00
parent 4b46c0f6a7
commit d0bc413581
2 changed files with 11 additions and 9 deletions

View File

@ -1,11 +1,13 @@
package eu.kanade.tachiyomi.util.system
import android.app.Activity
import android.content.Context
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
object ThemeUtil {
@ -36,8 +38,9 @@ object ThemeUtil {
return theme.styleRes == R.style.Theme_Tachiyomi_AllBlue
}
fun isPitchBlack(context: Context, theme: Themes): Boolean {
return context.isInNightMode() && theme.darkBackground == Color.BLACK
fun isPitchBlack(context: Context): Boolean {
val preferences: PreferencesHelper by injectLazy()
return context.isInNightMode() && preferences.themeDarkAmoled().get()
}
fun hasDarkActionBarInLight(context: Context, theme: Themes): Boolean {
@ -52,11 +55,10 @@ object ThemeUtil {
}
}
fun Activity.setThemeAndNight(preferences: PreferencesHelper) {
fun AppCompatActivity.setThemeAndNight(preferences: PreferencesHelper) {
if (preferences.nightMode().isNotSet()) {
ThemeUtil.convertTheme(preferences, preferences.oldTheme())
}
AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get())
val theme = getPrefTheme(preferences)
setTheme(theme.styleRes)
@ -66,6 +68,9 @@ fun Activity.setThemeAndNight(preferences: PreferencesHelper) {
setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue)
}
}
lifecycle.coroutineScope.launchWhenCreated {
AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get())
}
}
fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {

View File

@ -42,11 +42,9 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.lang.tintText
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.getPrefTheme
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.pxToDp
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.math.max
import kotlin.math.pow
@ -76,8 +74,7 @@ fun View.snack(
if (f != null) {
snack.f()
}
val theme = context.getPrefTheme(Injekt.get())
if (ThemeUtil.isPitchBlack(context, theme)) {
if (ThemeUtil.isPitchBlack(context)) {
val textView: TextView =
snack.view.findViewById(com.google.android.material.R.id.snackbar_text)
val button: Button? =