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
--- 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();
}