mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 09:57:47 +01:00
Fix bug in reader's current position
This commit is contained in:
parent
720b0a29ce
commit
571c24d3d9
8 changed files with 54 additions and 10 deletions
|
@ -83,7 +83,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
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<ReaderActivity> {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
|||
@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<ReaderPresenter> {
|
|||
|
||||
public void onPageListReady(List<Page> 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<ReaderPresenter> {
|
|||
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<ReaderPresenter> {
|
|||
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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class ChapterListHolder extends ItemViewHolder<Chapter> {
|
|||
}
|
||||
|
||||
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("");
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ public class VerticalViewer extends BaseViewer {
|
|||
@Override
|
||||
public void onPageListReady(List<Page> pages) {
|
||||
adapter.setPages(pages);
|
||||
updatePageNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<Page> pages);
|
||||
|
|
|
@ -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<Page> pages) {
|
||||
adapter.setPages(pages);
|
||||
updatePageNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -125,6 +125,10 @@ public class ReaderViewPager extends ViewPager {
|
|||
mOnChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onSingleTap();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue