Bug 1399042: Move NO_POSITION check for IndexOutOfBoundsException in onItemClick. r?mcomella draft
authorChenxia Liu <liuche@mozilla.com>
Wed, 13 Sep 2017 14:31:51 -0700
changeset 664361 07e4f481271bdd54ce3de78af74df79e745a8ef9
parent 663134 a73cc4e08bf5a005722c95b43f84ab0c8ff2bc7c
child 731433 6cdd225f432de8c5f32d13e5206f41f86b4e9c77
push id79684
push usercliu@mozilla.com
push dateWed, 13 Sep 2017 21:40:35 +0000
reviewersmcomella
bugs1399042
milestone57.0a1
Bug 1399042: Move NO_POSITION check for IndexOutOfBoundsException in onItemClick. r?mcomella MozReview-Commit-ID: GAs6HOwp8ru
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/StreamRecyclerAdapter.java
@@ -235,38 +235,38 @@ public class StreamRecyclerAdapter exten
         }
 
         final WebpageItemRow highlightItem = (WebpageItemRow) recyclerView.getChildViewHolder(v);
         openContextMenu(highlightItem, position, ActivityStreamTelemetry.Contract.INTERACTION_LONG_CLICK);
         return true;
     }
 
     private boolean onItemClickIsValidRowItem(final int position) {
-        final int viewType = getItemViewType(position);
-        if (viewType != RowItemType.HIGHLIGHT_ITEM.getViewType()
-                && viewType != RowItemType.TOP_STORIES_ITEM.getViewType()) {
-            // Headers (containing topsites and/or the highlights title) do their own click handling as needed
-            return false;
-        }
-
         // The position this method receives is from RecyclerView.ViewHolder.getAdapterPosition, whose docs state:
         // "Note that if you've called notifyDataSetChanged(), until the next layout pass, the return value of this
         // method will be NO_POSITION."
         //
         // At the time of writing, we call notifyDataSetChanged for:
         // - swapHighlights (can't do anything about this)
         // - setTileSize (in theory, we might be able to do something hacky to get the existing highlights list)
         //
         // Given the low crash rate (34 crashes in 23 days), I don't think it's worth investigating further
         // or adding a hack.
         if (position == RecyclerView.NO_POSITION) {
             Log.w(LOGTAG, "onItemClicked: received NO_POSITION. Returning");
             return false;
         }
 
+        final int viewType = getItemViewType(position);
+        if (viewType != RowItemType.HIGHLIGHT_ITEM.getViewType()
+                && viewType != RowItemType.TOP_STORIES_ITEM.getViewType()) {
+            // Headers (containing topsites and/or the highlights title) do their own click handling as needed
+            return false;
+        }
+
         return true;
     }
 
     @Override
     public void openContextMenu(final WebpageItemRow webpageItemRow, final int position, @NonNull final String interactionExtra) {
         final WebpageRowModel model = (WebpageRowModel) recyclerViewModel.get(position);
 
         final String sourceType;