Browse Source

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

master
Anthony Restaino 9 years ago
parent
commit
c9323cc7fd
  1. 20
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  2. 8
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

20
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -45,6 +45,7 @@ public class TabsManager {
private final List<LightningView> mTabList = new ArrayList<>(1); private final List<LightningView> mTabList = new ArrayList<>(1);
@Nullable private LightningView mCurrentTab; @Nullable private LightningView mCurrentTab;
@Nullable private TabNumberChangedListener mTabNumberListener;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@Inject Bus mEventBus; @Inject Bus mEventBus;
@ -53,6 +54,16 @@ public class TabsManager {
@Inject @Inject
public TabsManager() {} 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 * Restores old tabs that were open before the browser
* was closed. Handles the intent used to open the browser. * was closed. Handles the intent used to open the browser.
@ -240,6 +251,9 @@ public class TabsManager {
Log.d(TAG, "New tab"); Log.d(TAG, "New tab");
final LightningView tab = new LightningView(activity, url, isIncognito); final LightningView tab = new LightningView(activity, url, isIncognito);
mTabList.add(tab); mTabList.add(tab);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return tab; return tab;
} }
@ -284,9 +298,15 @@ public class TabsManager {
mCurrentTab = getTabAtPosition(current - 1); mCurrentTab = getTabAtPosition(current - 1);
} }
removeTab(current); removeTab(current);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return true; return true;
} else { } else {
removeTab(position); removeTab(position);
if (mTabNumberListener != null) {
mTabNumberListener.tabNumberChanged(size());
}
return false; return false;
} }
} }

8
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

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

Loading…
Cancel
Save