Bug 1346004 - Part 4 - Filter non-browsing tabs from the TabsLayout/TabStrip. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sat, 11 Mar 2017 20:48:54 +0100
changeset 502492 52e8d1a0f89ce96b553744c1203e3de5782038f4
parent 502491 2ab97b16955c8f43b5d41582c25b22a81fc1112f
child 502493 038e178277f3d7c16aaf77758c2e2cc4d7ad8490
push id50298
push usermozilla@buttercookie.de
push dateTue, 21 Mar 2017 21:08:11 +0000
reviewerssebastian
bugs1346004
milestone55.0a1
Bug 1346004 - Part 4 - Filter non-browsing tabs from the TabsLayout/TabStrip. r?sebastian Custom tabs etc. shouldn't show up in the main browser activity. MozReview-Commit-ID: 1yrLZP6HJ3e
mobile/android/base/java/org/mozilla/gecko/tabs/TabStrip.java
mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabStrip.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabStrip.java
@@ -19,38 +19,43 @@ import android.view.ViewTreeObserver;
 
 import org.mozilla.gecko.BrowserApp.TabStripInterface;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.widget.themed.ThemedImageButton;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 
+import static org.mozilla.gecko.Tab.TabType;
+
 public class TabStrip extends ThemedLinearLayout
                       implements TabStripInterface {
     private static final String LOGTAG = "GeckoTabStrip";
 
     private final TabStripView tabStripView;
     private final ThemedImageButton addTabButton;
 
     private final TabsListener tabsListener;
     private OnTabAddedOrRemovedListener tabChangedListener;
 
     // True when the tab strip isn't visible to the user due to something being drawn over it.
     private boolean tabStripIsCovered;
     private boolean tabsNeedUpdating;
+    private final TabType type;
 
     public TabStrip(Context context) {
         this(context, null);
     }
 
     public TabStrip(Context context, AttributeSet attrs) {
         super(context, attrs);
         setOrientation(HORIZONTAL);
 
+        type = TabType.BROWSING;
+
         LayoutInflater.from(context).inflate(R.layout.tab_strip_inner, this);
         tabStripView = (TabStripView) findViewById(R.id.tab_strip);
 
         addTabButton = (ThemedImageButton) findViewById(R.id.tablet_add_tab);
         addTabButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 final Tabs tabs = Tabs.getInstance();
@@ -108,16 +113,20 @@ public class TabStrip extends ThemedLine
 
     public void setOnTabChangedListener(OnTabAddedOrRemovedListener listener) {
         tabChangedListener = listener;
     }
 
     private class TabsListener implements Tabs.OnTabsChangedListener {
         @Override
         public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
+            if (msg != Tabs.TabEvents.RESTORED && tab.getType() != type) {
+                return;
+            }
+
             switch (msg) {
                 case RESTORED:
                     tabStripView.restoreTabs();
                     break;
 
                 case ADDED:
                     final int tabIndex = Integer.parseInt(data);
                     tabStripView.addTab(tab, tabIndex);
--- a/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/tabs/TabsLayout.java
@@ -14,34 +14,38 @@ import android.content.Context;
 import android.content.res.TypedArray;
 import android.support.v7.widget.RecyclerView;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.Button;
 
 import java.util.ArrayList;
 
+import static org.mozilla.gecko.Tab.TabType;
+
 public abstract class TabsLayout extends RecyclerView
         implements TabsPanel.TabsLayout,
         Tabs.OnTabsChangedListener,
         RecyclerViewClickSupport.OnItemClickListener,
         TabsTouchHelperCallback.DismissListener,
         TabsTouchHelperCallback.DragListener {
 
     private static final String LOGTAG = "Gecko" + TabsLayout.class.getSimpleName();
 
     private final boolean isPrivate;
+    private final TabType type;
     private TabsPanel tabsPanel;
     private final TabsLayoutAdapter tabsAdapter;
 
     public TabsLayout(Context context, AttributeSet attrs, int itemViewLayoutResId) {
         super(context, attrs);
 
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsLayout);
         isPrivate = (a.getInt(R.styleable.TabsLayout_tabs, 0x0) == 1);
+        type = TabType.BROWSING;
         a.recycle();
 
         tabsAdapter = new TabsLayoutAdapter(context, itemViewLayoutResId, isPrivate,
                 /* close on click listener */
                 new Button.OnClickListener() {
                     @Override
                     public void onClick(View v) {
                         // The view here is the close button, which has a reference
@@ -90,16 +94,20 @@ public abstract class TabsLayout extends
     }
 
     protected void autoHidePanel() {
         tabsPanel.autoHidePanel();
     }
 
     @Override
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, String data) {
+        if (msg != Tabs.TabEvents.RESTORED && tab.getType() != type) {
+            return;
+        }
+
         switch (msg) {
             case ADDED:
                 final int tabIndex = Integer.parseInt(data);
                 tabsAdapter.notifyTabInserted(tab, tabIndex);
                 if (addAtIndexRequiresScroll(tabIndex)) {
                     // (The SELECTED tab is updated *after* this call to ADDED, so don't just call
                     // updateSelectedPosition().)
                     scrollToPosition(tabIndex);
@@ -168,17 +176,17 @@ public abstract class TabsLayout extends
 
     private void refreshTabsData() {
         // Store a different copy of the tabs, so that we don't have to worry about
         // accidentally updating it on the wrong thread.
         final ArrayList<Tab> tabData = new ArrayList<>();
         final Iterable<Tab> allTabs = Tabs.getInstance().getTabsInOrder();
 
         for (final Tab tab : allTabs) {
-            if (tab.isPrivate() == isPrivate) {
+            if (tab.isPrivate() == isPrivate && tab.getType() == type) {
                 tabData.add(tab);
             }
         }
 
         tabsAdapter.setTabs(tabData);
         updateSelectedPosition();
     }