Bug 775512 - HistoryDividerItemDecoration: Ignore views that do not have an adapter position anymore. r=ahunt, a=ritu
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 19 Aug 2016 14:26:42 +0200
changeset 349910 97dd093ea5c7e2dc11f29ddfaf0d881c64dfb95c
parent 349909 d6be383e84be73c4b1d1e7d2248c978e501a6b40
child 349911 b7595b0e873652d31aaf1018193dde1f031b33d6
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, ritu
bugs775512
milestone50.0a2
Bug 775512 - HistoryDividerItemDecoration: Ignore views that do not have an adapter position anymore. r=ahunt, a=ritu MozReview-Commit-ID: 2s1H61s305Z
mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
@@ -20,30 +20,42 @@ public class HistoryDividerItemDecoratio
         mDividerPaint = new Paint();
         mDividerPaint.setColor(ContextCompat.getColor(context, R.color.toolbar_divider_grey));
         mDividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
     }
 
     @Override
     public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
         final int position = parent.getChildAdapterPosition(view);
+        if (position == RecyclerView.NO_POSITION) {
+            // This view is no longer corresponds to an adapter position (pending changes).
+            return;
+        }
+
         if (parent.getAdapter().getItemViewType(position) !=
                 CombinedHistoryItem.ItemType.itemTypeToViewType(CombinedHistoryItem.ItemType.SECTION_HEADER)) {
             outRect.set(0, 0, 0, mDividerHeight);
         }
     }
 
     @Override
     public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
         if (parent.getChildCount() == 0) {
             return;
         }
+
         for (int i = 0; i < parent.getChildCount(); i++) {
             final View child = parent.getChildAt(i);
             final int position = parent.getChildAdapterPosition(child);
+
+            if (position == RecyclerView.NO_POSITION) {
+                // This view is no longer corresponds to an adapter position (pending changes).
+                continue;
+            }
+
             if (parent.getAdapter().getItemViewType(position) !=
                     CombinedHistoryItem.ItemType.itemTypeToViewType(CombinedHistoryItem.ItemType.SECTION_HEADER)) {
                 final float bottom = child.getBottom() + child.getTranslationY();
                 c.drawRect(0, bottom, parent.getWidth(), bottom + mDividerHeight, mDividerPaint);
             }
         }
     }
 }