From cabea7e0972c94a0293aaa4e904793d70063ebbb Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Thu, 24 Mar 2016 21:06:04 -0400 Subject: [PATCH] Fixed bug where bookmarks as homepage changes what bookmarks are shown in bookmark drawer --- .../lightning/constant/BookmarkPage.java | 2 +- .../lightning/database/BookmarkManager.java | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) 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 91030da..6e4a02a 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -114,7 +114,7 @@ public final class BookmarkPage extends AsyncTask { } private void buildBookmarkPage(@Nullable final String folder, @NonNull final BookmarkManager manager) { - final List list = manager.getBookmarksFromFolder(folder, true); + final List list = manager.getBookmarksCopyFromFolder(folder, true); final File bookmarkWebPage; if (folder == null || folder.isEmpty()) { bookmarkWebPage = new File(mFilesDir, FILENAME); diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java index e06dd8a..60e6178 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java @@ -387,7 +387,7 @@ public class BookmarkManager { */ @NonNull public synchronized List getBookmarksFromFolder(@Nullable String folder, boolean sort) { - List bookmarks = new ArrayList<>(); + List bookmarks = new ArrayList<>(1); if (folder == null || folder.isEmpty()) { bookmarks.addAll(getFolders(sort)); folder = ""; @@ -403,6 +403,36 @@ public class BookmarkManager { return bookmarks; } + /** + * Different from {@link #getBookmarksFromFolder(String, boolean)} only in + * that it doesn't affect the internal state of the bookmark manager which + * tracks the current folder used by the bookmark drawer. + *

+ * This method returns a list of bookmarks and folders located in the specified folder. + * This method should generally be used by the UI when it needs a list to display to the + * user as it returns a subset of all bookmarks and includes folders as well which are + * really 'fake' bookmarks. + * + * @param folder the name of the folder to retrieve bookmarks from + * @return a list of bookmarks found in that folder + */ + @NonNull + public synchronized List getBookmarksCopyFromFolder(@Nullable String folder, boolean sort) { + List bookmarks = new ArrayList<>(1); + if (folder == null || folder.isEmpty()) { + bookmarks.addAll(getFolders(sort)); + folder = ""; + } + for (HistoryItem item : mBookmarksMap.values()) { + if (item.getFolder().equals(folder)) + bookmarks.add(item); + } + if (sort) { + Collections.sort(bookmarks, new SortIgnoreCase()); + } + return bookmarks; + } + /** * Tells you if you are at the root folder or in a subfolder *