Rename viewpager classes

This commit is contained in:
inorichi 2016-01-04 01:35:05 +01:00
parent 631ef65502
commit e477f2df1f
10 changed files with 104 additions and 104 deletions

View file

@ -6,7 +6,7 @@ import android.view.ViewGroup;
import rx.functions.Action1; import rx.functions.Action1;
public interface ViewPagerInterface { public interface Pager {
void setId(int id); void setId(int id);
void setLayoutParams(ViewGroup.LayoutParams layoutParams); void setLayoutParams(ViewGroup.LayoutParams layoutParams);

View file

@ -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();
}
}
}

View file

@ -12,15 +12,15 @@ import rx.Subscription;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
public abstract class ViewPagerReader extends BaseReader { public abstract class PagerReader extends BaseReader {
protected ViewPagerReaderAdapter adapter; protected PagerReaderAdapter adapter;
protected ViewPagerInterface pager; protected Pager pager;
protected boolean transitions; protected boolean transitions;
protected Subscription transitionsSubscription; protected Subscription transitionsSubscription;
protected void initializePager(ViewPagerInterface pager) { protected void initializePager(Pager pager) {
this.pager = pager; this.pager = pager;
pager.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); pager.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
pager.setOffscreenPageLimit(2); pager.setOffscreenPageLimit(2);
@ -53,7 +53,7 @@ public abstract class ViewPagerReader extends BaseReader {
} }
}); });
adapter = new ViewPagerReaderAdapter(getChildFragmentManager()); adapter = new PagerReaderAdapter(getChildFragmentManager());
pager.setAdapter(adapter); pager.setAdapter(adapter);
setPages(); setPages();

View file

@ -8,11 +8,11 @@ import java.util.List;
import eu.kanade.mangafeed.data.source.model.Page; import eu.kanade.mangafeed.data.source.model.Page;
public class ViewPagerReaderAdapter extends FragmentStatePagerAdapter { public class PagerReaderAdapter extends FragmentStatePagerAdapter {
private List<Page> pages; private List<Page> pages;
public ViewPagerReaderAdapter(FragmentManager fragmentManager) { public PagerReaderAdapter(FragmentManager fragmentManager) {
super(fragmentManager); super(fragmentManager);
} }
@ -23,7 +23,7 @@ public class ViewPagerReaderAdapter extends FragmentStatePagerAdapter {
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
return ViewPagerReaderFragment.newInstance(pages.get(position)); return PagerReaderFragment.newInstance(pages.get(position));
} }
public List<Page> getPages() { public List<Page> getPages() {

View file

@ -31,7 +31,7 @@ import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; import rx.schedulers.Schedulers;
import rx.subjects.PublishSubject; 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.page_image_view) SubsamplingScaleImageView imageView;
@Bind(R.id.progress_container) LinearLayout progressContainer; @Bind(R.id.progress_container) LinearLayout progressContainer;
@ -43,8 +43,8 @@ public class ViewPagerReaderFragment extends BaseFragment {
private Subscription progressSubscription; private Subscription progressSubscription;
private Subscription statusSubscription; private Subscription statusSubscription;
public static ViewPagerReaderFragment newInstance(Page page) { public static PagerReaderFragment newInstance(Page page) {
ViewPagerReaderFragment fragment = new ViewPagerReaderFragment(); PagerReaderFragment fragment = new PagerReaderFragment();
fragment.setPage(page); fragment.setPage(page);
return fragment; return fragment;
} }

View file

@ -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();
}
}
}

View file

@ -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.OnChapterBoundariesOutListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener; 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.PagerGestureListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface; import eu.kanade.mangafeed.ui.reader.viewer.common.Pager;
import rx.functions.Action1; import rx.functions.Action1;
public class HorizontalViewPager extends ViewPager implements ViewPagerInterface { public class HorizontalPager extends ViewPager implements Pager {
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
@ -22,18 +22,18 @@ public class HorizontalViewPager extends ViewPager implements ViewPagerInterface
private static final float SWIPE_TOLERANCE = 0.25f; private static final float SWIPE_TOLERANCE = 0.25f;
private float startDragX; private float startDragX;
public HorizontalViewPager(Context context) { public HorizontalPager(Context context) {
super(context); super(context);
init(context); init(context);
} }
public HorizontalViewPager(Context context, AttributeSet attrs) { public HorizontalPager(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(context); init(context);
} }
private void init(Context context) { private void init(Context context) {
gestureDetector = new GestureDetector(context, new ViewPagerGestureListener(this)); gestureDetector = new GestureDetector(context, new PagerGestureListener(this));
} }
@Override @Override

View file

@ -5,13 +5,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
HorizontalViewPager pager = new HorizontalViewPager(getActivity()); HorizontalPager pager = new HorizontalPager(getActivity());
initializePager(pager); initializePager(pager);
return pager; return pager;
} }

View file

@ -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.OnChapterBoundariesOutListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.OnChapterSingleTapListener; 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.PagerGestureListener;
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface; import eu.kanade.mangafeed.ui.reader.viewer.common.Pager;
import rx.functions.Action1; import rx.functions.Action1;
public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPagerInterface { public class VerticalPager extends VerticalViewPagerImpl implements Pager {
private GestureDetector gestureDetector; private GestureDetector gestureDetector;
@ -21,18 +21,18 @@ public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPage
private static final float SWIPE_TOLERANCE = 0.25f; private static final float SWIPE_TOLERANCE = 0.25f;
private float startDragY; private float startDragY;
public VerticalViewPager(Context context) { public VerticalPager(Context context) {
super(context); super(context);
init(context); init(context);
} }
public VerticalViewPager(Context context, AttributeSet attrs) { public VerticalPager(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(context); init(context);
} }
private void init(Context context) { private void init(Context context) {
gestureDetector = new GestureDetector(context, new VerticalViewPagerGestureListener(this)); gestureDetector = new GestureDetector(context, new VerticalPagerGestureListener(this));
} }
@Override @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) { public VerticalPagerGestureListener(Pager pager) {
super(viewPager); super(pager);
} }
@Override @Override

View file

@ -5,13 +5,13 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
VerticalViewPager pager = new VerticalViewPager(getActivity()); VerticalPager pager = new VerticalPager(getActivity());
initializePager(pager); initializePager(pager);
return pager; return pager;
} }