diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 3e980b3e9ad..80c001df52b 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -516,7 +516,7 @@ abstract public class BrowserApp extends GeckoApp } private void showTabs(TabsPanel.Panel panel) { - if (Tabs.getInstance().getDisplayCount() == 0) + if (Tabs.getInstance().getCount() == 0) return; mTabsPanel.show(panel); diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index f48139db71b..ae9218f3281 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -401,7 +401,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, } break; case RESTORED: - updateTabCount(Tabs.getInstance().getDisplayCount()); + updateTabCount(Tabs.getInstance().getCount()); break; case SELECTED: mAnimateSiteSecurity = false; @@ -415,7 +415,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, break; case CLOSED: case ADDED: - updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount()); + updateTabCountAndAnimate(Tabs.getInstance().getCount()); if (Tabs.getInstance().isSelectedTab(tab)) { updateBackButton(tab.canDoBack()); updateForwardButton(tab.canDoForward()); @@ -1156,7 +1156,7 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory, setSecurityMode(tab.getSecurityMode()); setReaderMode(tab.getReaderEnabled()); setShadowVisibility(true); - updateTabCount(Tabs.getInstance().getDisplayCount()); + updateTabCount(Tabs.getInstance().getCount()); updateBackButton(tab.canDoBack()); updateForwardButton(tab.canDoForward()); diff --git a/mobile/android/base/Tabs.java b/mobile/android/base/Tabs.java index e30fb4f897d..b20211b1fa7 100644 --- a/mobile/android/base/Tabs.java +++ b/mobile/android/base/Tabs.java @@ -99,15 +99,8 @@ public class Tabs implements GeckoEventListener { } } - public int getDisplayCount() { - boolean getPrivate = mSelectedTab != null && mSelectedTab.isPrivate(); - int count = 0; - for (Tab tab : mTabs.values()) { - if (tab.isPrivate() == getPrivate) { - count++; - } - } - return count; + public int getCount() { + return mTabs.size(); } private void lazyRegisterBookmarkObserver() { @@ -175,32 +168,15 @@ public class Tabs implements GeckoEventListener { return tab; } - private int getIndexOf(Tab tab) { + public int getIndexOf(Tab tab) { return mOrder.lastIndexOf(tab); } - private Tab getNextTabFrom(Tab tab, boolean getPrivate) { - int numTabs = mOrder.size(); - int index = getIndexOf(tab); - for (int i = index + 1; i < numTabs; i++) { - Tab next = mOrder.get(i); - if (next.isPrivate() == getPrivate) { - return next; - } - } - return null; - } - - private Tab getPreviousTabFrom(Tab tab, boolean getPrivate) { - int numTabs = mOrder.size(); - int index = getIndexOf(tab); - for (int i = index - 1; i >= 0; i--) { - Tab prev = mOrder.get(i); - if (prev.isPrivate() == getPrivate) { - return prev; - } - } - return null; + public Tab getTabAt(int index) { + if (index >= 0 && index < mOrder.size()) + return mOrder.get(index); + else + return null; } /** @@ -223,7 +199,7 @@ public class Tabs implements GeckoEventListener { } public Tab getTab(int id) { - if (mTabs.size() == 0) + if (getCount() == 0) return null; if (!mTabs.containsKey(id)) @@ -262,15 +238,10 @@ public class Tabs implements GeckoEventListener { if (selectedTab != tab) return selectedTab; - boolean getPrivate = tab.isPrivate(); - Tab nextTab = getNextTabFrom(tab, getPrivate); + int index = getIndexOf(tab); + Tab nextTab = getTabAt(index + 1); if (nextTab == null) - nextTab = getPreviousTabFrom(tab, getPrivate); - if (nextTab == null && getPrivate) { - // If there are no private tabs remaining, get the last normal tab - Tab lastTab = mOrder.get(mOrder.size() - 1); - nextTab = getPreviousTabFrom(lastTab, false); - } + nextTab = getTabAt(index - 1); Tab parent = getTab(tab.getParentId()); if (parent != null) {