Avoid crashes when fetching assist content URL in ReaderActivity

This commit is contained in:
arkon 2023-01-08 15:23:06 -05:00
parent 4cd01428ed
commit e265b929a1
2 changed files with 9 additions and 4 deletions

View File

@ -122,6 +122,7 @@ class ReaderActivity : BaseActivity() {
lateinit var binding: ReaderActivityBinding
val viewModel by viewModels<ReaderViewModel>()
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