From 5d03eef051e6412cff8536441cd343878c53c340 Mon Sep 17 00:00:00 2001 From: morcefaster <51055657+morcefaster@users.noreply.github.com> Date: Fri, 17 Apr 2020 00:22:44 +0300 Subject: [PATCH] Prevented overzealous preloading (#2882) --- .../eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt | 2 +- .../tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt | 3 +++ .../tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt | 3 +++ .../kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 465c74edc..bcca48887 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -168,7 +168,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { // Preload next chapter once we're within the last 3 pages of the current chapter val inPreloadRange = pages.size - page.number < 3 - if (inPreloadRange && allowPreload) { + if (inPreloadRange && allowPreload && page.chapter == adapter.currentChapter) { Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}") adapter.nextTransition?.to?.let { activity.requestPreloadChapter(it) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt index 57a644dcf..ac8752628 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewerAdapter.kt @@ -24,6 +24,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { var nextTransition: ChapterTransition.Next? = null private set + var currentChapter: ReaderChapter? = null /** * Updates this adapter with the given [chapters]. It handles setting a few pages of the * next/previous chapter to allow seamless transitions and inverting the pages if the viewer @@ -53,6 +54,8 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { newItems.addAll(currPages) } + currentChapter = chapters.currChapter + // Add next chapter transition and pages. nextTransition = ChapterTransition.Next(chapters.currChapter, chapters.nextChapter) .also { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index ee0afca88..409d9c71f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -21,6 +21,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter = emptyList() private set + var currentChapter: ReaderChapter? = null /** * Updates this adapter with the given [chapters]. It handles setting a few pages of the * next/previous chapter to allow seamless transitions. @@ -49,6 +50,8 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter