Bug 1253654 - Part 2 - Don't show the item divider in the history panel after a section header. r=liuche draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 14 Jul 2016 20:57:43 +0200
changeset 387730 e8b78e9fc9e5cc6d582272d7d28adf2ad0839b77
parent 387729 f3be6dad91262f6d5e37900f01c9825f485a4955
child 525438 d15e746d492ee886b3cbd844d5c15803cb22e6b4
push id23058
push usermozilla@buttercookie.de
push dateThu, 14 Jul 2016 19:25:41 +0000
reviewersliuche
bugs1253654
milestone50.0a1
Bug 1253654 - Part 2 - Don't show the item divider in the history panel after a section header. r=liuche That way, the section headers (e.g. "Today", "Yesterday", "Last 7 days" etc.) blend better with the following item. The correct hiding of the divider depends on the view type reported for the respective RecylerView child items. Because the view type is stored a simple number, this means that any other RecylerView wanting to use this divider decoration implementation must use the same item types as the history panel in order to remain compatible, otherwise the divider could be unexpectedly hidden. Therefore, we rename the DividerItemDecoration to underline its intended usage scope. MozReview-Commit-ID: 8JUS6ke3RBL
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
mobile/android/base/java/org/mozilla/gecko/widget/DividerItemDecoration.java
mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
mobile/android/base/moz.build
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryPanel.java
@@ -46,17 +46,17 @@ import org.mozilla.gecko.fxa.FxAccountCo
 import org.mozilla.gecko.fxa.SyncStatusListener;
 import org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.RemoteClient;
 import org.mozilla.gecko.restrictions.Restrictable;
-import org.mozilla.gecko.widget.DividerItemDecoration;
+import org.mozilla.gecko.widget.HistoryDividerItemDecoration;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
 public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsDialogFragment.RemoteClientsListener {
     private static final String LOGTAG = "GeckoCombinedHistoryPnl";
 
@@ -166,17 +166,17 @@ public class CombinedHistoryPanel extend
 
         final RecyclerView.ItemAnimator animator = new DefaultItemAnimator();
         animator.setAddDuration(100);
         animator.setChangeDuration(100);
         animator.setMoveDuration(100);
         animator.setRemoveDuration(100);
         mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
         mRecyclerView.setItemAnimator(animator);
-        mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
+        mRecyclerView.addItemDecoration(new HistoryDividerItemDecoration(getContext()));
         mRecyclerView.setOnHistoryClickedListener(mUrlOpenListener);
         mRecyclerView.setOnPanelLevelChangeListener(new OnLevelChangeListener());
         mRecyclerView.setHiddenClientsDialogBuilder(new HiddenClientsHelper());
         mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                 super.onScrolled(recyclerView, dx, dy);
                 final LinearLayoutManager llm = (LinearLayoutManager) recyclerView.getLayoutManager();
rename from mobile/android/base/java/org/mozilla/gecko/widget/DividerItemDecoration.java
rename to mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DividerItemDecoration.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/HistoryDividerItemDecoration.java
@@ -3,38 +3,47 @@ package org.mozilla.gecko.widget;
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Rect;
 import android.support.v4.content.ContextCompat;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 import org.mozilla.gecko.R;
+import org.mozilla.gecko.home.CombinedHistoryItem;
 
-public class DividerItemDecoration extends RecyclerView.ItemDecoration {
+public class HistoryDividerItemDecoration extends RecyclerView.ItemDecoration {
     private final int mDividerHeight;
     private final Paint mDividerPaint;
 
-    public DividerItemDecoration(Context context) {
+    public HistoryDividerItemDecoration(Context context) {
         mDividerHeight = (int) context.getResources().getDimension(R.dimen.page_row_divider_height);
 
         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) {
-        outRect.set(0, 0, 0, mDividerHeight);
+        final int position = parent.getChildAdapterPosition(view);
+        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 float bottom = child.getBottom() + child.getTranslationY();
-            c.drawRect(0, bottom, parent.getWidth(), bottom + mDividerHeight, mDividerPaint);
+            final int position = parent.getChildAdapterPosition(child);
+            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);
+            }
         }
     }
 }
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -646,28 +646,28 @@ gbjar.sources += ['java/org/mozilla/geck
     'widget/AnimatedHeightLayout.java',
     'widget/BasicColorPicker.java',
     'widget/CheckableLinearLayout.java',
     'widget/ClickableWhenDisabledEditText.java',
     'widget/ContentSecurityDoorHanger.java',
     'widget/CropImageView.java',
     'widget/DateTimePicker.java',
     'widget/DefaultDoorHanger.java',
-    'widget/DividerItemDecoration.java',
     'widget/DoorHanger.java',
     'widget/DoorhangerConfig.java',
     'widget/EllipsisTextView.java',
     'widget/ExternalIntentDuringPrivateBrowsingPromptFragment.java',
     'widget/FadedMultiColorTextView.java',
     'widget/FadedSingleColorTextView.java',
     'widget/FadedTextView.java',
     'widget/FaviconView.java',
     'widget/FlowLayout.java',
     'widget/GeckoActionProvider.java',
     'widget/GeckoPopupMenu.java',
+    'widget/HistoryDividerItemDecoration.java',
     'widget/IconTabWidget.java',
     'widget/LoginDoorHanger.java',
     'widget/RecyclerViewClickSupport.java',
     'widget/ResizablePathDrawable.java',
     'widget/RoundedCornerLayout.java',
     'widget/SiteLogins.java',
     'widget/SquaredImageView.java',
     'widget/SquaredRelativeLayout.java',