Changes to viewpager readers
This commit is contained in:
parent
e2795f5480
commit
273527e7fb
@ -57,6 +57,11 @@ public abstract class BaseReader {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPageChanged(int position) {
|
||||
currentPosition = position;
|
||||
updatePageNumber();
|
||||
}
|
||||
|
||||
public void destroy() {}
|
||||
|
||||
public abstract int getTotalPages();
|
||||
|
@ -0,0 +1,6 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.common;
|
||||
|
||||
public interface OnChapterBoundariesOutListener {
|
||||
void onFirstPageOutEvent();
|
||||
void onLastPageOutEvent();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.common;
|
||||
|
||||
public interface OnChapterSingleTapListener {
|
||||
void onCenterTap();
|
||||
void onLeftSideTap();
|
||||
void onRightSideTap();
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.common;
|
||||
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public interface ViewPagerInterface {
|
||||
|
||||
void setOffscreenPageLimit(int limit);
|
||||
|
||||
int getCurrentItem();
|
||||
void setCurrentItem(int item, boolean smoothScroll);
|
||||
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
|
||||
PagerAdapter getAdapter();
|
||||
void setAdapter(PagerAdapter adapter);
|
||||
|
||||
boolean onImageTouch(MotionEvent motionEvent);
|
||||
|
||||
void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener);
|
||||
void setOnChapterSingleTapListener(OnChapterSingleTapListener listener);
|
||||
|
||||
OnChapterBoundariesOutListener getChapterBoundariesListener();
|
||||
OnChapterSingleTapListener getChapterSingleTapListener();
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.common;
|
||||
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.kanade.mangafeed.data.source.model.Page;
|
||||
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader;
|
||||
import rx.Subscription;
|
||||
|
||||
public abstract class ViewPagerReader extends BaseReader {
|
||||
|
||||
protected ViewPagerReaderAdapter adapter;
|
||||
protected ViewPagerInterface viewPager;
|
||||
|
||||
protected boolean transitions;
|
||||
protected Subscription transitionsSubscription;
|
||||
|
||||
public ViewPagerReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
|
||||
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable()
|
||||
.subscribe(value -> transitions = value);
|
||||
}
|
||||
|
||||
protected void initializeViewPager() {
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
viewPager.setOnChapterBoundariesOutListener(new OnChapterBoundariesOutListener() {
|
||||
@Override
|
||||
public void onFirstPageOutEvent() {
|
||||
onFirstPageOut();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLastPageOutEvent() {
|
||||
onLastPageOut();
|
||||
}
|
||||
});
|
||||
viewPager.setOnChapterSingleTapListener(new OnChapterSingleTapListener() {
|
||||
@Override
|
||||
public void onCenterTap() {
|
||||
activity.onCenterSingleTap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalPages() {
|
||||
return adapter.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedPage(int pageNumber) {
|
||||
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onImageTouch(MotionEvent motionEvent) {
|
||||
return viewPager.onImageTouch(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageListReady(List<Page> pages) {
|
||||
currentPosition = 0;
|
||||
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
|
||||
viewPager.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CallSuper
|
||||
public void destroy() {
|
||||
transitionsSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
public abstract void onFirstPageOut();
|
||||
public abstract void onLastPageOut();
|
||||
|
||||
}
|
@ -1,100 +1,26 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.horizontal;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.source.model.Page;
|
||||
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReaderAdapter;
|
||||
import rx.Subscription;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader;
|
||||
|
||||
public abstract class HorizontalReader extends BaseReader {
|
||||
|
||||
@Bind(R.id.view_pager) HorizontalViewPager viewPager;
|
||||
|
||||
protected ViewPagerReaderAdapter adapter;
|
||||
|
||||
private boolean transitions;
|
||||
private Subscription transitionsSubscription;
|
||||
public abstract class HorizontalReader extends ViewPagerReader {
|
||||
|
||||
public HorizontalReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container);
|
||||
ButterKnife.bind(this, container);
|
||||
|
||||
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable()
|
||||
.subscribe(value -> transitions = value);
|
||||
viewPager = (ViewPagerInterface) container.findViewById(R.id.view_pager);
|
||||
initializeViewPager();
|
||||
((HorizontalViewPager) viewPager).addOnPageChangeListener(new PageChangeListener());
|
||||
}
|
||||
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
viewPager.addOnPageChangeListener(new HorizontalViewPager.SimpleOnPageChangeListener() {
|
||||
private class PageChangeListener extends HorizontalViewPager.SimpleOnPageChangeListener {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
currentPosition = position;
|
||||
updatePageNumber();
|
||||
onPageChanged(position);
|
||||
}
|
||||
});
|
||||
viewPager.setOnChapterBoundariesOutListener(new HorizontalViewPager.OnChapterBoundariesOutListener() {
|
||||
@Override
|
||||
public void onFirstPageOutEvent() {
|
||||
onFirstPageOut();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLastPageOutEvent() {
|
||||
onLastPageOut();
|
||||
}
|
||||
});
|
||||
viewPager.setOnChapterSingleTapListener(new HorizontalViewPager.OnChapterSingleTapListener() {
|
||||
@Override
|
||||
public void onCenterTap() {
|
||||
activity.onCenterSingleTap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalPages() {
|
||||
return adapter.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedPage(int pageNumber) {
|
||||
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageListReady(List<Page> pages) {
|
||||
currentPosition = 0;
|
||||
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
|
||||
viewPager.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onImageTouch(MotionEvent motionEvent) {
|
||||
return viewPager.onImageTouch(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
transitionsSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
public abstract void onFirstPageOut();
|
||||
public abstract void onLastPageOut();
|
||||
|
||||
}
|
||||
|
@ -6,61 +6,66 @@ import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class HorizontalViewPager extends ViewPager {
|
||||
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;
|
||||
|
||||
public class HorizontalViewPager extends ViewPager implements ViewPagerInterface {
|
||||
|
||||
private GestureDetector gestureDetector;
|
||||
|
||||
private OnChapterBoundariesOutListener mOnChapterBoundariesOutListener;
|
||||
private OnChapterSingleTapListener mOnChapterSingleTapListener;
|
||||
private OnChapterBoundariesOutListener onChapterBoundariesOutListener;
|
||||
private OnChapterSingleTapListener onChapterSingleTapListener;
|
||||
|
||||
private static final float LEFT_REGION = 0.33f;
|
||||
private static final float RIGHT_REGION = 0.66f;
|
||||
private static final float SWIPE_TOLERANCE = 0.25f;
|
||||
private float startDragX;
|
||||
|
||||
public HorizontalViewPager(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public HorizontalViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
gestureDetector = new GestureDetector(getContext(), new ReaderViewGestureListener());
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
gestureDetector = new GestureDetector(context, new ViewPagerGestureListener(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
|
||||
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) {
|
||||
if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) {
|
||||
startDragX = ev.getX();
|
||||
}
|
||||
}
|
||||
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do Nothing.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
if (this.getCurrentItem() == 0) {
|
||||
if (onChapterBoundariesOutListener != null) {
|
||||
if (getCurrentItem() == 0) {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
|
||||
float displacement = ev.getX() - startDragX;
|
||||
|
||||
if (ev.getX() > startDragX && displacement > getWidth() * SWIPE_TOLERANCE) {
|
||||
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
onChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
startDragX = 0;
|
||||
}
|
||||
} else if (this.getCurrentItem() == this.getAdapter().getCount() - 1) {
|
||||
} else if (getCurrentItem() == getAdapter().getCount() - 1) {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
|
||||
float displacement = startDragX - ev.getX();
|
||||
|
||||
if (ev.getX() < startDragX && displacement > getWidth() * SWIPE_TOLERANCE) {
|
||||
mOnChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
onChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -70,73 +75,31 @@ public class HorizontalViewPager extends ViewPager {
|
||||
}
|
||||
|
||||
return super.onTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do Nothing.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onImageTouch(MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public interface OnChapterBoundariesOutListener {
|
||||
void onFirstPageOutEvent();
|
||||
void onLastPageOutEvent();
|
||||
@Override
|
||||
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener) {
|
||||
onChapterBoundariesOutListener = listener;
|
||||
}
|
||||
|
||||
public interface OnChapterSingleTapListener {
|
||||
void onCenterTap();
|
||||
void onLeftSideTap();
|
||||
void onRightSideTap();
|
||||
}
|
||||
|
||||
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener onChapterBoundariesOutListener) {
|
||||
mOnChapterBoundariesOutListener = onChapterBoundariesOutListener;
|
||||
}
|
||||
|
||||
public void setOnChapterSingleTapListener(OnChapterSingleTapListener onChapterSingleTapListener) {
|
||||
mOnChapterSingleTapListener = onChapterSingleTapListener;
|
||||
}
|
||||
|
||||
|
||||
private class ReaderViewGestureListener extends GestureDetector.SimpleOnGestureListener {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
final int position = getCurrentItem();
|
||||
final float positionX = e.getX();
|
||||
|
||||
if (positionX < getWidth() * LEFT_REGION) {
|
||||
if (position != 0) {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onLeftSideTap();
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
}
|
||||
}
|
||||
} else if (positionX > getWidth() * RIGHT_REGION) {
|
||||
if (position != getAdapter().getCount() - 1) {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onRightSideTap();
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
mOnChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onCenterTap();
|
||||
}
|
||||
public void setOnChapterSingleTapListener(OnChapterSingleTapListener listener) {
|
||||
onChapterSingleTapListener = listener;
|
||||
}
|
||||
|
||||
return true;
|
||||
@Override
|
||||
public OnChapterBoundariesOutListener getChapterBoundariesListener() {
|
||||
return onChapterBoundariesOutListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnChapterSingleTapListener getChapterSingleTapListener() {
|
||||
return onChapterSingleTapListener;
|
||||
}
|
||||
|
||||
}
|
@ -1,97 +1,36 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.vertical;
|
||||
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.mangafeed.R;
|
||||
import eu.kanade.mangafeed.data.source.model.Page;
|
||||
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReaderAdapter;
|
||||
import rx.Subscription;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerInterface;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReader;
|
||||
|
||||
public class VerticalReader extends BaseReader {
|
||||
|
||||
@Bind(R.id.view_pager) VerticalViewPager viewPager;
|
||||
|
||||
private ViewPagerReaderAdapter adapter;
|
||||
|
||||
private boolean transitions;
|
||||
private Subscription transitionsSubscription;
|
||||
public class VerticalReader extends ViewPagerReader {
|
||||
|
||||
public VerticalReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
activity.getLayoutInflater().inflate(R.layout.reader_vertical, container);
|
||||
ButterKnife.bind(this, container);
|
||||
|
||||
transitionsSubscription = activity.getPreferences().enableTransitions().asObservable()
|
||||
.subscribe(value -> transitions = value);
|
||||
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
currentPosition = position;
|
||||
updatePageNumber();
|
||||
viewPager = (ViewPagerInterface) container.findViewById(R.id.view_pager);
|
||||
initializeViewPager();
|
||||
((VerticalViewPager) viewPager).addOnPageChangeListener(new PageChangeListener());
|
||||
}
|
||||
});
|
||||
viewPager.setOnChapterBoundariesOutListener(new VerticalViewPager.OnChapterBoundariesOutListener() {
|
||||
|
||||
@Override
|
||||
public void onFirstPageOutEvent() {
|
||||
public void onFirstPageOut() {
|
||||
requestPreviousChapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLastPageOutEvent() {
|
||||
public void onLastPageOut() {
|
||||
requestNextChapter();
|
||||
}
|
||||
});
|
||||
viewPager.setOnChapterSingleTapListener(new VerticalViewPager.OnChapterSingleTapListener() {
|
||||
|
||||
private class PageChangeListener extends VerticalViewPagerImpl.SimpleOnPageChangeListener {
|
||||
@Override
|
||||
public void onCenterTap() {
|
||||
activity.onCenterSingleTap();
|
||||
public void onPageSelected(int position) {
|
||||
onPageChanged(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRightSideTap() {
|
||||
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalPages() {
|
||||
return adapter.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedPage(int pageNumber) {
|
||||
viewPager.setCurrentItem(getCurrentPageIndex(pageNumber), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageListReady(List<Page> pages) {
|
||||
currentPosition = 0;
|
||||
adapter = new ViewPagerReaderAdapter(activity.getSupportFragmentManager(), pages);
|
||||
viewPager.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onImageTouch(MotionEvent motionEvent) {
|
||||
return viewPager.onImageTouch(motionEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
transitionsSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
@ -5,61 +5,66 @@ import android.util.AttributeSet;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.VerticalViewPager {
|
||||
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;
|
||||
|
||||
public class VerticalViewPager extends VerticalViewPagerImpl implements ViewPagerInterface {
|
||||
|
||||
private GestureDetector gestureDetector;
|
||||
|
||||
private OnChapterBoundariesOutListener mOnChapterBoundariesOutListener;
|
||||
private OnChapterSingleTapListener mOnChapterSingleTapListener;
|
||||
private OnChapterBoundariesOutListener onChapterBoundariesOutListener;
|
||||
private OnChapterSingleTapListener onChapterSingleTapListener;
|
||||
|
||||
private static final float LEFT_REGION = 0.33f;
|
||||
private static final float RIGHT_REGION = 0.66f;
|
||||
private static final float SWIPE_TOLERANCE = 0.25f;
|
||||
private float startDragY;
|
||||
|
||||
public VerticalViewPager(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public VerticalViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
gestureDetector = new GestureDetector(getContext(), new ReaderViewGestureListener());
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
gestureDetector = new GestureDetector(context, new VerticalViewPagerGestureListener(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
|
||||
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) {
|
||||
if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) {
|
||||
startDragY = ev.getY();
|
||||
}
|
||||
}
|
||||
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do Nothing.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
if (this.getCurrentItem() == 0) {
|
||||
if (onChapterBoundariesOutListener != null) {
|
||||
if (getCurrentItem() == 0) {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
|
||||
float displacement = ev.getY() - startDragY;
|
||||
|
||||
if (ev.getY() > startDragY && displacement > getHeight() * SWIPE_TOLERANCE) {
|
||||
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
onChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
startDragY = 0;
|
||||
}
|
||||
} else if (this.getCurrentItem() == this.getAdapter().getCount() - 1) {
|
||||
} else if (getCurrentItem() == getAdapter().getCount() - 1) {
|
||||
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
|
||||
float displacement = startDragY - ev.getY();
|
||||
|
||||
if (ev.getY() < startDragY && displacement > getHeight() * SWIPE_TOLERANCE) {
|
||||
mOnChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
onChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -69,71 +74,46 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V
|
||||
}
|
||||
|
||||
return super.onTouchEvent(ev);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Do Nothing.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onImageTouch(MotionEvent event) {
|
||||
return gestureDetector.onTouchEvent(event);
|
||||
}
|
||||
|
||||
public interface OnChapterBoundariesOutListener {
|
||||
void onFirstPageOutEvent();
|
||||
void onLastPageOutEvent();
|
||||
@Override
|
||||
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener listener) {
|
||||
onChapterBoundariesOutListener = listener;
|
||||
}
|
||||
|
||||
public interface OnChapterSingleTapListener {
|
||||
void onCenterTap();
|
||||
void onLeftSideTap();
|
||||
void onRightSideTap();
|
||||
}
|
||||
|
||||
public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener onChapterBoundariesOutListener) {
|
||||
mOnChapterBoundariesOutListener = onChapterBoundariesOutListener;
|
||||
}
|
||||
|
||||
public void setOnChapterSingleTapListener(OnChapterSingleTapListener onChapterSingleTapListener) {
|
||||
mOnChapterSingleTapListener = onChapterSingleTapListener;
|
||||
}
|
||||
|
||||
private class ReaderViewGestureListener extends GestureDetector.SimpleOnGestureListener {
|
||||
|
||||
@Override
|
||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
final int position = getCurrentItem();
|
||||
final float positionX = e.getX();
|
||||
|
||||
if (positionX < getWidth() * LEFT_REGION) {
|
||||
if (position != 0) {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onLeftSideTap();
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
mOnChapterBoundariesOutListener.onFirstPageOutEvent();
|
||||
}
|
||||
}
|
||||
} else if (positionX > getWidth() * RIGHT_REGION) {
|
||||
if (position != getAdapter().getCount() - 1) {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onRightSideTap();
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterBoundariesOutListener != null) {
|
||||
mOnChapterBoundariesOutListener.onLastPageOutEvent();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mOnChapterSingleTapListener != null) {
|
||||
mOnChapterSingleTapListener.onCenterTap();
|
||||
}
|
||||
public void setOnChapterSingleTapListener(OnChapterSingleTapListener listener) {
|
||||
onChapterSingleTapListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnChapterBoundariesOutListener getChapterBoundariesListener() {
|
||||
return onChapterBoundariesOutListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnChapterSingleTapListener getChapterSingleTapListener() {
|
||||
return onChapterSingleTapListener;
|
||||
}
|
||||
|
||||
private class VerticalViewPagerGestureListener extends ViewPagerGestureListener {
|
||||
|
||||
public VerticalViewPagerGestureListener(ViewPagerInterface viewPager) {
|
||||
super(viewPager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
// Vertical view pager ignores scrolling events sometimes.
|
||||
// Returning true here fixes it, but we lose touch events on the image like
|
||||
// double tap to zoom
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,6 @@
|
||||
<color name="line_grey">@color/md_light_dividers</color>
|
||||
<color name="light_grey">@color/md_grey_300</color>
|
||||
<color name="page_number_background">#AAE9E9E9</color>
|
||||
<color name="page_number_background_black">#AA252525</color>
|
||||
<color name="page_number_background_black">#99252525</color>
|
||||
<color name="reader_menu_background">@color/colorPrimarySuperDark</color>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user