From 141f9b7730dc63c123cbe2fca455f70edba9eb39 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 31 Dec 2020 11:21:39 -0500 Subject: [PATCH] Handle last read page being above total page count (fixes #4010) --- .../eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt | 3 ++- .../kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt | 2 +- 2 files changed, 3 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 30411aa5be..d485c7a71f 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 @@ -16,6 +16,7 @@ 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 timber.log.Timber +import kotlin.math.min /** * Implementation of a [BaseViewer] to display pages with a [ViewPager]. @@ -239,7 +240,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { if (pager.isGone) { Timber.d("Pager first layout") val pages = chapters.currChapter.pages ?: return - moveToPage(pages[chapters.currChapter.requestedPage]) + moveToPage(pages[min(chapters.currChapter.requestedPage, pages.lastIndex)]) pager.isVisible = true } } 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 dfbfb96f12..4364d5a88b 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 @@ -229,7 +229,7 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr if (recycler.isGone) { Timber.d("Recycler first layout") val pages = chapters.currChapter.pages ?: return - moveToPage(pages[chapters.currChapter.requestedPage]) + moveToPage(pages[min(chapters.currChapter.requestedPage, pages.lastIndex)]) recycler.isVisible = true } }