mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-07 19:27:25 +01:00
Prevented overzealous preloading (#2882)
This commit is contained in:
parent
48f7b06549
commit
5d03eef051
@ -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
|
// Preload next chapter once we're within the last 3 pages of the current chapter
|
||||||
val inPreloadRange = pages.size - page.number < 3
|
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}")
|
Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}")
|
||||||
adapter.nextTransition?.to?.let {
|
adapter.nextTransition?.to?.let {
|
||||||
activity.requestPreloadChapter(it)
|
activity.requestPreloadChapter(it)
|
||||||
|
@ -24,6 +24,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
|
|||||||
var nextTransition: ChapterTransition.Next? = null
|
var nextTransition: ChapterTransition.Next? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var currentChapter: ReaderChapter? = null
|
||||||
/**
|
/**
|
||||||
* Updates this adapter with the given [chapters]. It handles setting a few pages of the
|
* 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
|
* 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)
|
newItems.addAll(currPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentChapter = chapters.currChapter
|
||||||
|
|
||||||
// Add next chapter transition and pages.
|
// Add next chapter transition and pages.
|
||||||
nextTransition = ChapterTransition.Next(chapters.currChapter, chapters.nextChapter)
|
nextTransition = ChapterTransition.Next(chapters.currChapter, chapters.nextChapter)
|
||||||
.also {
|
.also {
|
||||||
|
@ -21,6 +21,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
|||||||
var items: List<Any> = emptyList()
|
var items: List<Any> = emptyList()
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var currentChapter: ReaderChapter? = null
|
||||||
/**
|
/**
|
||||||
* Updates this adapter with the given [chapters]. It handles setting a few pages of the
|
* Updates this adapter with the given [chapters]. It handles setting a few pages of the
|
||||||
* next/previous chapter to allow seamless transitions.
|
* next/previous chapter to allow seamless transitions.
|
||||||
@ -49,6 +50,8 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
|
|||||||
newItems.addAll(currPages)
|
newItems.addAll(currPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentChapter = chapters.currChapter
|
||||||
|
|
||||||
// Add next chapter transition and pages.
|
// Add next chapter transition and pages.
|
||||||
if (forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded) {
|
if (forceTransition || chapters.nextChapter?.state !is ReaderChapter.State.Loaded) {
|
||||||
newItems.add(ChapterTransition.Next(chapters.currChapter, chapters.nextChapter))
|
newItems.add(ChapterTransition.Next(chapters.currChapter, chapters.nextChapter))
|
||||||
|
@ -170,7 +170,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
|
|||||||
|
|
||||||
// Preload next chapter once we're within the last 3 pages of the current chapter
|
// Preload next chapter once we're within the last 3 pages of the current chapter
|
||||||
val inPreloadRange = pages.size - page.number < 3
|
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}")
|
Timber.d("Request preload next chapter because we're at page ${page.number} of ${pages.size}")
|
||||||
val nextItem = adapter.items.getOrNull(adapter.items.size - 1)
|
val nextItem = adapter.items.getOrNull(adapter.items.size - 1)
|
||||||
val transitionChapter = (nextItem as? ChapterTransition.Next)?.to ?: (nextItem as?ReaderPage)?.chapter
|
val transitionChapter = (nextItem as? ChapterTransition.Next)?.to ?: (nextItem as?ReaderPage)?.chapter
|
||||||
|
Loading…
Reference in New Issue
Block a user