jenkins-bot has submitted this change and it was merged.

Change subject: Workaround ItemTouchHelper NPE
......................................................................


Workaround ItemTouchHelper NPE

This issue occurs with "don't keep activities" enabled while quickly
tapping a news item.

Change-Id: Idaed5f133806ad3d70cae3039e2f445c7b98159b
---
M app/src/main/java/org/wikipedia/feed/view/FeedView.java
1 file changed, 33 insertions(+), 1 deletion(-)

Approvals:
  Dbrant: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/feed/view/FeedView.java 
b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
index 4749803..a97716a 100644
--- a/app/src/main/java/org/wikipedia/feed/view/FeedView.java
+++ b/app/src/main/java/org/wikipedia/feed/view/FeedView.java
@@ -2,11 +2,15 @@
 
 import android.content.Context;
 import android.support.annotation.Nullable;
+import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.StaggeredGridLayoutManager;
 import android.support.v7.widget.helper.ItemTouchHelper;
 import android.util.AttributeSet;
+import android.view.View;
 
 import org.wikipedia.R;
+import org.wikipedia.crash.RemoteLogException;
+import org.wikipedia.util.log.L;
 import org.wikipedia.views.AutoFitRecyclerView;
 import org.wikipedia.views.HeaderMarginItemDecoration;
 import org.wikipedia.views.ItemTouchHelperSwipeAdapter;
@@ -33,7 +37,7 @@
 
     public void callback(@Nullable ItemTouchHelperSwipeAdapter.Callback 
callback) {
         if (itemTouchHelper != null) {
-            itemTouchHelper.attachToRecyclerView(null);
+            itemTouchHelper.attachToRecyclerView(new DummyView(getContext()));
             itemTouchHelper = null;
         }
 
@@ -64,6 +68,34 @@
         callback(new RecyclerViewColumnCallback());
     }
 
+    /* Workaround for 
https://code.google.com/p/android/issues/detail?id=205947.
+       ItemTouchHelper.attachToRecyclerView(null) should remove its gesture 
callback before nulling
+       its RecyclerView:
+        java.lang.NullPointerException: Attempt to invoke virtual method 
'android.view.View 
android.support.v7.widget.RecyclerView.findChildViewUnder(float, float)' on a 
null object reference
+            at 
android.support.v7.widget.helper.ItemTouchHelper.findChildView(ItemTouchHelper.java:1024)
+            at 
android.support.v7.widget.helper.ItemTouchHelper.access$2400(ItemTouchHelper.java:76)
+            at 
android.support.v7.widget.helper.ItemTouchHelper$ItemTouchHelperGestureListener.onLongPress(ItemTouchHelper.java:2265)
+            at 
android.view.GestureDetector.dispatchLongPress(GestureDetector.java:770)
+            at android.view.GestureDetector.-wrap0(GestureDetector.java)
+            at 
android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:293)
+            at android.os.Handler.dispatchMessage(Handler.java:102)
+            at android.os.Looper.loop(Looper.java:154)
+            at android.app.ActivityThread.main(ActivityThread.java:6077)
+            at java.lang.reflect.Method.invoke(Native Method)
+            at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
+            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
+     */
+    private static class DummyView extends RecyclerView {
+        DummyView(Context context) {
+            super(context);
+        }
+
+        @Override public View findChildViewUnder(float x, float y) {
+            L.logRemoteError(new 
RemoteLogException("ItemTouchHelper.attachToRecyclerView(null)"));
+            return super.findChildViewUnder(x, y);
+        }
+    }
+
     private class RecyclerViewColumnCallback implements 
AutoFitRecyclerView.Callback {
         @Override public void onColumns(int columns) {
             // todo: when there is only one element, should we setSpanCount to 
1? e.g.:

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Idaed5f133806ad3d70cae3039e2f445c7b98159b
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to