From e265b929a19d3258cbe305d5b4a2d2bdcf1eb9ec Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 8 Jan 2023 15:23:06 -0500 Subject: [PATCH] Avoid crashes when fetching assist content URL in ReaderActivity --- .../{GlobalSerachCard.kt => GlobalSearchCard.kt} | 0 .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 13 +++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) rename app/src/main/java/eu/kanade/presentation/browse/components/{GlobalSerachCard.kt => GlobalSearchCard.kt} (100%) diff --git a/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSerachCard.kt b/app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt similarity index 100% rename from app/src/main/java/eu/kanade/presentation/browse/components/GlobalSerachCard.kt rename to app/src/main/java/eu/kanade/presentation/browse/components/GlobalSearchCard.kt 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 5be20f21d..def083f3c 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 @@ -122,6 +122,7 @@ class ReaderActivity : BaseActivity() { lateinit var binding: ReaderActivityBinding val viewModel by viewModels() + private var assistUrl: String? = null val hasCutout by lazy { hasDisplayCutout() } @@ -301,9 +302,7 @@ class ReaderActivity : BaseActivity() { override fun onProvideAssistContent(outContent: AssistContent) { super.onProvideAssistContent(outContent) - viewModel.getChapterUrl()?.let { url -> - outContent.webUri = url.toUri() - } + assistUrl?.let { outContent.webUri = it.toUri() } } /** @@ -764,6 +763,12 @@ class ReaderActivity : BaseActivity() { // Invalidate menu to show proper chapter bookmark state invalidateOptionsMenu() + + lifecycleScope.launchIO { + viewModel.getChapterUrl()?.let { url -> + assistUrl = url + } + } } /** @@ -796,7 +801,7 @@ class ReaderActivity : BaseActivity() { * Moves the viewer to the given page [index]. It does nothing if the viewer is null or the * page is not found. */ - fun moveToPageIndex(index: Int) { + private fun moveToPageIndex(index: Int) { val viewer = viewer ?: return val currentChapter = viewModel.getCurrentChapter() ?: return val page = currentChapter.pages?.getOrNull(index) ?: return