From 80ac1928c132bfe939f690feba9de4ced0cca3f1 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Thu, 29 Oct 2015 23:35:58 -0400 Subject: [PATCH] Fixed bug where the homepage file url was showing --- .../browser/lightning/activity/BrowserActivity.java | 4 ++-- .../acr/browser/lightning/constant/BookmarkPage.java | 11 ++++++++--- .../acr/browser/lightning/constant/Constants.java | 5 ----- .../acr/browser/lightning/constant/StartPage.java | 2 +- .../lightning/dialog/LightningDialogBuilder.java | 5 +++-- .../java/acr/browser/lightning/utils/UrlUtils.java | 8 ++++++-- .../acr/browser/lightning/view/LightningView.java | 5 +++-- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 5fa828d..9b9b5d7 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -2032,7 +2032,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements public void bookmarkChanged(final BookmarkEvents.BookmarkChanged event) { final LightningView currentTab = tabsManager.getCurrentTab(); if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) - && currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { + && currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) { currentTab.loadBookmarkpage(); } if (currentTab != null) { @@ -2049,7 +2049,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements public void bookmarkDeleted(final BookmarkEvents.Deleted event) { final LightningView currentTab = tabsManager.getCurrentTab(); if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) - && currentTab.getUrl().endsWith(Constants.BOOKMARKS_FILENAME)) { + && currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) { currentTab.loadBookmarkpage(); } if (currentTab != null) { 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 1399d40..d5f6401 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -20,6 +20,11 @@ import acr.browser.lightning.utils.Utils; public final class BookmarkPage { + /** + * The bookmark page standard suffix + */ + public static final String FILENAME = "bookmarks.html"; + private static final String HEADING = "\n" + "\n" + "\n" + @@ -66,9 +71,9 @@ public final class BookmarkPage { final List list = manager.getBookmarksFromFolder(folder, true); final File bookmarkWebPage; if (folder == null || folder.isEmpty()) { - bookmarkWebPage = new File(FILES_DIR, Constants.BOOKMARKS_FILENAME); + bookmarkWebPage = new File(FILES_DIR, FILENAME); } else { - bookmarkWebPage = new File(FILES_DIR, folder + '-' + Constants.BOOKMARKS_FILENAME); + bookmarkWebPage = new File(FILES_DIR, folder + '-' + FILENAME); } final StringBuilder bookmarkBuilder = new StringBuilder(BookmarkPage.HEADING); @@ -77,7 +82,7 @@ public final class BookmarkPage { final HistoryItem item = list.get(n); bookmarkBuilder.append(BookmarkPage.PART1); if (item.isFolder()) { - final File folderPage = new File(FILES_DIR, item.getTitle() + '-' + Constants.BOOKMARKS_FILENAME); + final File folderPage = new File(FILES_DIR, item.getTitle() + '-' + FILENAME); bookmarkBuilder.append(Constants.FILE).append(folderPage); bookmarkBuilder.append(BookmarkPage.PART2); bookmarkBuilder.append(folderIconPath); diff --git a/app/src/main/java/acr/browser/lightning/constant/Constants.java b/app/src/main/java/acr/browser/lightning/constant/Constants.java index 33bc973..46feeec 100644 --- a/app/src/main/java/acr/browser/lightning/constant/Constants.java +++ b/app/src/main/java/acr/browser/lightning/constant/Constants.java @@ -43,11 +43,6 @@ public final class Constants { public static final int PROXY_I2P = 2; public static final int PROXY_MANUAL = 3; - /** - * The bookmark page standard suffix - */ - public static final String BOOKMARKS_FILENAME = "bookmarks.html"; - public static final String DEFAULT_ENCODING = "UTF-8"; public static final String[] TEXT_ENCODINGS = {"ISO-8859-1", "UTF-8", "GBK", "Big5", "ISO-2022-JP", "SHIFT_JS", "EUC-JP", "EUC-KR"}; 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 f640023..b13d426 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -16,7 +16,7 @@ import acr.browser.lightning.utils.Utils; public class StartPage { - private static final String FILENAME = "homepage.html"; + public static final String FILENAME = "homepage.html"; private static final String HEAD = "" + "" diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 93682ba..02c3f8e 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -24,6 +24,7 @@ import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.bus.BookmarkEvents; import acr.browser.lightning.bus.BrowserEvents; +import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.database.BookmarkManager; @@ -60,11 +61,11 @@ public class LightningDialogBuilder { */ public void showLongPressedDialogForBookmarkUrl(final Context context, final String url) { final HistoryItem item; - if (url.startsWith(Constants.FILE) && url.endsWith(Constants.BOOKMARKS_FILENAME)) { + if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) { // TODO hacky, make a better bookmark mechanism in the future final Uri uri = Uri.parse(url); final String filename = uri.getLastPathSegment(); - final String folderTitle = filename.substring(0, filename.length() - Constants.BOOKMARKS_FILENAME.length() - 1); + final String folderTitle = filename.substring(0, filename.length() - BookmarkPage.FILENAME.length() - 1); item = new HistoryItem(); item.setIsFolder(true); item.setTitle(folderTitle); diff --git a/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java b/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java index f45b2d8..06b5c7c 100644 --- a/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/UrlUtils.java @@ -21,8 +21,10 @@ import android.webkit.URLUtil; import java.util.regex.Matcher; import java.util.regex.Pattern; +import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.HistoryPage; +import acr.browser.lightning.constant.StartPage; /** * Utility methods for Url manipulation @@ -153,7 +155,9 @@ public class UrlUtils { * Returns whether the given url is the bookmarks/history page or a normal website */ public static boolean isSpecialUrl(String url) { - return url != null && url.startsWith(Constants.FILE) - && (url.endsWith(Constants.BOOKMARKS_FILENAME) || url.endsWith(HistoryPage.FILENAME)); + return url != null && url.startsWith(Constants.FILE) && + (url.endsWith(BookmarkPage.FILENAME) || + url.endsWith(HistoryPage.FILENAME) || + url.endsWith(StartPage.FILENAME)); } } \ No newline at end of file diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 15e741a..34300ee 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -43,6 +43,7 @@ import javax.inject.Inject; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.bus.BrowserEvents; +import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.StartPage; @@ -167,7 +168,7 @@ public class LightningView { } finally { Utils.close(outputStream); } - File bookmarkWebPage = new File(mActivity.getFilesDir(), Constants.BOOKMARKS_FILENAME); + File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME); BrowserApp.getAppComponent().getBookmarkPage().buildBookmarkPage(null); mWebView.loadUrl(Constants.FILE + bookmarkWebPage); @@ -624,7 +625,7 @@ public class LightningView { final String newUrl = result.getExtra(); mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, newUrl); } - } else if (currentUrl.endsWith(Constants.BOOKMARKS_FILENAME)) { + } else if (currentUrl.endsWith(BookmarkPage.FILENAME)) { if (url != null) { mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, url); } else if (result != null && result.getExtra() != null) {