diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index fbcd1e1c5..853ec7141 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -117,7 +117,10 @@ class ReaderActivity : BaseRxActivity() { override fun onPause() { viewer?.let { - presenter.currentPage = it.getActivePage() + val activePage = it.getActivePage() + if (activePage != null) { + presenter.currentPage = activePage + } } super.onPause() } @@ -318,8 +321,12 @@ class ReaderActivity : BaseRxActivity() { fun gotoPageInCurrentChapter(pageIndex: Int) { viewer?.let { - val requestedPage = it.getActivePage().chapter.pages[pageIndex] - it.setActivePage(requestedPage) + val activePage = it.getActivePage() + if (activePage != null) { + val requestedPage = activePage.chapter.pages[pageIndex] + it.setActivePage(requestedPage) + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt index fc147cb1c..7897b563f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.kt @@ -71,14 +71,16 @@ abstract class BaseReader : BaseFragment() { */ fun updatePageNumber() { val activePage = getActivePage() - readerActivity.onPageChanged(activePage.pageNumber, activePage.chapter.pages.size) + if (activePage != null) { + readerActivity.onPageChanged(activePage.pageNumber, activePage.chapter.pages.size) + } } /** * Returns the active page. */ - fun getActivePage(): Page { - return pages.getOrElse(currentPage) { pages[0] } + fun getActivePage(): Page? { + return pages.getOrNull(currentPage) } /**