From a05cc934d0abd95dad478d65e8de659b870c1dc8 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 28 Nov 2015 23:32:13 +0100 Subject: [PATCH] Improve reader gestures. Upgrade gradle and retrolambda. --- .../mangafeed/ui/reader/ReaderActivity.java | 25 +++++++++---------- .../mangafeed/ui/reader/ReaderPresenter.java | 13 +++++----- .../common/ViewPagerReaderFragment.java | 21 ++++++++-------- .../horizontal/HorizontalViewPager.java | 3 --- .../viewer/vertical/VerticalViewPager.java | 3 --- app/src/main/res/layout/fragment_page.xml | 9 ------- build.gradle | 4 +-- 7 files changed, 31 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index 9a9c84331d..123daa1de0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -7,7 +7,6 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.widget.Toolbar; -import android.view.MotionEvent; import android.view.Surface; import android.view.View; import android.view.ViewGroup; @@ -82,14 +81,6 @@ public class ReaderActivity extends BaseRxActivity { initializeSettings(); } - @Override - protected void onDestroy() { - readerMenu.destroy(); - if (viewer != null) - viewer.destroy(); - super.onDestroy(); - } - @Override protected void onResume() { super.onResume(); @@ -103,6 +94,14 @@ public class ReaderActivity extends BaseRxActivity { super.onPause(); } + @Override + protected void onDestroy() { + readerMenu.destroy(); + if (viewer != null) + viewer.destroy(); + super.onDestroy(); + } + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { Icepick.saveInstanceState(readerMenu, outState); @@ -146,10 +145,6 @@ public class ReaderActivity extends BaseRxActivity { viewer.setSelectedPage(pageIndex); } - public boolean onImageSingleTap(MotionEvent motionEvent) { - return viewer.onImageTouch(motionEvent); - } - public void onCenterSingleTap() { readerMenu.toggle(); } @@ -262,4 +257,8 @@ public class ReaderActivity extends BaseRxActivity { return preferences; } + public BaseReader getViewer() { + return viewer; + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index 5cbe422c53..78a2bd6847 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -181,15 +181,14 @@ public class ReaderPresenter extends BasePresenter { nextChapterPageList = pages; // Preload at most 5 pages int pagesToPreload = Math.min(pages.size(), 5); - return Observable.from(pages) - .take(pagesToPreload) - .concatMap(page -> page.getImageUrl() == null ? - source.getImageUrlFromPage(page) : - Observable.just(page)) - .doOnCompleted(this::stopPreloadingNextChapter); + return Observable.from(pages).take(pagesToPreload); }) + .concatMap(page -> page.getImageUrl() == null ? + source.getImageUrlFromPage(page) : + Observable.just(page)) .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()); + .observeOn(AndroidSchedulers.mainThread()) + .doOnCompleted(this::stopPreloadingNextChapter); } // Loads the given chapter diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java index 814f2d7c7e..6108f7326c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java @@ -3,6 +3,7 @@ package eu.kanade.mangafeed.ui.reader.viewer.common; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -18,7 +19,6 @@ import java.util.concurrent.atomic.AtomicInteger; import butterknife.Bind; import butterknife.ButterKnife; -import butterknife.OnClick; import de.greenrobot.event.EventBus; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.source.model.Page; @@ -37,7 +37,6 @@ public class ViewPagerReaderFragment extends BaseFragment { @Bind(R.id.progress_container) LinearLayout progressContainer; @Bind(R.id.progress) ProgressBar progressBar; @Bind(R.id.progress_text) TextView progressText; - @Bind(R.id.image_error) TextView errorText; @Bind(R.id.retry_button) Button retryButton; private Page page; @@ -59,7 +58,16 @@ public class ViewPagerReaderFragment extends BaseFragment { imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE); imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE); imageView.setOnTouchListener((v, motionEvent) -> - ((ReaderActivity) getActivity()).onImageSingleTap(motionEvent)); + ((ReaderActivity) getActivity()).getViewer().onImageTouch(motionEvent)); + + retryButton.setOnTouchListener((v, event) -> { + if (event.getAction() == MotionEvent.ACTION_UP) { + if (page != null) + EventBus.getDefault().postSticky(new RetryPageEvent(page)); + return true; + } + return true; + }); return view; } @@ -86,11 +94,6 @@ public class ViewPagerReaderFragment extends BaseFragment { this.page = page; } - @OnClick(R.id.retry_button) - void retry() { - EventBus.getDefault().postSticky(new RetryPageEvent(page)); - } - private void showImage() { if (page == null || page.getImagePath() == null) return; @@ -112,12 +115,10 @@ public class ViewPagerReaderFragment extends BaseFragment { private void showError() { progressContainer.setVisibility(View.GONE); - errorText.setVisibility(View.VISIBLE); retryButton.setVisibility(View.VISIBLE); } private void hideError() { - errorText.setVisibility(View.GONE); retryButton.setVisibility(View.GONE); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java index 4e3ef31d82..6fd65d1068 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java @@ -26,8 +26,6 @@ public class HorizontalViewPager extends ViewPager { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { try { - gestureDetector.onTouchEvent(ev); - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) { startDragX = ev.getX(); @@ -85,7 +83,6 @@ public class HorizontalViewPager extends ViewPager { public interface OnChapterBoundariesOutListener { void onFirstPageOutEvent(); - void onLastPageOutEvent(); } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java index 3d5a7afabb..eff4ef830a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java @@ -25,8 +25,6 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V @Override public boolean onInterceptTouchEvent(MotionEvent ev) { try { - gestureDetector.onTouchEvent(ev); - if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) { startDragY = ev.getY(); @@ -84,7 +82,6 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V public interface OnChapterBoundariesOutListener { void onFirstPageOutEvent(); - void onLastPageOutEvent(); } diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/fragment_page.xml index 0232702eac..dc95020a42 100644 --- a/app/src/main/res/layout/fragment_page.xml +++ b/app/src/main/res/layout/fragment_page.xml @@ -30,15 +30,6 @@ - -