diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index 7c41038..691d742 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -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; 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 { 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 { } + @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 { 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 { diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index 9a78c3f..4742801 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/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"; @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); } diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index d35cd2a..5bb1a63 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/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;}"; @NonNull - private static File getStartPageFile(@NonNull Application application) { + public static File getStartPageFile(@NonNull Application application) { return new File(application.getFilesDir(), FILENAME); }