Merge pull request #51 from icewind1991/last-page

Load the last page when switching to the previous chapter (Fix #48)
This commit is contained in:
inorichi 2016-01-23 19:13:21 +01:00
commit 6c844cfd9c
2 changed files with 12 additions and 4 deletions

View File

@ -164,6 +164,10 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
} }
public void onChapterReady(List<Page> pages, Manga manga, Chapter chapter, int currentPage) { public void onChapterReady(List<Page> pages, Manga manga, Chapter chapter, int currentPage) {
if (currentPage == -1) {
currentPage = pages.size() - 1;
}
if (viewer == null) { if (viewer == null) {
viewer = createViewer(manga); viewer = createViewer(manga);
getSupportFragmentManager().beginTransaction().replace(R.id.reader, viewer).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.reader, viewer).commit();

View File

@ -215,8 +215,12 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
.doOnNext(mangaSync -> this.mangaSyncList = mangaSync); .doOnNext(mangaSync -> this.mangaSyncList = mangaSync);
} }
// Loads the given chapter
private void loadChapter(Chapter chapter) { private void loadChapter(Chapter chapter) {
loadChapter(chapter, 0);
}
// Loads the given chapter
private void loadChapter(Chapter chapter, int requestedPage) {
// Before loading the chapter, stop preloading (if it's working) and save current progress // Before loading the chapter, stop preloading (if it's working) and save current progress
stopPreloadingNextChapter(); stopPreloadingNextChapter();
@ -227,7 +231,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
if (!chapter.read && chapter.last_page_read != 0) if (!chapter.read && chapter.last_page_read != 0)
currentPage = chapter.last_page_read; currentPage = chapter.last_page_read;
else else
currentPage = 0; currentPage = requestedPage;
// Reset next and previous chapter. They have to be fetched again // Reset next and previous chapter. They have to be fetched again
nextChapter = null; nextChapter = null;
@ -312,7 +316,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
public boolean loadNextChapter() { public boolean loadNextChapter() {
if (hasNextChapter()) { if (hasNextChapter()) {
onChapterLeft(); onChapterLeft();
loadChapter(nextChapter); loadChapter(nextChapter, 0);
return true; return true;
} }
return false; return false;
@ -321,7 +325,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
public boolean loadPreviousChapter() { public boolean loadPreviousChapter() {
if (hasPreviousChapter()) { if (hasPreviousChapter()) {
onChapterLeft(); onChapterLeft();
loadChapter(previousChapter); loadChapter(previousChapter, -1);
return true; return true;
} }
return false; return false;