Browse Source

Fixing bug where last tab would be destroyed on exit in certain cases

master
anthony restaino 8 years ago
parent
commit
eed6866113
  1. 21
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  2. 2
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  3. 2
      app/src/main/java/acr/browser/lightning/constant/StartPage.java

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

@ -1,6 +1,7 @@
package acr.browser.lightning.browser; package acr.browser.lightning.browser;
import android.app.Activity; import android.app.Activity;
import android.app.Application;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -17,7 +18,9 @@ import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.activity.TabsManager;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
@ -34,6 +37,7 @@ public class BrowserPresenter {
private static final String TAG = "BrowserPresenter"; private static final String TAG = "BrowserPresenter";
@NonNull private final TabsManager mTabsModel; @NonNull private final TabsManager mTabsModel;
@Inject Application mApplication;
@Inject PreferenceManager mPreferences; @Inject PreferenceManager mPreferences;
@NonNull private final BrowserView mView; @NonNull private final BrowserView mView;
@ -144,6 +148,19 @@ public class BrowserPresenter {
} }
@NonNull
private String mapHomepageToCurrentUrl() {
String homepage = mPreferences.getHomepage();
switch (homepage) {
case Constants.SCHEME_HOMEPAGE:
return Constants.FILE + StartPage.getStartPageFile(mApplication);
case Constants.SCHEME_BOOKMARKS:
return Constants.FILE + BookmarkPage.getBookmarkPage(mApplication, null);
default:
return homepage;
}
}
/** /**
* Deletes the tab at the specified position. * Deletes the tab at the specified position.
* *
@ -166,8 +183,8 @@ public class BrowserPresenter {
boolean shouldClose = mShouldClose && isShown && tabToDelete.isNewTab(); boolean shouldClose = mShouldClose && isShown && tabToDelete.isNewTab();
final LightningView currentTab = mTabsModel.getCurrentTab(); final LightningView currentTab = mTabsModel.getCurrentTab();
if (mTabsModel.size() == 1 && currentTab != null && if (mTabsModel.size() == 1 && currentTab != null &&
(UrlUtils.isStartPageUrl(currentTab.getUrl()) || URLUtil.isFileUrl(currentTab.getUrl()) &&
currentTab.getUrl().equals(mPreferences.getHomepage()))) { currentTab.getUrl().equals(mapHomepageToCurrentUrl())) {
mView.closeActivity(); mView.closeActivity();
return; return;
} else { } else {

2
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -81,7 +81,7 @@ public final class BookmarkPage {
private static final String DEFAULT_ICON = "default.png"; private static final String DEFAULT_ICON = "default.png";
@NonNull @NonNull
private static File getBookmarkPage(@NonNull Application application, @Nullable String folder) { public static File getBookmarkPage(@NonNull Application application, @Nullable String folder) {
String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : ""; String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : "";
return new File(application.getFilesDir(), prefix + FILENAME); return new File(application.getFilesDir(), prefix + FILENAME);
} }

2
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -55,7 +55,7 @@ public class StartPage {
private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>"; private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>";
@NonNull @NonNull
private static File getStartPageFile(@NonNull Application application) { public static File getStartPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME); return new File(application.getFilesDir(), FILENAME);
} }

Loading…
Cancel
Save