Browse Source

Fixed bug where new intents wouldn't open in the browser if it had been killed by the OS

master
Anthony Restaino 9 years ago
parent
commit
486078a7d1
  1. 1
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 27
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 51
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

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

@ -549,7 +549,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private void initializePreferences() { private void initializePreferences() {
final LightningView currentView = mTabsManager.getCurrentTab(); final LightningView currentView = mTabsManager.getCurrentTab();
final WebView currentWebView = mTabsManager.getCurrentWebView();
mFullScreen = mPreferences.getFullScreenEnabled(); mFullScreen = mPreferences.getFullScreenEnabled();
boolean colorMode = mPreferences.getColorModeEnabled(); boolean colorMode = mPreferences.getColorModeEnabled();
colorMode &= !mDarkTheme; colorMode &= !mDarkTheme;

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

@ -64,6 +64,24 @@ public class TabsManager {
mTabNumberListener = listener; mTabNumberListener = listener;
} }
private boolean mIsInitialized = false;
private List<Runnable> mPostInitializationWorkList = new ArrayList<>();
public void doAfterInitialization(@NonNull Runnable runnable) {
if (mIsInitialized) {
runnable.run();
} else {
mPostInitializationWorkList.add(runnable);
}
}
private void finishInitialization() {
mIsInitialized = true;
for (Runnable runnable : mPostInitializationWorkList) {
runnable.run();
}
}
/** /**
* 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.
@ -79,10 +97,12 @@ public class TabsManager {
@Override @Override
public void onSubscribe(@NonNull final Subscriber<Void> subscriber) { public void onSubscribe(@NonNull final Subscriber<Void> subscriber) {
// Make sure we start with a clean tab list
shutdown();
// If incognito, only create one tab, do not handle intent // If incognito, only create one tab, do not handle intent
// in order to protect user privacy // in order to protect user privacy
if (incognito && mTabList.isEmpty()) { if (incognito) {
newTab(activity, null, true); newTab(activity, null, true);
subscriber.onComplete(); subscriber.onComplete();
return; return;
@ -93,10 +113,12 @@ public class TabsManager {
dataString = intent.getDataString(); dataString = intent.getDataString();
} }
final String url = dataString; final String url = dataString;
mTabList.clear();
mCurrentTab = null; mCurrentTab = null;
if (mPreferenceManager.getRestoreLostTabsEnabled()) { if (mPreferenceManager.getRestoreLostTabsEnabled()) {
restoreLostTabs(url, activity, subscriber); restoreLostTabs(url, activity, subscriber);
} else {
newTab(activity, null, false);
finishInitialization();
} }
} }
@ -138,6 +160,7 @@ public class TabsManager {
if (mTabList.size() == 0) { if (mTabList.size() == 0) {
newTab(activity, null, false); newTab(activity, null, false);
} }
finishInitialization();
subscriber.onComplete(); subscriber.onComplete();
} }
}); });

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

@ -169,33 +169,38 @@ public class BrowserPresenter {
Log.d(Constants.TAG, "deleted tab"); Log.d(Constants.TAG, "deleted tab");
} }
public void onNewIntent(Intent intent) { public void onNewIntent(final Intent intent) {
final String url; mTabsModel.doAfterInitialization(new Runnable() {
if (intent != null) { @Override
url = intent.getDataString(); public void run() {
} else { final String url;
url = null; if (intent != null) {
} url = intent.getDataString();
int num = 0; } else {
if (intent != null && intent.getExtras() != null) { url = null;
num = intent.getExtras().getInt(Constants.INTENT_ORIGIN); }
} int num = 0;
if (intent != null && intent.getExtras() != null) {
num = intent.getExtras().getInt(Constants.INTENT_ORIGIN);
}
if (num == 1) { if (num == 1) {
loadUrlInCurrentView(url); loadUrlInCurrentView(url);
} else if (url != null) { } else if (url != null) {
if (url.startsWith(Constants.FILE)) { if (url.startsWith(Constants.FILE)) {
mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() { mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
newTab(url, true);
}
});
} else {
newTab(url, true); newTab(url, true);
} }
}); mIsNewIntent = true;
} else { }
newTab(url, true);
} }
mIsNewIntent = true; });
}
} }
public void loadUrlInCurrentView(final String url) { public void loadUrlInCurrentView(final String url) {

Loading…
Cancel
Save