Fixed bug where bookmarks as homepage changes what bookmarks are shown in bookmark drawer

This commit is contained in:
Anthony Restaino 2016-03-24 21:06:04 -04:00
parent 4d400f995f
commit cabea7e097
2 changed files with 32 additions and 2 deletions

View File

@ -114,7 +114,7 @@ public final class BookmarkPage extends AsyncTask<Void, Void, Void> {
}
private void buildBookmarkPage(@Nullable final String folder, @NonNull final BookmarkManager manager) {
final List<HistoryItem> list = manager.getBookmarksFromFolder(folder, true);
final List<HistoryItem> list = manager.getBookmarksCopyFromFolder(folder, true);
final File bookmarkWebPage;
if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(mFilesDir, FILENAME);

View File

@ -387,7 +387,7 @@ public class BookmarkManager {
*/
@NonNull
public synchronized List<HistoryItem> getBookmarksFromFolder(@Nullable String folder, boolean sort) {
List<HistoryItem> bookmarks = new ArrayList<>();
List<HistoryItem> 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.
* <p/>
* 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<HistoryItem> getBookmarksCopyFromFolder(@Nullable String folder, boolean sort) {
List<HistoryItem> 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
*