Bug 1350718 - Post: Name the special value -1 used to indicate a new tab should be appended. r=maliu

MozReview-Commit-ID: 7r8cHItW4wG

--HG--
extra : rebase_source : b7ea5736f706a126f553d6c2eddc314ee4f5f011
This commit is contained in:
Tom Klein 2017-04-06 11:27:42 -05:00
Родитель 69608d9657
Коммит 89477640e6
2 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -81,6 +81,8 @@ public class Tabs implements BundleEventListener {
private static final long PERSIST_TABS_AFTER_MILLISECONDS = 1000 * 2; private static final long PERSIST_TABS_AFTER_MILLISECONDS = 1000 * 2;
public static final int INVALID_TAB_ID = -1; public static final int INVALID_TAB_ID = -1;
// Used to indicate a new tab should be appended to the current tabs.
public static final int NEW_LAST_INDEX = -1;
private static final AtomicInteger sTabId = new AtomicInteger(0); private static final AtomicInteger sTabId = new AtomicInteger(0);
private volatile boolean mInitialTabsAdded; private volatile boolean mInitialTabsAdded;
@ -260,10 +262,17 @@ public class Tabs implements BundleEventListener {
return tab; return tab;
} }
// Return the index, among those tabs of the chosen type whose privacy setting matches /**
// isPrivate, of the tab at position index in mOrder. Returns -1, for "new last tab", * Return the index, among those tabs of the chosen {@code type} whose privacy setting matches
// when index is -1. * {@code isPrivate}, of the tab at position {@code index} in {@code mOrder}. Returns
* {@code NEW_LAST_INDEX} when {@code index} is {@code NEW_LAST_INDEX} or no matches were
* found.
*/
private int getPrivacySpecificTabIndex(int index, boolean isPrivate, TabType type) { private int getPrivacySpecificTabIndex(int index, boolean isPrivate, TabType type) {
if (index == NEW_LAST_INDEX) {
return NEW_LAST_INDEX;
}
int privacySpecificIndex = -1; int privacySpecificIndex = -1;
for (int i = 0; i <= index; i++) { for (int i = 0; i <= index; i++) {
final Tab tab = mOrder.get(i); final Tab tab = mOrder.get(i);
@ -271,7 +280,7 @@ public class Tabs implements BundleEventListener {
privacySpecificIndex++; privacySpecificIndex++;
} }
} }
return privacySpecificIndex; return privacySpecificIndex > -1 ? privacySpecificIndex : NEW_LAST_INDEX;
} }
public synchronized void removeTab(int id) { public synchronized void removeTab(int id) {
@ -1022,7 +1031,7 @@ public class Tabs implements BundleEventListener {
String tabUrl = (url != null && Uri.parse(url).getScheme() != null) ? url : null; String tabUrl = (url != null && Uri.parse(url).getScheme() != null) ? url : null;
// Add the new tab to the end of the tab order. // Add the new tab to the end of the tab order.
final int tabIndex = -1; final int tabIndex = NEW_LAST_INDEX;
tabToSelect = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex, type); tabToSelect = addTab(tabId, tabUrl, external, parentId, url, isPrivate, tabIndex, type);
tabToSelect.setDesktopMode(desktopMode); tabToSelect.setDesktopMode(desktopMode);

Просмотреть файл

@ -106,8 +106,7 @@ public abstract class TabsLayout extends RecyclerView
switch (msg) { switch (msg) {
case ADDED: case ADDED:
int tabIndex = Integer.parseInt(data); int tabIndex = Integer.parseInt(data);
// A tabIndex of -1 means "add a new last tab". tabIndex = tabIndex == Tabs.NEW_LAST_INDEX ? tabsAdapter.getItemCount() : tabIndex;
tabIndex = tabIndex == -1 ? tabsAdapter.getItemCount() : tabIndex;
tabsAdapter.notifyTabInserted(tab, tabIndex); tabsAdapter.notifyTabInserted(tab, tabIndex);
if (addAtIndexRequiresScroll(tabIndex)) { if (addAtIndexRequiresScroll(tabIndex)) {
// (The SELECTED tab is updated *after* this call to ADDED, so don't just call // (The SELECTED tab is updated *after* this call to ADDED, so don't just call