Start preloading next chapter if within last 3 pages instead of last page

This commit is contained in:
arkon 2020-03-09 15:09:17 -04:00
parent 9936b402a6
commit de512216c4
4 changed files with 11 additions and 7 deletions

View File

@ -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)
}

View File

@ -42,7 +42,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))
}

View File

@ -38,7 +38,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
}
}
// 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))
}

View File

@ -145,9 +145,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)
}