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 1b02aa2a1..f13467d9e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java @@ -83,7 +83,7 @@ public class ReaderPresenter extends BasePresenter { source = event.getSource(); chapter = event.getChapter(); if (chapter.last_page_read != 0) - currentPage = chapter.last_page_read - 1; + currentPage = chapter.last_page_read; start(1); } @@ -110,10 +110,9 @@ public class ReaderPresenter extends BasePresenter { } private void saveChapter() { - chapter.last_page_read = currentPage + 1; + chapter.last_page_read = currentPage; if (currentPage == pageList.size() - 1) { chapter.read = true; - } db.insertChapterBlock(chapter); } 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 d2aee1021..1fe1f950c 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 @@ -38,6 +38,7 @@ public class ReaderActivity extends BaseRxActivity { @Inject PreferencesHelper prefs; private BaseViewer viewer; + private boolean isFullscreen; private static final int LEFT_TO_RIGHT = 1; private static final int RIGHT_TO_LEFT = 2; @@ -66,15 +67,25 @@ public class ReaderActivity extends BaseRxActivity { public void onPageListReady(List pages) { viewer.onPageListReady(pages); + viewer.updatePageNumber(); } public void onPageChanged(int currentPageIndex, int totalPages) { - if (currentPageIndex != 0) - getPresenter().setCurrentPage(currentPageIndex); String page = (currentPageIndex + 1) + "/" + totalPages; pageNumber.setText(page); } + @Override + protected void onPause() { + getPresenter().setCurrentPage(viewer.getCurrentPosition()); + super.onPause(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + public void setSelectedPage(int pageIndex) { viewer.setSelectedPage(pageIndex); } @@ -95,6 +106,22 @@ public class ReaderActivity extends BaseRxActivity { View.SYSTEM_UI_FLAG_LOW_PROFILE ); } + isFullscreen = true; + } + + public void disableFullscreen() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + ); + } else { + getWindow().getDecorView().setSystemUiVisibility( + View.VISIBLE + ); + } + isFullscreen = false; } public void enableHardwareAcceleration() { @@ -103,10 +130,21 @@ public class ReaderActivity extends BaseRxActivity { WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); } - public boolean onImageTouch(MotionEvent motionEvent) { + public boolean onImageSingleTap(MotionEvent motionEvent) { return viewer.onImageTouch(motionEvent); } + public void onCenterSingleTap() { + toggleFullscreen(); + } + + private void toggleFullscreen() { + if (isFullscreen) + disableFullscreen(); + else + enableFullScreen(); + } + private BaseViewer getViewer() { switch (prefs.getDefaultViewer()) { case LEFT_TO_RIGHT: default: diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java index 4276e8f67..f3535a599 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ReaderPageFragment.java @@ -59,7 +59,7 @@ public class ReaderPageFragment extends Fragment { imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE); imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE); imageView.setOnTouchListener((v, motionEvent) -> - ((ReaderActivity) getActivity()).onImageTouch(motionEvent)); + ((ReaderActivity) getActivity()).onImageSingleTap(motionEvent)); return view; } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java index ffa40386c..1b273d311 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/holder/ChapterListHolder.java @@ -38,7 +38,7 @@ public class ChapterListHolder extends ItemViewHolder { } if (chapter.last_page_read > 0 && !chapter.read) { - pages.setText(getContext().getString(R.string.chapter_progress, chapter.last_page_read)); + pages.setText(getContext().getString(R.string.chapter_progress, chapter.last_page_read+1)); } else { pages.setText(""); } 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 28842cc65..b3081a1e7 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 @@ -60,7 +60,6 @@ public class VerticalViewer extends BaseViewer { @Override public void onPageListReady(List pages) { adapter.setPages(pages); - updatePageNumber(); } @Override 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 972fed88c..f1424b9f1 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 @@ -29,6 +29,10 @@ public abstract class BaseViewer { return viewerPosition; } + public int getCurrentPosition() { + return getCurrentPageIndex(currentPosition); + } + public abstract int getTotalPages(); public abstract void setSelectedPage(int pageNumber); public abstract void onPageListReady(List pages); 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 9d1ba5d52..2ebdbaab0 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 @@ -54,6 +54,7 @@ public abstract class ViewPagerViewer extends BaseViewer { onLastPageOut(); } }); + viewPager.setOnChapterSingleTapListener(activity::onCenterSingleTap); } public ReaderViewPager getViewPager() { @@ -73,7 +74,6 @@ public abstract class ViewPagerViewer extends BaseViewer { @Override public void onPageListReady(List pages) { adapter.setPages(pages); - updatePageNumber(); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/widget/ReaderViewPager.java b/app/src/main/java/eu/kanade/mangafeed/widget/ReaderViewPager.java index ca5ab6c83..e5988c8b7 100644 --- a/app/src/main/java/eu/kanade/mangafeed/widget/ReaderViewPager.java +++ b/app/src/main/java/eu/kanade/mangafeed/widget/ReaderViewPager.java @@ -125,6 +125,10 @@ public class ReaderViewPager extends ViewPager { mOnChapterBoundariesOutListener.onLastPageOutEvent(); } } + } else { + if (mOnChapterSingleTapListener != null) { + mOnChapterSingleTapListener.onSingleTap(); + } } return true;