|
|
@@ -7,6 +7,7 @@ import android.support.v7.widget.PagerSnapHelper;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.support.v7.widget.SnapHelper;
|
|
|
import android.util.AttributeSet;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
@@ -74,18 +75,82 @@ public class CustomListicleImageView extends ConstraintLayout {
|
|
|
snapHelper.attachToRecyclerView(recyclerView);
|
|
|
}
|
|
|
|
|
|
+ int oldX;
|
|
|
+ int oldY;
|
|
|
+
|
|
|
+ private static final String DIRECTION_NONE = "none";
|
|
|
+ private static final String DIRECTION_UP = "up";
|
|
|
+ private static final String DIRECTION_DOWN = "down";
|
|
|
+ private static final String DIRECTION_RIGHT = "right";
|
|
|
+ private static final String DIRECTION_LEFT = "left";
|
|
|
+
|
|
|
+ private String getDirection(MotionEvent e) {
|
|
|
+ String direction = DIRECTION_NONE;
|
|
|
+ int action = e.getAction();
|
|
|
+ switch (action) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ oldX = (int) e.getX();
|
|
|
+ oldY = (int) e.getY();
|
|
|
+ break;
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ int newX = (int) e.getX();
|
|
|
+ int newY = (int) e.getY();
|
|
|
+
|
|
|
+ int dx = oldX - newX;
|
|
|
+ int dy = oldY - newY;
|
|
|
+
|
|
|
+ // Use dx and dy to determine the direction of the move
|
|
|
+ if (Math.abs(dx) > Math.abs(dy)) {
|
|
|
+ if (dx > 0) {
|
|
|
+ direction = DIRECTION_RIGHT;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ direction = DIRECTION_LEFT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (dy > 0) {
|
|
|
+ direction = DIRECTION_DOWN;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ direction = DIRECTION_UP;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // nothing
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return direction;
|
|
|
+ }
|
|
|
+
|
|
|
private RecyclerView.OnItemTouchListener touchEventListener = new RecyclerView.OnItemTouchListener() {
|
|
|
@Override
|
|
|
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
|
|
+ String direction = getDirection(e);
|
|
|
+ Log.w("APP# CustomListicleImageView | onInterceptTouchEvent", "|" + "direction: " + direction);
|
|
|
+
|
|
|
int action = e.getAction();
|
|
|
switch (action) {
|
|
|
- case MotionEvent.ACTION_MOVE:
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
case MotionEvent.ACTION_UP:
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
/**
|
|
|
- * todo index 가 0 일 때 좌-> 우 드래그 시 false, index 가 끝일 때 좌<-우 드래그 시 false
|
|
|
+ * index 가 0 일 때 좌-> 우 드래그 시 false, index 가 끝일 때 좌<-우 드래그 시 false
|
|
|
*/
|
|
|
- rv.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
+ boolean intercept = true;
|
|
|
+ if (currentIndex == 0) {
|
|
|
+ if (direction.equals(DIRECTION_LEFT)) {
|
|
|
+ intercept = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (currentIndex == contentsLength - 1) {
|
|
|
+ if (direction.equals(DIRECTION_RIGHT)) {
|
|
|
+ intercept = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rv.getParent().requestDisallowInterceptTouchEvent(intercept);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|