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
This commit is contained in:
parent
5f5fc77877
commit
b3854ad382
4 changed files with 15 additions and 12 deletions
|
@ -610,7 +610,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
binding.rightChapter.setTooltip(R.string.action_next_chapter)
|
binding.rightChapter.setTooltip(R.string.action_next_chapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
val loadingIndicatorContext = createReaderThemeContext(preferences.readerTheme().get())
|
val loadingIndicatorContext = createReaderThemeContext()
|
||||||
loadingIndicator = ReaderProgressIndicator(loadingIndicatorContext).apply {
|
loadingIndicator = ReaderProgressIndicator(loadingIndicatorContext).apply {
|
||||||
updateLayoutParams<FrameLayout.LayoutParams> {
|
updateLayoutParams<FrameLayout.LayoutParams> {
|
||||||
gravity = Gravity.CENTER
|
gravity = Gravity.CENTER
|
||||||
|
|
|
@ -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
|
* Context that has been wrapped to use the correct theme values based on the
|
||||||
* current app theme and reader background color
|
* 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
|
* 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() {
|
fun refresh() {
|
||||||
readerThemedContext = viewer.activity.createReaderThemeContext(viewer.config.theme)
|
readerThemedContext = viewer.activity.createReaderThemeContext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
||||||
* Context that has been wrapped to use the correct theme values based on the
|
* Context that has been wrapped to use the correct theme values based on the
|
||||||
* current app theme and reader background color
|
* 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
|
* Updates this adapter with the given [chapters]. It handles setting a few pages of the
|
||||||
|
@ -85,7 +85,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
||||||
}
|
}
|
||||||
|
|
||||||
fun refresh() {
|
fun refresh() {
|
||||||
readerThemedContext = viewer.activity.createReaderThemeContext(viewer.config.theme)
|
readerThemedContext = viewer.activity.createReaderThemeContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,6 @@ import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.content.res.ResourcesCompat
|
|
||||||
import androidx.core.graphics.alpha
|
import androidx.core.graphics.alpha
|
||||||
import androidx.core.graphics.blue
|
import androidx.core.graphics.blue
|
||||||
import androidx.core.graphics.green
|
import androidx.core.graphics.green
|
||||||
|
@ -40,8 +39,12 @@ import androidx.core.graphics.red
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity
|
||||||
import eu.kanade.tachiyomi.util.lang.truncateCenter
|
import eu.kanade.tachiyomi.util.lang.truncateCenter
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
@ -307,8 +310,9 @@ fun Context.isNightMode(): Boolean {
|
||||||
* Context wrapping method obtained from AppCompatDelegateImpl
|
* Context wrapping method obtained from AppCompatDelegateImpl
|
||||||
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java;l=348;drc=e28752c96fc3fb4d3354781469a1af3dbded4898
|
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:appcompat/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java;l=348;drc=e28752c96fc3fb4d3354781469a1af3dbded4898
|
||||||
*/
|
*/
|
||||||
fun Context.createReaderThemeContext(readerThemeSelected: Int): Context {
|
fun Context.createReaderThemeContext(): Context {
|
||||||
val isDarkBackground = when (readerThemeSelected) {
|
val prefs = Injekt.get<PreferencesHelper>()
|
||||||
|
val isDarkBackground = when (prefs.readerTheme().get()) {
|
||||||
1, 2 -> true // Black, Gray
|
1, 2 -> true // Black, Gray
|
||||||
3 -> applicationContext.isNightMode() // Automatic bg uses activity background by default
|
3 -> applicationContext.isNightMode() // Automatic bg uses activity background by default
|
||||||
else -> false // White
|
else -> false // White
|
||||||
|
@ -319,11 +323,10 @@ fun Context.createReaderThemeContext(readerThemeSelected: Int): Context {
|
||||||
overrideConf.setTo(resources.configuration)
|
overrideConf.setTo(resources.configuration)
|
||||||
overrideConf.uiMode = (overrideConf.uiMode and Configuration.UI_MODE_NIGHT_MASK.inv()) or expected
|
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)
|
wrappedContext.applyOverrideConfiguration(overrideConf)
|
||||||
if (theme != null) {
|
BaseThemedActivity.getThemeResIds(prefs.appTheme().get(), prefs.themeDarkAmoled().get())
|
||||||
ResourcesCompat.ThemeCompat.rebase(wrappedContext.theme)
|
.forEach { wrappedContext.theme.applyStyle(it, true) }
|
||||||
}
|
|
||||||
return wrappedContext
|
return wrappedContext
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
|
|
Reference in a new issue