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;
public interface ViewPagerInterface {
public interface Pager {
void setId(int id);
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;
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();

View File

@ -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<Page> 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<Page> getPages() {

View File

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

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.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

View File

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

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.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

View File

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