Browse Source

moved the deleting logic to TabsManager

master
Ravjit Singh Uppal 9 years ago
parent
commit
006eb5e191
  1. 56
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 29
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java

56
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -816,8 +816,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -816,8 +816,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
*/
private synchronized void showTab(final int position) {
final LightningView currentView = mTabsManager.getCurrentTab();
final WebView currentWebView = currentView != null ? currentView.getWebView() : null;
final LightningView newView = mTabsManager.switchToTab(position);
switchTabs(currentView, newView);
}
// This is commodity to breack the flow between regular tab management and the CLIQZ's search
// interface.
private void switchTabs(final LightningView currentView, final LightningView newView) {
final WebView currentWebView = currentView != null ? currentView.getWebView() : null;
final WebView newWebView = newView != null ? newView.getWebView() : null;
if (newView == null || newWebView == null) {
return;
@ -1000,14 +1006,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1000,14 +1006,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private synchronized void deleteTab(int position) {
final LightningView tabToDelete = mTabsManager.getTabAtPosition(position);
final LightningView currentTab = mTabsManager.getCurrentTab();
if (tabToDelete == null) {
return;
}
int current = mTabsManager.positionOf(currentTab);
if (!UrlUtils.isSpecialUrl(tabToDelete.getUrl()) && !isIncognito()) {
mPreferences.setSavedUrl(tabToDelete.getUrl());
}
@ -1016,37 +1019,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1016,37 +1019,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
if (isShown) {
mBrowserFrame.setBackgroundColor(mBackgroundColor);
}
if (current > position) {
mTabsManager.deleteTab(position);
mEventBus.post(new BrowserEvents.TabsChanged());
} else if (mTabsManager.size() > position + 1) {
if (current == position) {
showTab(position + 1);
mTabsManager.deleteTab(position);
mEventBus.post(new BrowserEvents.TabsChanged());
} else {
mTabsManager.deleteTab(position);
}
} else if (mTabsManager.size() > 1) {
if (current == position) {
showTab(position - 1);
mTabsManager.deleteTab(position);
mEventBus.post(new BrowserEvents.TabsChanged());
} else {
mTabsManager.deleteTab(position);
}
} else {
if (currentTab != null && (UrlUtils.isSpecialUrl(currentTab.getUrl())
|| currentTab.getUrl().equals(mHomepage))) {
closeActivity();
} else {
mTabsManager.deleteTab(position);
performExitCleanUp();
tabToDelete.pauseTimers();
mEventBus.post(new BrowserEvents.TabsChanged());
finish();
}
final LightningView currentTab = mTabsManager.getCurrentTab();
mTabsManager.deleteTab(position);
final LightningView afterTab = mTabsManager.getCurrentTab();
if (afterTab == null) {
// if (currentTab != null && (UrlUtils.isSpecialUrl(currentTab.getUrl())
// || currentTab.getUrl().equals(mPreferenceManager.getHomepage()))) {
// closeActivity();
// } else {
performExitCleanUp();
finish();
// }
} else if (afterTab != currentTab) {
switchTabs(currentTab, afterTab);
currentTab.pauseTimers();
}
mEventBus.post(new BrowserEvents.TabsChanged());
if (shouldClose) {

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

@ -9,6 +9,8 @@ import android.support.v7.app.AlertDialog; @@ -9,6 +9,8 @@ import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.webkit.WebView;
import com.squareup.otto.Bus;
import java.util.ArrayList;
import java.util.List;
@ -16,8 +18,10 @@ import javax.inject.Inject; @@ -16,8 +18,10 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import acr.browser.lightning.R;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.UrlUtils;
import acr.browser.lightning.utils.Utils;
import acr.browser.lightning.view.LightningView;
@ -35,6 +39,9 @@ public class TabsManager { @@ -35,6 +39,9 @@ public class TabsManager {
@Inject
PreferenceManager mPreferenceManager;
@Inject
Bus mEventBus;
@Inject
public TabsManager() {}
@ -182,7 +189,7 @@ public class TabsManager { @@ -182,7 +189,7 @@ public class TabsManager {
* @return The removed tab reference or null
*/
@Nullable
public synchronized LightningView deleteTab(final int position) {
public synchronized LightningView removeTab(final int position) {
if (position >= mWebViewList.size()) {
return null;
}
@ -191,9 +198,29 @@ public class TabsManager { @@ -191,9 +198,29 @@ public class TabsManager {
mCurrentTab = null;
}
tab.onDestroy();
Log.d(Constants.TAG, tab.toString());
return tab;
}
public synchronized void deleteTab(int position) {
final LightningView currentTab = getCurrentTab();
int current = positionOf(currentTab);
if (current == position) {
if (size() == 1) {
mCurrentTab = null;
} else if (current < size() - 1 ) {
// There is another tab after this one
mCurrentTab = getTabAtPosition(current + 1);
} else {
mCurrentTab = getTabAtPosition(current - 1);
}
removeTab(current);
} else {
removeTab(position);
}
}
/**
* Return the position of the given tab.
*

Loading…
Cancel
Save