From b3854ad3829dbb97831cd8db3defeb967a89334e Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 26 Aug 2021 04:27:34 +0700 Subject: [PATCH] Fix reader crash on Android 9 (#5789) * Fix failed reader context creation on v28 * Re-apply the reader styles manually after overriding night mode This commit replaces the ThemeCompat.rebase() call since the private API used is in dark greylist max target P, thus making it unreachable. * Revert "Fix failed reader context creation on v28" This reverts commit 6e2104d7 --- .../tachiyomi/ui/reader/ReaderActivity.kt | 2 +- .../reader/viewer/pager/PagerViewerAdapter.kt | 4 ++-- .../ui/reader/viewer/webtoon/WebtoonAdapter.kt | 4 ++-- .../tachiyomi/util/system/ContextExtensions.kt | 17 ++++++++++------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index c8acea3cd..6d08494bf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -610,7 +610,7 @@ class ReaderActivity : BaseRxActivity() binding.rightChapter.setTooltip(R.string.action_next_chapter) } - val loadingIndicatorContext = createReaderThemeContext(preferences.readerTheme().get()) + val loadingIndicatorContext = createReaderThemeContext() loadingIndicator = ReaderProgressIndicator(loadingIndicatorContext).apply { updateLayoutParams { gravity = Gravity.CENTER diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 6d70bdf28..24589ca0e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -37,7 +37,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { * Context that has been wrapped to use the correct theme values based on the * current app theme and reader background color */ - private var readerThemedContext = viewer.activity.createReaderThemeContext(viewer.config.theme) + private var readerThemedContext = viewer.activity.createReaderThemeContext() /** * Updates this adapter with the given [chapters]. It handles setting a few pages of the @@ -197,6 +197,6 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { } fun refresh() { - readerThemedContext = viewer.activity.createReaderThemeContext(viewer.config.theme) + readerThemedContext = viewer.activity.createReaderThemeContext() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index a48c90060..5f17b4ce1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -29,7 +29,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter() + val isDarkBackground = when (prefs.readerTheme().get()) { 1, 2 -> true // Black, Gray 3 -> applicationContext.isNightMode() // Automatic bg uses activity background by default else -> false // White @@ -319,11 +323,10 @@ fun Context.createReaderThemeContext(readerThemeSelected: Int): Context { overrideConf.setTo(resources.configuration) overrideConf.uiMode = (overrideConf.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or expected - val wrappedContext = ContextThemeWrapper(this, R.style.Theme_AppCompat_Empty) + val wrappedContext = ContextThemeWrapper(this, R.style.Theme_Tachiyomi) wrappedContext.applyOverrideConfiguration(overrideConf) - if (theme != null) { - ResourcesCompat.ThemeCompat.rebase(wrappedContext.theme) - } + BaseThemedActivity.getThemeResIds(prefs.appTheme().get(), prefs.themeDarkAmoled().get()) + .forEach { wrappedContext.theme.applyStyle(it, true) } return wrappedContext } return this