From 8379caa1493655c2e5b469784eeac850ef6bef2b Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 9 Mar 2020 15:09:17 -0400 Subject: [PATCH] Start preloading next chapter if within last 3 pages instead of last page --- .../tachiyomi/ui/reader/viewer/pager/PagerViewer.kt | 6 ++++-- .../ui/reader/viewer/pager/PagerViewerAdapter.kt | 2 +- .../tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt | 2 +- .../tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt | 8 +++++--- 4 files changed, 11 insertions(+), 7 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 5f8b1f764b..537efb4197 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 @@ -144,8 +144,10 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { Timber.d("onReaderPageSelected: ${page.number}/${pages.size}") activity.onPageSelected(page) - if (page === pages.last()) { - Timber.d("Request preload next chapter because we're at the last page") + // Preload next chapter once we're within the last 3 pages of the current chapter + val inPreloadRange = pages.size - page.number < 3 + if (inPreloadRange) { + 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 bb8677bfcc..d579d177d0 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 @@ -41,7 +41,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() { } } - // Skip transition page if the chapter is loaded & current page is not a transition page + // Skip transition page if the chapter is loaded & current page is not a transition page if (forceTransition || chapters.prevChapter?.state !is ReaderChapter.State.Loaded) { newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) } 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 dbd7854499..b80f6d5782 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 @@ -38,7 +38,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : androidx.recyclerview.widget.R } } - // Skip transition page if the chapter is loaded & current page is not a transition page + // Skip transition page if the chapter is loaded & current page is not a transition page if (forceTransition || chapters.prevChapter?.state !is ReaderChapter.State.Loaded) { newItems.add(ChapterTransition.Prev(chapters.currChapter, chapters.prevChapter)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index b3672f7ffd..f83b2d4a91 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -142,9 +142,11 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer { Timber.d("onPageSelected: ${page.number}/${pages.size}") activity.onPageSelected(page) - if (page === pages.last()) { - Timber.d("Request preload next chapter because we're at the last page") - val transition = adapter.items.getOrNull(position + 1) as? ChapterTransition.Next + // Preload next chapter once we're within the last 3 pages of the current chapter + val inPreloadRange = pages.size - page.number < 3 + if (inPreloadRange) { + Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}") + val transition = adapter.items.getOrNull(pages.size + 1) as? ChapterTransition.Next if (transition?.to != null) { activity.requestPreloadChapter(transition.to) }