Fix off-screen fetcher jobs blocking decode queue

This commit is contained in:
FooIbar authored and renovate[bot] committed 2024-10-29 06:56:24 +08:00
1 parent 4cefa439ec
commit bc5032b2d0
5 files changed
+27

No files matched your search

@@ -143,6 +143,10 @@ class ArchivePageLoader(
override val isReady: Boolean
get() = size != 0
override fun onCancelRequest(index: Int) {
jobs[index]?.cancel()
}
override val title by lazy {
FileUtils.getNameFromFilename(file.name)!!
}
@@ -66,6 +66,10 @@ class EhPageLoader(private val mGalleryInfo: GalleryInfo, startPage: Int) :
override val isReady: Boolean
get() = ::mSpiderQueen.isInitialized && mSpiderQueen.isReady
override fun onCancelRequest(index: Int) {
mSpiderQueen.cancelRequest(index)
}
override fun onGetPages(pages: Int) {}
override fun onGet509(index: Int) {}
@@ -109,6 +109,12 @@ abstract class PageLoader {
protected abstract fun onForceRequest(index: Int, orgImg: Boolean)
fun cancelRequest(index: Int) {
onCancelRequest(index)
}
protected abstract fun onCancelRequest(index: Int)
fun notifyPageWait(index: Int) {
pages[index].reset()
}
@@ -281,6 +281,10 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
}
}
fun cancelRequest(index: Int) {
mWorkerScope.cancelDecode(index)
}
fun preloadPages(pages: List<Int>, pair: Pair<Int, Int>) {
mWorkerScope.updateRAList(pages, pair)
}
@@ -503,6 +507,10 @@ class SpiderQueen private constructor(val galleryInfo: GalleryInfo) : CoroutineS
var isDownloadMode = false
private set
fun cancelDecode(index: Int) {
decoder.cancel(index)
}
@Synchronized
fun enterDownloadMode() {
if (isDownloadMode) return
@@ -61,6 +61,11 @@ fun PagerItem(
}
}
}
DisposableEffect(Unit) {
onDispose {
pageLoader.cancelRequest(page.index)
}
}
val defaultError = stringResource(id = R.string.decode_image_error)
when (val state = page.statusObserved) {
is PageStatus.Queued, is PageStatus.Loading -> {