mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-23 13:45:43 +03:00
Make active page nullable. Fixes #326
This commit is contained in:
parent
0714fdc7e6
commit
728ab18017
2 changed files with 15 additions and 6 deletions
|
@ -117,7 +117,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||
|
||||
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<ReaderPresenter>() {
|
|||
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue