Преглед изворни кода

[콘텐츠상세][Common] 콘텐츠 마지막장 도달시 오른쪽 드래그 액션 발생시 마지막 토스트

Hasemi пре 7 година
родитељ
комит
495186bee3

+ 4 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/contents/ContentsFragment.java

@@ -27,6 +27,7 @@ import kr.co.zumo.app.lifeplus.helper.ActionBarHelper;
 import kr.co.zumo.app.lifeplus.util.AppUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
+import kr.co.zumo.app.lifeplus.view.screen.main.TouchEventWithDirection;
 
 /**
  * ContentsFragment
@@ -197,10 +198,12 @@ public class ContentsFragment extends FragmentBase<ContentsPresenter> implements
         startSmoothScroll(linearSmoothScroller);
       }
     };
+    
+    TouchEventWithDirection touchEventWithDirection = new TouchEventWithDirection();
     recyclerViewContentsDetail.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
       @Override
       public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent motionEvent) {
-        if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
+        if (touchEventWithDirection.getDirection(motionEvent).equals(TouchEventWithDirection.DIRECTION_RIGHT)) {
           if (layoutManager.findFirstVisibleItemPosition() == contentsDetailBeans.size() - 1) {
             presenter.onEvent(new Event.Builder(Event.NONE).build());
           }

+ 67 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/TouchEventWithDirection.java

@@ -0,0 +1,67 @@
+package kr.co.zumo.app.lifeplus.view.screen.main;
+
+import android.view.MotionEvent;
+
+/**
+ * TouchEventWithDirection
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-12-13]   [최초 작성]
+ * @since 2018-12-13
+ */
+public class TouchEventWithDirection {
+
+  public static final String DIRECTION_NONE = "none";
+  public static final String DIRECTION_UP = "up";
+  public static final String DIRECTION_DOWN = "down";
+  public static final String DIRECTION_RIGHT = "right";
+  public static final String DIRECTION_LEFT = "left";
+
+  private String direction;
+  private int oldX;
+  private int oldY;
+
+  public String getDirection(MotionEvent e) {
+    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;
+  }
+
+}