Browse Source

[메인][Common] 스크롤 처리 클래스 분리

Hasemi 7 years ago
parent
commit
c16219e3bf

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

@@ -13,6 +13,7 @@ import android.support.v7.widget.PagerSnapHelper;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.SnapHelper;
 import android.util.DisplayMetrics;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -74,14 +75,14 @@ public class ContentsFragment extends FragmentBase<ContentsPresenter> implements
       @Override
       public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent motionEvent) {
         if (null != layoutManager && layoutManager.findFirstVisibleItemPosition() == adapter.getItemCount() - 1) {
-          if (touchEventWithDirection.getDirection(motionEvent).equals(TouchEventWithDirection.DIRECTION_LEFT)) {
-            direction = TouchEventWithDirection.DIRECTION_LEFT;
-          }
-          else if (null != direction && direction.equals(TouchEventWithDirection.DIRECTION_LEFT)
-            && touchEventWithDirection.getDirection(motionEvent).equals(TouchEventWithDirection.DIRECTION_NONE)) {
+          if (null != direction && direction.equals(TouchEventWithDirection.DIRECTION_LEFT) && motionEvent.getAction() == MotionEvent.ACTION_UP) {
             presenter.onEvent(new Event.Builder(Event.LAST).build());
+            Log.e("APP#  ContentsFragment | onInterceptTouchEvent", "|" + "들어옴");
             direction = null;
           }
+          String currentDirection = touchEventWithDirection.getDirection(motionEvent);
+          direction = currentDirection;
+          Log.e("APP#  ContentsFragment | onInterceptTouchEvent", "|" + direction);
 
         }
         return false;

+ 5 - 52
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/main/MainContentsCategoryHolder.java

@@ -30,7 +30,7 @@ import kr.co.zumo.app.lifeplus.view.IEventListener;
  * @since 2018. 10. 15.
  */
 public class MainContentsCategoryHolder extends MainContentsHolder {
-
+  private String direction = TouchEventWithDirection.DIRECTION_NONE;
   private RecyclerView recyclerView;
   private MainCategoryContentsAdapter adapter;
   private TextView textView;
@@ -160,6 +160,8 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
       }
     });
 
+    TouchEventWithDirection touchEventWithDirection = new TouchEventWithDirection(50);
+
     if (index == 1) {
       recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
         @Override
@@ -172,7 +174,7 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
                * 스크롤 시킬 조건
                * - 1번 카테고리가 화면에서 벗어나 있을 때, (아래 쪽이 잘렸을 때)
                */
-              if (DIRECTION_LEFT.equals(direction) || DIRECTION_RIGHT.equals(direction)) {
+              if (TouchEventWithDirection.DIRECTION_LEFT.equals(direction) || TouchEventWithDirection.DIRECTION_RIGHT.equals(direction)) {
                 listener.onEvent(new Event.Builder(Event.SCROLL).index(index).build());
               }
               break;
@@ -180,7 +182,7 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
               break;
           }
 
-          direction = getDirection(e);
+          direction = touchEventWithDirection.getDirection(e);
           return false;
         }
 
@@ -200,55 +202,6 @@ public class MainContentsCategoryHolder extends MainContentsHolder {
 //    recyclerView.getLayoutManager().onRestoreInstanceState(state);
   }
 
-  int oldX;
-  int oldY;
-  String direction;
-
-  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;
-  }
 
   @Override
   public void dispose() {