Bug 1400950 - Don't draw divider above Highlights title. r?mcomella draft
authorChenxia Liu <liuche@mozilla.com>
Tue, 19 Sep 2017 18:38:16 -0700
changeset 667789 dd2d254beebf4a14c19d5212e8f4525596ecc0b1
parent 667397 83966a788a801e0e79860a7e46d19f4259a3abd9
child 732511 39df560cba2e005932ea7aee997b7c389df9a55b
push id80847
push usercliu@mozilla.com
push dateWed, 20 Sep 2017 18:44:52 +0000
reviewersmcomella
bugs1400950
milestone57.0a1
Bug 1400950 - Don't draw divider above Highlights title. r?mcomella MozReview-Commit-ID: GHXKAhlbc7I
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsDividerItemDecoration.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsDividerItemDecoration.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsDividerItemDecoration.java
@@ -9,20 +9,22 @@ import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 
 /**
- * ItemDecoration implementation that draws horizontal divider line between highlight items.
+ * ItemDecoration implementation that draws horizontal divider line between items
+ * in the AS newtab page.
  */
 /* package */ class HighlightsDividerItemDecoration extends RecyclerView.ItemDecoration {
-    // We do not want to draw a divider for the Top Sites panel.
+
+    // We do not want to draw a divider above the first item.
     private static final int START_DRAWING_AT_POSITION = 1;
 
     private static final int[] ATTRS = new int[]{
             android.R.attr.listDivider
     };
     private Drawable divider;
 
     /* package */ HighlightsDividerItemDecoration(Context context) {
@@ -43,21 +45,28 @@ import android.view.View;
             if (parent.getChildAdapterPosition(child) < START_DRAWING_AT_POSITION) {
                 continue;
             }
 
             if (child.getVisibility() == View.GONE) {
                 continue;
             }
 
+            // Do not draw dividers above section title items.
+            final int childViewType = parent.getAdapter().getItemViewType(i);
+            if (childViewType == StreamRecyclerAdapter.RowItemType.HIGHLIGHTS_TITLE.getViewType()
+                    || childViewType == StreamRecyclerAdapter.RowItemType.TOP_STORIES_TITLE.getViewType()) {
+                continue;
+            }
+
             final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                     .getLayoutParams();
-            final int top = child.getBottom() + params.bottomMargin;
-            final int bottom = top + divider.getIntrinsicHeight();
-            divider.setBounds(left, top, right, bottom);
+            final int topOfDivider = child.getTop() + params.topMargin;
+            final int bottomOfDivider = topOfDivider + divider.getIntrinsicHeight();
+            divider.setBounds(left, topOfDivider, right, bottomOfDivider);
             divider.draw(c);
         }
     }
 
     @Override
     public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
         outRect.set(0, 0, 0, divider.getIntrinsicHeight());
     }