Incorrect mark as read with seamless mode. #142

This commit is contained in:
inorichi 2016-02-14 15:35:58 +01:00
parent 4c073e713d
commit 5c329d2314
2 changed files with 23 additions and 16 deletions

View File

@ -253,7 +253,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
}
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<ReaderActivity> {
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<Page> 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();

View File

@ -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;