Niedzielski has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311633

Change subject: Hygiene: refactor feed CardView listener to file
......................................................................

Hygiene: refactor feed CardView listener to file

Move HorizontalScrollingListCardView.DontInterceptTouchListener to new
file. The listener is large and independent enough to separate.

Change-Id: Idbfbfa1a8c4025566b1a8357e6d36da034f8fdda
---
M app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
A app/src/main/java/org/wikipedia/views/DontInterceptTouchListener.java
2 files changed, 59 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/33/311633/1

diff --git 
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
 
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
index 914faa2..1db791f 100644
--- 
a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
+++ 
b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java
@@ -3,18 +3,16 @@
 import android.content.Context;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
-import android.support.v4.view.MotionEventCompat;
 import android.support.v7.widget.CardView;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
-import android.view.MotionEvent;
 import android.view.View;
-import android.view.ViewConfiguration;
 import android.view.ViewGroup;
 
 import org.wikipedia.R;
 import org.wikipedia.views.DefaultRecyclerAdapter;
 import org.wikipedia.views.DefaultViewHolder;
+import org.wikipedia.views.DontInterceptTouchListener;
 import org.wikipedia.views.MarginItemDecoration;
 import org.wikipedia.views.ViewUtil;
 
@@ -87,57 +85,5 @@
                                                                                
          int viewType) {
             return new DefaultViewHolder<>(new 
HorizontalScrollingListCardItemView(parent.getContext()));
         }
-    }
-
-    private static class DontInterceptTouchListener implements 
RecyclerView.OnItemTouchListener {
-        private int pointerId = Integer.MIN_VALUE;
-        private float x = Float.MIN_VALUE;
-        private float y = Float.MIN_VALUE;
-        private boolean disallowInterception;
-
-        @Override public boolean onInterceptTouchEvent(RecyclerView view, 
MotionEvent event) {
-            int action = MotionEventCompat.getActionMasked(event);
-            switch(action) {
-                case MotionEvent.ACTION_DOWN:
-                    pointerId = MotionEventCompat.getPointerId(event, 0);
-                    x = event.getX();
-                    y = event.getY();
-                    break;
-                case MotionEvent.ACTION_MOVE:
-                    if (disallowInterception) {
-                        break;
-                    }
-
-                    int pointerIndex = 
MotionEventCompat.findPointerIndex(event, pointerId);
-                    if (pointerIndex < 0) {
-                        
view.getParent().requestDisallowInterceptTouchEvent(false);
-                        break;
-                    }
-
-                    float dy = Math.abs(y - MotionEventCompat.getY(event, 
pointerIndex));
-                    float dx = Math.abs(x - MotionEventCompat.getX(event, 
pointerIndex));
-                    int slop = 
ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
-
-                    if (dx > slop) {
-                        disallowInterception = true;
-                    } else if (dy > slop) {
-                        
view.getParent().requestDisallowInterceptTouchEvent(false);
-                        break;
-                    }
-
-                    view.getParent().requestDisallowInterceptTouchEvent(true);
-                    break;
-                default:
-                    this.pointerId = Integer.MIN_VALUE;
-                    x = Float.MIN_VALUE;
-                    y = Float.MIN_VALUE;
-                    disallowInterception = false;
-                    break;
-            }
-            return false;
-        }
-
-        @Override public void onTouchEvent(RecyclerView view, MotionEvent 
event) { }
-        @Override public void onRequestDisallowInterceptTouchEvent(boolean 
disallowIntercept) { }
     }
 }
diff --git 
a/app/src/main/java/org/wikipedia/views/DontInterceptTouchListener.java 
b/app/src/main/java/org/wikipedia/views/DontInterceptTouchListener.java
new file mode 100644
index 0000000..78f288d
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/views/DontInterceptTouchListener.java
@@ -0,0 +1,58 @@
+package org.wikipedia.views;
+
+import android.support.v4.view.MotionEventCompat;
+import android.support.v7.widget.RecyclerView;
+import android.view.MotionEvent;
+import android.view.ViewConfiguration;
+
+public class DontInterceptTouchListener implements 
RecyclerView.OnItemTouchListener {
+    private int pointerId = Integer.MIN_VALUE;
+    private float x = Float.MIN_VALUE;
+    private float y = Float.MIN_VALUE;
+    private boolean disallowInterception;
+
+    @Override public boolean onInterceptTouchEvent(RecyclerView view, 
MotionEvent event) {
+        int action = MotionEventCompat.getActionMasked(event);
+        switch(action) {
+            case MotionEvent.ACTION_DOWN:
+                pointerId = MotionEventCompat.getPointerId(event, 0);
+                x = event.getX();
+                y = event.getY();
+                break;
+            case MotionEvent.ACTION_MOVE:
+                if (disallowInterception) {
+                    break;
+                }
+
+                int pointerIndex = MotionEventCompat.findPointerIndex(event, 
pointerId);
+                if (pointerIndex < 0) {
+                    view.getParent().requestDisallowInterceptTouchEvent(false);
+                    break;
+                }
+
+                float dy = Math.abs(y - MotionEventCompat.getY(event, 
pointerIndex));
+                float dx = Math.abs(x - MotionEventCompat.getX(event, 
pointerIndex));
+                int slop = 
ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
+
+                if (dx > slop) {
+                    disallowInterception = true;
+                } else if (dy > slop) {
+                    view.getParent().requestDisallowInterceptTouchEvent(false);
+                    break;
+                }
+
+                view.getParent().requestDisallowInterceptTouchEvent(true);
+                break;
+            default:
+                this.pointerId = Integer.MIN_VALUE;
+                x = Float.MIN_VALUE;
+                y = Float.MIN_VALUE;
+                disallowInterception = false;
+                break;
+        }
+        return false;
+    }
+
+    @Override public void onTouchEvent(RecyclerView view, MotionEvent event) { 
}
+    @Override public void onRequestDisallowInterceptTouchEvent(boolean 
disallowIntercept) { }
+}
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/311633
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idbfbfa1a8c4025566b1a8357e6d36da034f8fdda
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to