Bug 1122074 - Normal Tabs tray has an empty state. r=mcomella, a=sledru
authorMartyn Haigh <martyn.haigh@gmail.com>
Fri, 23 Jan 2015 16:01:15 +0000
changeset 243019 c1e9f11144a5
parent 243018 17830430e6be
child 243020 d6baa06d52b4
push id4364
push userryanvm@gmail.com
push date2015-01-24 16:33 +0000
treeherdermozilla-beta@34330baf2af6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, sledru
bugs1122074
milestone36.0
Bug 1122074 - Normal Tabs tray has an empty state. r=mcomella, a=sledru
mobile/android/base/tabs/TabsGridLayout.java
--- a/mobile/android/base/tabs/TabsGridLayout.java
+++ b/mobile/android/base/tabs/TabsGridLayout.java
@@ -216,26 +216,43 @@ class TabsGridLayout extends GridView
     public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
         switch (msg) {
             case ADDED:
                 // Refresh the list to make sure the new tab is added in the right position.
                 refreshTabsData();
                 break;
 
             case CLOSED:
-                if(mTabsAdapter.getCount() > 0) {
+                if (mTabsAdapter.getCount() > 0) {
                     animateRemoveTab(tab);
                 }
-               if (tab.isPrivate() == mIsPrivate && mTabsAdapter.getCount() > 0) {
-                   if (mTabsAdapter.removeTab(tab)) {
-                       int selected = mTabsAdapter.getPositionForTab(Tabs.getInstance().getSelectedTab());
-                       updateSelectedStyle(selected);
-                   }
-               }
-               break;
+
+                final Tabs tabsInstance = Tabs.getInstance();
+
+                if (mTabsAdapter.removeTab(tab)) {
+                    if (tab.isPrivate() == mIsPrivate && mTabsAdapter.getCount() > 0) {
+                        int selected = mTabsAdapter.getPositionForTab(tabsInstance.getSelectedTab());
+                        updateSelectedStyle(selected);
+                    }
+                    if(!tab.isPrivate()) {
+                        // Make sure we always have at least one normal tab
+                        final Iterable<Tab> tabs = tabsInstance.getTabsInOrder();
+                        boolean removedTabIsLastNormalTab = true;
+                        for (Tab singleTab : tabs) {
+                            if (!singleTab.isPrivate()) {
+                                removedTabIsLastNormalTab = false;
+                                break;
+                            }
+                        }
+                        if (removedTabIsLastNormalTab) {
+                            tabsInstance.addTab();
+                        }
+                    }
+                }
+                break;
 
             case SELECTED:
                 // Update the selected position, then fall through...
                 updateSelectedPosition();
             case UNSELECTED:
                 // We just need to update the style for the unselected tab...
             case THUMBNAIL:
             case TITLE: