From 728ab180178d44e43fa570570de260ddba2c09b7 Mon Sep 17 00:00:00 2001 From: len Date: Fri, 3 Jun 2016 12:25:39 +0200 Subject: [PATCH] Make active page nullable. Fixes #326 --- .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 13 ++++++++++--- .../tachiyomi/ui/reader/viewer/base/BaseReader.kt | 8 +++++--- 2 files changed, 15 insertions(+), 6 deletions(-) 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 fbcd1e1c5f..853ec7141a 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 fc147cb1c4..7897b563fe 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) } /**