diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt index c502a86384..4eaf58344d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ThemeUtil.kt @@ -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 { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 4e0f7964b2..628fd3fdb6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -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? =