diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt index e3adc33b9..759037936 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/HttpPageLoader.kt @@ -65,11 +65,16 @@ internal class HttpPageLoader( scope.launchIO { flow { while (true) { - emit(runInterruptible { queue.take() }.page) + emit(runInterruptible { queue.take() }) } } - .filter { it.status == Page.State.Queue } - .collect(::internalLoadPage) + .filter { it.page.status == Page.State.Queue } + .collect { + internalLoadPage( + page = it.page, + force = it.priority == PriorityPage.RETRY, + ) + } } // EXH --> } @@ -125,7 +130,7 @@ internal class HttpPageLoader( val queuedPages = mutableListOf() if (page.status == Page.State.Queue) { - queuedPages += PriorityPage(page, 1).also { queue.offer(it) } + queuedPages += PriorityPage(page, PriorityPage.DEFAULT).also { queue.offer(it) } } queuedPages += preloadNextPages(page, preloadSize) @@ -157,7 +162,7 @@ internal class HttpPageLoader( boostPage(page) } else { // EXH <-- - queue.offer(PriorityPage(page, 2)) + queue.offer(PriorityPage(page, PriorityPage.RETRY)) } } @@ -196,7 +201,7 @@ internal class HttpPageLoader( .subList(pageIndex + 1, min(pageIndex + 1 + amount, pages.size)) .mapNotNull { if (it.status == Page.State.Queue) { - PriorityPage(it, 0).apply { queue.offer(this) } + PriorityPage(it, PriorityPage.ADJACENT).apply { queue.offer(this) } } else { null } @@ -209,7 +214,7 @@ internal class HttpPageLoader( * * @param page the page whose source image has to be downloaded. */ - private suspend fun internalLoadPage(page: ReaderPage) { + private suspend fun internalLoadPage(page: ReaderPage, force: Boolean) { try { if (page.imageUrl.isNullOrEmpty()) { page.status = Page.State.LoadPage @@ -217,7 +222,7 @@ internal class HttpPageLoader( } val imageUrl = page.imageUrl!! - if (!chapterCache.isImageInCache(imageUrl)) { + if (force || !chapterCache.isImageInCache(imageUrl)) { page.status = Page.State.DownloadImage val imageResponse = source.getImage(page, dataSaver) chapterCache.putImageToCache(imageUrl, imageResponse) @@ -254,6 +259,10 @@ private class PriorityPage( ) : Comparable { companion object { private val idGenerator = AtomicInt(0) + + const val RETRY = 2 + const val DEFAULT = 1 + const val ADJACENT = 0 } private val identifier = idGenerator.incrementAndFetch()