Temporarily fix bug where tabs created outside the presenter class (in manager) cause the tab number to be mismatched

This commit is contained in:
Anthony Restaino 2016-02-09 21:10:51 -05:00
parent 2bca40901f
commit c9323cc7fd
2 changed files with 28 additions and 0 deletions

View File

@ -45,6 +45,7 @@ public class TabsManager {
private final List<LightningView> mTabList = new ArrayList<>(1);
@Nullable private LightningView mCurrentTab;
@Nullable private TabNumberChangedListener mTabNumberListener;
@Inject PreferenceManager mPreferenceManager;
@Inject Bus mEventBus;
@ -53,6 +54,16 @@ public class TabsManager {
@Inject
public TabsManager() {}
// TODO remove and make presenter call new tab methods so it always knows
@Deprecated
public interface TabNumberChangedListener {
void tabNumberChanged(int newNumber);
}
public void setTabNumberChangedListener(@Nullable TabNumberChangedListener listener) {
mTabNumberListener = listener;
}
/**
* Restores old tabs that were open before the browser
* was closed. Handles the intent used to open the browser.
@ -240,6 +251,9 @@ public class TabsManager {
Log.d(TAG, "New tab");
final LightningView tab = new LightningView(activity, url, isIncognito);
mTabList.add(tab);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return tab;
}
@ -284,9 +298,15 @@ public class TabsManager {
mCurrentTab = getTabAtPosition(current - 1);
}
removeTab(current);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return true;
} else {
removeTab(position);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return false;
}
}

View File

@ -44,6 +44,12 @@ public class BrowserPresenter {
BrowserApp.getAppComponent().inject(this);
mView = view;
mIsIncognito = isIncognito;
mTabsModel.setTabNumberChangedListener(new TabsManager.TabNumberChangedListener() {
@Override
public void tabNumberChanged(int newNumber) {
mView.updateTabNumber(newNumber);
}
});
}
public void setupTabs(Intent intent, boolean isIncognito) {
@ -214,6 +220,8 @@ public class BrowserPresenter {
return false;
}
Log.d(TAG, "New tab, show: " + show);
mIsNewIntent = false;
LightningView startingTab = mTabsModel.newTab((Activity) mView, url, mIsIncognito);
if (mTabsModel.size() == 1) {