diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java index 11b757915..2e688eb2d 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java @@ -27,7 +27,7 @@ public class ReaderPresenter extends BasePresenter { private Source source; private Chapter chapter; private List pageList; - @State int savedSelectedPage = -1; + @State int savedSelectedPage = 0; private static final int GET_PAGE_LIST = 1; private static final int GET_PAGE_IMAGES = 2; @@ -40,7 +40,12 @@ public class ReaderPresenter extends BasePresenter { () -> getPageListObservable() .doOnNext(pages -> pageList = pages) .doOnCompleted(() -> start(GET_PAGE_IMAGES)), - (view, pages) -> view.onPageListReady(pages), + (view, pages) -> { + view.onPageListReady(pages); + if (savedSelectedPage != 0) { + view.setSelectedPage(savedSelectedPage); + } + }, (view, error) -> Timber.e("An error occurred while downloading page list") ); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java index 31cc6c18b..5c8ada458 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java @@ -71,13 +71,14 @@ public class ReaderActivity extends BaseRxActivity { viewer.onPageListReady(pages); } - public void onPageChanged(int currentPage, int totalPages) { - String page = currentPage + "/" + totalPages; + public void onPageChanged(int currentPageIndex, int totalPages) { + currentPage = currentPageIndex; + String page = (currentPageIndex + 1) + "/" + totalPages; pageNumber.setText(page); } - public void setCurrentPage(int page) { - currentPage = page; + public void setSelectedPage(int pageIndex) { + viewer.setSelectedPage(pageIndex); } public void hideStatusBar() { @@ -98,7 +99,7 @@ public class ReaderActivity extends BaseRxActivity { private BaseViewer getViewer() { switch (prefs.getDefaultViewer()) { - case LEFT_TO_RIGHT: + case LEFT_TO_RIGHT: default: return new LeftToRightViewer(this, container); case RIGHT_TO_LEFT: return new RightToLeftViewer(this, container); @@ -107,7 +108,6 @@ public class ReaderActivity extends BaseRxActivity { case WEBTOON: return new WebtoonViewer(this, container); } - return null; } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/RightToLeftViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/RightToLeftViewer.java index c690d8e44..838f33ed9 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/RightToLeftViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/RightToLeftViewer.java @@ -25,13 +25,8 @@ public class RightToLeftViewer extends ViewPagerViewer { } @Override - public int getCurrentPageFromPos(int position) { - return getTotalPages() - position; - } - - @Override - public int getPosFromPage(Page page) { - return getTotalPages() - (page.getPageNumber() + 1); + public int getCurrentPageIndex(int viewerPosition) { + return getTotalPages() - viewerPosition - 1; } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java index d92aa2712..02e65ddd9 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java @@ -52,6 +52,12 @@ public class VerticalViewer extends BaseViewer { return adapter.getCount(); } + @Override + public void setSelectedPage(int pageNumber) { + // TODO + return; + } + @Override public void onPageListReady(List pages) { adapter.setPages(pages); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java index 9e4a4d773..36798a14a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java @@ -33,6 +33,12 @@ public class WebtoonViewer extends BaseViewer { return adapter.getItemCount(); } + @Override + public void setSelectedPage(int pageNumber) { + // TODO + return; + } + @Override public void onPageListReady(List pages) { adapter.setPages(pages); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java index 0869e57e2..972fed88c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java @@ -20,18 +20,17 @@ public abstract class BaseViewer { } public void updatePageNumber() { - activity.onPageChanged(getCurrentPageFromPos(currentPosition), getTotalPages()); + activity.onPageChanged(getCurrentPageIndex(currentPosition), getTotalPages()); } - public int getCurrentPageFromPos(int position) { - return position + 1; - } - - public int getPosFromPage(Page page) { - return page.getPageNumber(); + // Returns the page index given a position in the viewer. Useful por a right to left viewer, + // where the current page is the inverse of the position + public int getCurrentPageIndex(int viewerPosition) { + return viewerPosition; } public abstract int getTotalPages(); + public abstract void setSelectedPage(int pageNumber); public abstract void onPageListReady(List pages); public abstract boolean onImageTouch(MotionEvent motionEvent); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/ViewPagerViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/ViewPagerViewer.java index da3a6b9ef..9d1ba5d52 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/ViewPagerViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/ViewPagerViewer.java @@ -65,6 +65,11 @@ public abstract class ViewPagerViewer extends BaseViewer { return adapter.getCount(); } + @Override + public void setSelectedPage(int pageNumber) { + viewPager.setCurrentItem(getCurrentPageIndex(pageNumber)); + } + @Override public void onPageListReady(List pages) { adapter.setPages(pages);