Bug 1337947 - Fix tab strip divider drawing for RTL. r=maliu, a=gchang
authorTom Klein <twointofive@gmail.com>
Fri, 07 Apr 2017 00:50:24 -0500
changeset 395875 6430228451e7fb677722a743b9a998ca188f7b43
parent 395874 2fb6cb8d0267a84cc4ad68ff6b0c5c62b4cbf7e2
child 395876 30801f76e945300a891b36408b9ee2fd113b18f6
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaliu, gchang
bugs1337947
milestone54.0a2
Bug 1337947 - Fix tab strip divider drawing for RTL. r=maliu, a=gchang MozReview-Commit-ID: LITy483QhlW
mobile/android/base/java/org/mozilla/gecko/tabs/TabStripDividerItem.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripDividerItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStripDividerItem.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko.tabs;
 import org.mozilla.gecko.R;
 
 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.support.v7.widget.ViewUtils;
 import android.view.View;
 
 class TabStripDividerItem extends RecyclerView.ItemDecoration {
     private final int margin;
     private final int dividerWidth;
     private final int dividerHeight;
     private final int dividerPaddingBottom;
     private final Paint dividerPaint;
@@ -33,31 +34,35 @@ class TabStripDividerItem extends Recycl
         dividerPaint.setStyle(Paint.Style.FILL_AND_STROKE);
     }
 
     /**
      * Return whether a divider should be drawn on the left side of the tab represented by
      * {@code view}.
      */
     private static boolean drawLeftDividerForView(View view, RecyclerView parent) {
+        final boolean isLTR = !ViewUtils.isLayoutRtl(parent);
         final int position = parent.getChildAdapterPosition(view);
-        // No left divider if this is tab 0 or this tab is currently pressed.
-        if (position == 0 || view.isPressed()) {
+        // No left divider if this is the leftmost tab or this tab is currently pressed.
+        final boolean isLeftmostTab = isLTR ? position == 0 : position == parent.getAdapter().getItemCount() - 1;
+        if (isLeftmostTab || view.isPressed()) {
             return false;
         }
 
         final int selectedPosition = ((TabStripView) parent).getPositionForSelectedTab();
-        // No left divider if this tab or the previous tab is the current selected tab.
+        // No left divider if this tab or the tab to its left is the current selected tab.
+        final int positionToTheRightOfSelectedTab = isLTR ? selectedPosition + 1 : selectedPosition - 1;
         if (selectedPosition != RecyclerView.NO_POSITION &&
-                (position == selectedPosition || position == selectedPosition + 1)) {
+                (position == selectedPosition || position == positionToTheRightOfSelectedTab)) {
             return false;
         }
 
-        final RecyclerView.ViewHolder holder = parent.findViewHolderForAdapterPosition(position - 1);
-        // No left divider if the previous tab is currently pressed.
+        // No left divider if the tab to the left is currently pressed.
+        final int positionToTheLeft = isLTR ? position - 1 : position + 1;
+        final RecyclerView.ViewHolder holder = parent.findViewHolderForAdapterPosition(positionToTheLeft);
         if (holder != null && holder.itemView.isPressed()) {
             return false;
         }
 
         return true;
     }
 
     @Override