diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerInterface.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/Pager.java similarity index 96% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerInterface.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/Pager.java index 604081ba9..3fce355ac 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerInterface.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/Pager.java @@ -6,7 +6,7 @@ import android.view.ViewGroup; import rx.functions.Action1; -public interface ViewPagerInterface { +public interface Pager { void setId(int id); void setLayoutParams(ViewGroup.LayoutParams layoutParams); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerGestureListener.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerGestureListener.java new file mode 100644 index 000000000..5554bce56 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerGestureListener.java @@ -0,0 +1,71 @@ +package eu.kanade.mangafeed.ui.reader.viewer.common; + +import android.view.GestureDetector; +import android.view.MotionEvent; + +public class PagerGestureListener extends GestureDetector.SimpleOnGestureListener { + + private Pager pager; + + private static final float LEFT_REGION = 0.33f; + private static final float RIGHT_REGION = 0.66f; + + public PagerGestureListener(Pager pager) { + this.pager = pager; + } + + @Override + public boolean onSingleTapConfirmed(MotionEvent e) { + final int position = pager.getCurrentItem(); + final float positionX = e.getX(); + + if (positionX < pager.getWidth() * LEFT_REGION) { + if (position != 0) { + onLeftSideTap(); + } else { + onFirstPageOut(); + } + } else if (positionX > pager.getWidth() * RIGHT_REGION) { + if (position != pager.getAdapter().getCount() - 1) { + onRightSideTap(); + } else { + onLastPageOut(); + } + } else { + onCenterTap(); + } + + return true; + } + + private void onLeftSideTap() { + if (pager.getChapterSingleTapListener() != null) { + pager.getChapterSingleTapListener().onLeftSideTap(); + } + } + + private void onRightSideTap() { + if (pager.getChapterSingleTapListener() != null) { + pager.getChapterSingleTapListener().onRightSideTap(); + } + } + + private void onCenterTap() { + if (pager.getChapterSingleTapListener() != null) { + pager.getChapterSingleTapListener().onCenterTap(); + } + } + + private void onFirstPageOut() { + if (pager.getChapterBoundariesListener() != null) { + pager.getChapterBoundariesListener().onFirstPageOutEvent(); + } + } + + private void onLastPageOut() { + if (pager.getChapterBoundariesListener() != null) { + pager.getChapterBoundariesListener().onLastPageOutEvent(); + } + } + +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReader.java similarity index 90% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReader.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReader.java index 860ec92bb..178fd4af3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReader.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReader.java @@ -12,15 +12,15 @@ import rx.Subscription; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; -public abstract class ViewPagerReader extends BaseReader { +public abstract class PagerReader extends BaseReader { - protected ViewPagerReaderAdapter adapter; - protected ViewPagerInterface pager; + protected PagerReaderAdapter adapter; + protected Pager pager; protected boolean transitions; protected Subscription transitionsSubscription; - protected void initializePager(ViewPagerInterface pager) { + protected void initializePager(Pager pager) { this.pager = pager; pager.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); pager.setOffscreenPageLimit(2); @@ -53,7 +53,7 @@ public abstract class ViewPagerReader extends BaseReader { } }); - adapter = new ViewPagerReaderAdapter(getChildFragmentManager()); + adapter = new PagerReaderAdapter(getChildFragmentManager()); pager.setAdapter(adapter); setPages(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderAdapter.java similarity index 78% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderAdapter.java index 7c4e432dc..3a609f85e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderAdapter.java @@ -8,11 +8,11 @@ import java.util.List; import eu.kanade.mangafeed.data.source.model.Page; -public class ViewPagerReaderAdapter extends FragmentStatePagerAdapter { +public class PagerReaderAdapter extends FragmentStatePagerAdapter { private List pages; - public ViewPagerReaderAdapter(FragmentManager fragmentManager) { + public PagerReaderAdapter(FragmentManager fragmentManager) { super(fragmentManager); } @@ -23,7 +23,7 @@ public class ViewPagerReaderAdapter extends FragmentStatePagerAdapter { @Override public Fragment getItem(int position) { - return ViewPagerReaderFragment.newInstance(pages.get(position)); + return PagerReaderFragment.newInstance(pages.get(position)); } public List getPages() { 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/PagerReaderFragment.java similarity index 96% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderFragment.java index a3afb1287..37b36ab44 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/PagerReaderFragment.java @@ -31,7 +31,7 @@ import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; -public class ViewPagerReaderFragment extends BaseFragment { +public class PagerReaderFragment extends BaseFragment { @Bind(R.id.page_image_view) SubsamplingScaleImageView imageView; @Bind(R.id.progress_container) LinearLayout progressContainer; @@ -43,8 +43,8 @@ public class ViewPagerReaderFragment extends BaseFragment { private Subscription progressSubscription; private Subscription statusSubscription; - public static ViewPagerReaderFragment newInstance(Page page) { - ViewPagerReaderFragment fragment = new ViewPagerReaderFragment(); + public static PagerReaderFragment newInstance(Page page) { + PagerReaderFragment fragment = new PagerReaderFragment(); fragment.setPage(page); return fragment; } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerGestureListener.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerGestureListener.java deleted file mode 100644 index c2fdf68b8..000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerGestureListener.java +++ /dev/null @@ -1,71 +0,0 @@ -package eu.kanade.mangafeed.ui.reader.viewer.common; - -import android.view.GestureDetector; -import android.view.MotionEvent; - -public class ViewPagerGestureListener extends GestureDetector.SimpleOnGestureListener { - - private ViewPagerInterface viewPager; - - private static final float LEFT_REGION = 0.33f; - private static final float RIGHT_REGION = 0.66f; - - public ViewPagerGestureListener(ViewPagerInterface viewPager) { - this.viewPager = viewPager; - } - - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - final int position = viewPager.getCurrentItem(); - final float positionX = e.getX(); - - if (positionX < viewPager.getWidth() * LEFT_REGION) { - if (position != 0) { - onLeftSideTap(); - } else { - onFirstPageOut(); - } - } else if (positionX > viewPager.getWidth() * RIGHT_REGION) { - if (position != viewPager.getAdapter().getCount() - 1) { - onRightSideTap(); - } else { - onLastPageOut(); - } - } else { - onCenterTap(); - } - - return true; - } - - private void onLeftSideTap() { - if (viewPager.getChapterSingleTapListener() != null) { - viewPager.getChapterSingleTapListener().onLeftSideTap(); - } - } - - private void onRightSideTap() { - if (viewPager.getChapterSingleTapListener() != null) { - viewPager.getChapterSingleTapListener().onRightSideTap(); - } - } - - private void onCenterTap() { - if (viewPager.getChapterSingleTapListener() != null) { - viewPager.getChapterSingleTapListener().onCenterTap(); - } - } - - private void onFirstPageOut() { - if (viewPager.getChapterBoundariesListener() != null) { - viewPager.getChapterBoundariesListener().onFirstPageOutEvent(); - } - } - - private void onLastPageOut() { - if (viewPager.getChapterBoundariesListener() != null) { - viewPager.getChapterBoundariesListener().onLastPageOutEvent(); - } - } - -} 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/HorizontalPager.java similarity index 89% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalViewPager.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalPager.java index 938a87809..2115fdfbd 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/HorizontalPager.java @@ -8,11 +8,11 @@ import android.view.MotionEvent; import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterBoundariesOutListener; import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerGestureListener; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface; +import eu.kanade.mangafeed.ui.reader.viewer.common.PagerGestureListener; +import eu.kanade.mangafeed.ui.reader.viewer.common.Pager; import rx.functions.Action1; -public class HorizontalViewPager extends ViewPager implements ViewPagerInterface { +public class HorizontalPager extends ViewPager implements Pager { private GestureDetector gestureDetector; @@ -22,18 +22,18 @@ public class HorizontalViewPager extends ViewPager implements ViewPagerInterface private static final float SWIPE_TOLERANCE = 0.25f; private float startDragX; - public HorizontalViewPager(Context context) { + public HorizontalPager(Context context) { super(context); init(context); } - public HorizontalViewPager(Context context, AttributeSet attrs) { + public HorizontalPager(Context context, AttributeSet attrs) { super(context, attrs); init(context); } private void init(Context context) { - gestureDetector = new GestureDetector(context, new ViewPagerGestureListener(this)); + gestureDetector = new GestureDetector(context, new PagerGestureListener(this)); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java index c825dc4a6..692cd71fa 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/horizontal/HorizontalReader.java @@ -5,13 +5,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader; +import eu.kanade.mangafeed.ui.reader.viewer.common.PagerReader; -public abstract class HorizontalReader extends ViewPagerReader { +public abstract class HorizontalReader extends PagerReader { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { - HorizontalViewPager pager = new HorizontalViewPager(getActivity()); + HorizontalPager pager = new HorizontalPager(getActivity()); initializePager(pager); return pager; } 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/VerticalPager.java similarity index 87% rename from app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalViewPager.java rename to app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalPager.java index 1f704f824..03c9b9f44 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/VerticalPager.java @@ -7,11 +7,11 @@ import android.view.MotionEvent; import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterBoundariesOutListener; import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerGestureListener; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface; +import eu.kanade.mangafeed.ui.reader.viewer.common.PagerGestureListener; +import eu.kanade.mangafeed.ui.reader.viewer.common.Pager; import rx.functions.Action1; -public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPagerInterface { +public class VerticalPager extends VerticalViewPagerImpl implements Pager { private GestureDetector gestureDetector; @@ -21,18 +21,18 @@ public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPage private static final float SWIPE_TOLERANCE = 0.25f; private float startDragY; - public VerticalViewPager(Context context) { + public VerticalPager(Context context) { super(context); init(context); } - public VerticalViewPager(Context context, AttributeSet attrs) { + public VerticalPager(Context context, AttributeSet attrs) { super(context, attrs); init(context); } private void init(Context context) { - gestureDetector = new GestureDetector(context, new VerticalViewPagerGestureListener(this)); + gestureDetector = new GestureDetector(context, new VerticalPagerGestureListener(this)); } @Override @@ -120,10 +120,10 @@ public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPage }); } - private static class VerticalViewPagerGestureListener extends ViewPagerGestureListener { + private static class VerticalPagerGestureListener extends PagerGestureListener { - public VerticalViewPagerGestureListener(ViewPagerInterface viewPager) { - super(viewPager); + public VerticalPagerGestureListener(Pager pager) { + super(pager); } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java index 4961506e3..1711d813b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/vertical/VerticalReader.java @@ -5,13 +5,13 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader; +import eu.kanade.mangafeed.ui.reader.viewer.common.PagerReader; -public class VerticalReader extends ViewPagerReader { +public class VerticalReader extends PagerReader { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { - VerticalViewPager pager = new VerticalViewPager(getActivity()); + VerticalPager pager = new VerticalPager(getActivity()); initializePager(pager); return pager; }