From 5c329d2314704278a60dda69e689375f0210e007 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 14 Feb 2016 15:35:58 +0100 Subject: [PATCH] Incorrect mark as read with seamless mode. #142 --- .../tachiyomi/ui/reader/ReaderPresenter.java | 28 +++++++++++-------- .../ui/reader/viewer/base/BaseReader.java | 11 +++++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java index 21ca56529..aede73ffd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.java @@ -253,7 +253,7 @@ public class ReaderPresenter extends BasePresenter { } public void setActiveChapter(Chapter chapter) { - onChapterLeft(true); // force markAsRead since at this point the current page is already for the next chapter + onChapterLeft(); this.activeChapter = chapter; nextChapter = null; previousChapter = null; @@ -292,25 +292,29 @@ public class ReaderPresenter extends BasePresenter { retryPageSubject.onNext(page); } - public void onChapterLeft() { - onChapterLeft(false); - } - // Called before loading another chapter or leaving the reader. It allows to do operations // over the chapter read like saving progress - public void onChapterLeft(boolean forceMarkAsRead) { - if (activeChapter.getPages() == null) + public void onChapterLeft() { + List pages = activeChapter.getPages(); + if (pages == null) return; - Page activePage = getCurrentPage(); + // Get the last page read + int activePageNumber = activeChapter.last_page_read; + + // Just in case, avoid out of index exceptions + if (activePageNumber >= pages.size()) { + activePageNumber = pages.size() - 1; + } + Page activePage = pages.get(activePageNumber); // Cache current page list progress for online chapters to allow a faster reopen - if (!activeChapter.isDownloaded()) - source.savePageList(activeChapter.url, activePage.getChapter().getPages()); + if (!activeChapter.isDownloaded()) { + source.savePageList(activeChapter.url, pages); + } // Save current progress of the chapter. Mark as read if the chapter is finished - activeChapter.last_page_read = activePage.getPageNumber(); - if (forceMarkAsRead || activePage.isLastPage()) { + if (activePage.isLastPage()) { activeChapter.read = true; } db.insertChapter(activeChapter).asRxObservable().subscribe(); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.java b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.java index 4167c0143..c5ceb6e97 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/base/BaseReader.java @@ -36,16 +36,19 @@ public abstract class BaseReader extends BaseFragment { } public void onPageChanged(int position) { + Page oldPage = pages.get(currentPage); + Page newPage = pages.get(position); + newPage.getChapter().last_page_read = newPage.getPageNumber(); + if (getReaderActivity().getPresenter().isSeamlessMode()) { - Chapter oldChapter = pages.get(currentPage).getChapter(); - Chapter newChapter = pages.get(position).getChapter(); + Chapter oldChapter = oldPage.getChapter(); + Chapter newChapter = newPage.getChapter(); if (!hasRequestedNextChapter && position > pages.size() - 5) { hasRequestedNextChapter = true; getReaderActivity().getPresenter().appendNextChapter(); } if (!oldChapter.id.equals(newChapter.id)) { - Page page = pages.get(position); - onChapterChanged(page.getChapter(), page); + onChapterChanged(newPage.getChapter(), newPage); } } currentPage = position;