Browse Source

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

master
anthony restaino 7 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 @@ @@ -1,6 +1,7 @@
package acr.browser.lightning.browser;
import android.app.Activity;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.NonNull;
@ -17,7 +18,9 @@ import acr.browser.lightning.BuildConfig; @@ -17,7 +18,9 @@ import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.TabsManager;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.preference.PreferenceManager;
@ -34,6 +37,7 @@ public class BrowserPresenter { @@ -34,6 +37,7 @@ public class BrowserPresenter {
private static final String TAG = "BrowserPresenter";
@NonNull private final TabsManager mTabsModel;
@Inject Application mApplication;
@Inject PreferenceManager mPreferences;
@NonNull private final BrowserView mView;
@ -144,6 +148,19 @@ public class BrowserPresenter { @@ -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.
*
@ -166,8 +183,8 @@ public class BrowserPresenter { @@ -166,8 +183,8 @@ public class BrowserPresenter {
boolean shouldClose = mShouldClose && isShown && tabToDelete.isNewTab();
final LightningView currentTab = mTabsModel.getCurrentTab();
if (mTabsModel.size() == 1 && currentTab != null &&
(UrlUtils.isStartPageUrl(currentTab.getUrl()) ||
currentTab.getUrl().equals(mPreferences.getHomepage()))) {
URLUtil.isFileUrl(currentTab.getUrl()) &&
currentTab.getUrl().equals(mapHomepageToCurrentUrl())) {
mView.closeActivity();
return;
} else {

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

@ -81,7 +81,7 @@ public final class BookmarkPage { @@ -81,7 +81,7 @@ public final class BookmarkPage {
private static final String DEFAULT_ICON = "default.png";
@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 + '-' : "";
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 { @@ -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>";
@NonNull
private static File getStartPageFile(@NonNull Application application) {
public static File getStartPageFile(@NonNull Application application) {
return new File(application.getFilesDir(), FILENAME);
}

Loading…
Cancel
Save