@ -18,10 +18,10 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation.NavigationRegion
import eu.kanade.tachiyomi.util.system.logcat
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.cancel
import rx.subscriptions.CompositeSubscription
import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import kotlin.math.max
@ -195,17 +195,17 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
* /
private fun onPageSelected ( page : ReaderPage , allowPreload : Boolean ) {
val pages = page . chapter . pages ?: return
Timber . d ( " onPageSelected: ${page.number} / ${pages.size} " )
logcat { " onPageSelected: ${page.number} / ${pages.size} " }
activity . onPageSelected ( page )
// Preload next chapter once we're within the last 5 pages of the current chapter
val inPreloadRange = pages . size - page . number < 5
if ( inPreloadRange && allowPreload && page . chapter == adapter . currentChapter ) {
Timber . d ( " Request preload next chapter because we're at page ${page.number} of ${pages.size} " )
logcat { " Request preload next chapter because we're at page ${page.number} of ${pages.size} " }
val nextItem = adapter . items . getOrNull ( adapter . items . size - 1 )
val transitionChapter = ( nextItem as ? ChapterTransition . Next ) ?. to ?: ( nextItem as ? ReaderPage ) ?. chapter
if ( transitionChapter != null ) {
Timber . d ( " Requesting to preload chapter ${transitionChapter.chapter.chapter_number} " )
logcat { " Requesting to preload chapter ${transitionChapter.chapter.chapter_number} " }
activity . requestPreloadChapter ( transitionChapter )
}
}
@ -216,10 +216,10 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
* preload of the destination chapter of the transition .
* /
private fun onTransitionSelected ( transition : ChapterTransition ) {
Timber . d ( " onTransitionSelected: $transition " )
logcat { " onTransitionSelected: $transition " }
val toChapter = transition . to
if ( toChapter != null ) {
Timber . d ( " Request preload destination chapter because we're on the transition " )
logcat { " Request preload destination chapter because we're on the transition " }
activity . requestPreloadChapter ( toChapter )
} else if ( transition is ChapterTransition . Next ) {
// No more chapters, show menu because the user is probably going to close the reader
@ -231,12 +231,12 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
* Tells this viewer to set the given [ chapters ] as active .
* /
override fun setChapters ( chapters : ViewerChapters ) {
Timber . d ( " setChapters " )
logcat { " setChapters " }
val forceTransition = config . alwaysShowChapterTransition || currentPage is ChapterTransition
adapter . setChapters ( chapters , forceTransition )
if ( recycler . isGone ) {
Timber . d ( " Recycler first layout " )
logcat { " Recycler first layout " }
val pages = chapters . currChapter . pages ?: return
moveToPage ( pages [ min ( chapters . currChapter . requestedPage , pages . lastIndex ) ] )
recycler . isVisible = true
@ -247,7 +247,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
* Tells this viewer to move to the given [ page ] .
* /
override fun moveToPage ( page : ReaderPage ) {
Timber . d ( " moveToPage " )
logcat { " moveToPage " }
val position = adapter . items . indexOf ( page )
if ( position != - 1 ) {
recycler . scrollToPosition ( position )
@ -255,7 +255,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
onScrolled ( pos = position )
}
} else {
Timber . d ( " Page $page not found in adapter " )
logcat { " Page $page not found in adapter " }
}
}