From a0f05928e038c194ad3d3bff67a83f87b6a5528f Mon Sep 17 00:00:00 2001 From: TwistedUmbrellaX <1173913+AbandonedCart@users.noreply.github.com> Date: Mon, 11 Mar 2024 04:51:55 -0400 Subject: [PATCH] fix: reapply theme to each init call (#235) --- app/src/main/java/ani/dantotsu/Functions.kt | 11 ++++++----- .../ani/dantotsu/media/anime/AnimeWatchFragment.kt | 2 ++ .../ani/dantotsu/media/manga/MangaReadFragment.kt | 1 + app/src/main/java/ani/dantotsu/themes/ThemeManager.kt | 8 ++++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index aafad39f2c..f3f59fcb2d 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -167,6 +167,7 @@ fun initActivity(a: Activity) { navBarHeight = insets.bottom } } + if (a !is MainActivity) a.setNavigationTheme() } fun Activity.hideSystemBars() { @@ -178,11 +179,11 @@ fun Activity.hideSystemBars() { } fun Activity.setNavigationTheme() { - val a = TypedValue() - theme.resolveAttribute(android.R.attr.colorBackground, a, true) - if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && a.isColorType) - || (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)) { - window.navigationBarColor = a.data + val tv = TypedValue() + theme.resolveAttribute(android.R.attr.colorBackground, tv, true) + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && tv.isColorType) + || (tv.type >= TypedValue.TYPE_FIRST_COLOR_INT && tv.type <= TypedValue.TYPE_LAST_COLOR_INT)) { + window.navigationBarColor = tv.data } } diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt index d1aa973036..fc8141e209 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchFragment.kt @@ -559,6 +559,8 @@ class AnimeWatchFragment : Fragment() { super.onResume() binding.mediaInfoProgressBar.visibility = progress binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state) + + requireActivity().setNavigationTheme() } override fun onPause() { diff --git a/app/src/main/java/ani/dantotsu/media/manga/MangaReadFragment.kt b/app/src/main/java/ani/dantotsu/media/manga/MangaReadFragment.kt index 6b979319e2..9fda920fba 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/MangaReadFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/MangaReadFragment.kt @@ -601,6 +601,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener { super.onResume() binding.mediaInfoProgressBar.visibility = progress binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state) + requireActivity().setNavigationTheme() } diff --git a/app/src/main/java/ani/dantotsu/themes/ThemeManager.kt b/app/src/main/java/ani/dantotsu/themes/ThemeManager.kt index 27dd2cc91c..05e1c5de51 100644 --- a/app/src/main/java/ani/dantotsu/themes/ThemeManager.kt +++ b/app/src/main/java/ani/dantotsu/themes/ThemeManager.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.content.res.Configuration import android.graphics.Bitmap +import android.os.Build import android.view.Window import android.view.WindowManager import ani.dantotsu.R @@ -54,7 +55,10 @@ class ThemeManager(private val context: Activity) { } val window = context.window - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + @Suppress("DEPRECATION") + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) + } window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) window.statusBarColor = 0x00000000 context.setTheme(themeToApply) @@ -137,7 +141,7 @@ class ThemeManager(private val context: Activity) { companion object { fun fromString(value: String): Theme { - return values().find { it.theme == value } ?: PURPLE + return entries.find { it.theme == value } ?: PURPLE } } }