From 7c3cd10696fbfcba90751220664daf822996d1c3 Mon Sep 17 00:00:00 2001 From: len Date: Sun, 11 Sep 2016 16:00:06 +0200 Subject: [PATCH] Notify first page change --- .../tachiyomi/ui/reader/ReaderActivity.kt | 17 ++++++++++------- .../ui/reader/viewer/base/BaseReader.kt | 15 +++------------ .../ui/reader/viewer/pager/PagerReader.kt | 7 +++++-- .../ui/reader/viewer/webtoon/WebtoonReader.kt | 2 +- 4 files changed, 19 insertions(+), 22 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 be9f9e735c..c148383a64 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 @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.reader.viewer.base.BaseReader import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.LeftToRightReader @@ -308,15 +309,18 @@ class ReaderActivity : BaseRxActivity() { return fragment } - fun onPageChanged(currentPageIndex: Int, totalPages: Int) { - val page = currentPageIndex + 1 - page_number.text = "$page/$totalPages" + fun onPageChanged(page: Page) { + presenter.onPageChanged(page) + + val pageNumber = page.pageNumber + 1 + val pageCount = page.chapter.pages!!.size + page_number.text = "$pageNumber/$pageCount" if (page_seekbar.rotation != 180f) { - left_page_text.text = "$page" + left_page_text.text = "$pageNumber" } else { - right_page_text.text = "$page" + right_page_text.text = "$pageNumber" } - page_seekbar.progress = currentPageIndex + page_seekbar.progress = page.pageNumber } fun gotoPageInCurrentChapter(pageIndex: Int) { @@ -326,7 +330,6 @@ class ReaderActivity : BaseRxActivity() { 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 360696b62d..1e6667fee8 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 @@ -66,16 +66,6 @@ abstract class BaseReader : BaseFragment() { */ private var hasRequestedNextChapter: Boolean = false - /** - * Updates the reader activity with the active page. - */ - fun updatePageNumber() { - val activePage = getActivePage() - if (activePage != null) { - readerActivity.onPageChanged(activePage.pageNumber, activePage.chapter.pages!!.size) - } - } - /** * Returns the active page. */ @@ -91,11 +81,13 @@ abstract class BaseReader : BaseFragment() { fun onPageChanged(position: Int) { val oldPage = pages[currentPage] val newPage = pages[position] - readerActivity.presenter.onPageChanged(newPage) val oldChapter = oldPage.chapter val newChapter = newPage.chapter + // Update page indicator and seekbar + readerActivity.onPageChanged(newPage) + // Active chapter has changed. if (oldChapter.id != newChapter.id) { readerActivity.onEnterChapter(newPage.chapter, newPage.pageNumber) @@ -108,7 +100,6 @@ abstract class BaseReader : BaseFragment() { } currentPage = position - updatePageNumber() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt index fafd4f3a76..8f75411059 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt @@ -219,8 +219,11 @@ abstract class PagerReader : BaseReader() { protected fun setPagesOnAdapter() { if (pages.isNotEmpty()) { adapter.pages = pages - setActivePage(currentPage) - updatePageNumber() + if (currentPage == pager.currentItem) { + onPageChanged(currentPage) + } else { + setActivePage(currentPage) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt index 7565f8d5ee..9795d81308 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt @@ -177,7 +177,7 @@ class WebtoonReader : BaseReader() { if (pages.isNotEmpty()) { adapter.pages = pages recycler.adapter = adapter - updatePageNumber() + onPageChanged(currentPage) } }