Skip to content

Commit

Permalink
Update the navigation bar bookmarked flag when bookmarks are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Feb 20, 2020
1 parent 1480654 commit 4fd4f0c
Showing 1 changed file with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.VRBrowserActivity;
import org.mozilla.vrbrowser.VRBrowserApplication;
import org.mozilla.vrbrowser.browser.BookmarksStore;
import org.mozilla.vrbrowser.browser.Media;
import org.mozilla.vrbrowser.browser.PromptDelegate;
import org.mozilla.vrbrowser.browser.SessionChangeListener;
Expand Down Expand Up @@ -173,11 +174,13 @@ private void initialize(Context aContext) {
setupListeners(mSession);

mBookmarksView = new BookmarksView(aContext);
mBookmarksView.addBookmarksListener(mBookmarksListener);
mBookmarksView.addBookmarksListener(mBookmarksViewListener);

mHistoryView = new HistoryView(aContext);
mHistoryView.addHistoryListener(mHistoryListener);

SessionStore.get().getBookmarkStore().addListener(mBookmarksListener);

mHandle = ((WidgetManagerDelegate)aContext).newWidgetHandle();
mWidgetPlacement = new WidgetPlacement(aContext);
mPlacementBeforeFullscreen = new WidgetPlacement(aContext);
Expand Down Expand Up @@ -622,6 +625,8 @@ public void setActiveWindow(boolean active) {
session.getTextInput().setView(this);
}
mSession.updateLastUse();

updateBookmarked();
}

hideContextMenus();
Expand Down Expand Up @@ -913,8 +918,9 @@ public void releaseWidget() {
mTexture.release();
mTexture = null;
}
mBookmarksView.removeBookmarksListener(mBookmarksListener);
mBookmarksView.removeBookmarksListener(mBookmarksViewListener);
mHistoryView.removeHistoryListener(mHistoryListener);
SessionStore.get().getBookmarkStore().removeListener(mBookmarksListener);
mPromptDelegate.detachFromWindow();
super.releaseWidget();
}
Expand Down Expand Up @@ -1343,7 +1349,7 @@ public void onRemoveFromBookmarks(LibraryMenuWidget.LibraryContextMenuItem item)
});
}

private BookmarksCallback mBookmarksListener = new BookmarksCallback() {
private BookmarksCallback mBookmarksViewListener = new BookmarksCallback() {
@Override
public void onShowContextMenu(@NonNull View view, @NonNull Bookmark item, boolean isLastVisibleItem) {
showLibraryItemContextMenu(
Expand Down Expand Up @@ -1415,6 +1421,33 @@ public void onClickItem(@NonNull View view, @NonNull VisitInfo item) {
}
};

private BookmarksStore.BookmarkListener mBookmarksListener = new BookmarksStore.BookmarkListener() {
@Override
public void onBookmarksUpdated() {
updateBookmarked();
}

@Override
public void onBookmarkAdded() {
updateBookmarked();
}
};

private void updateBookmarked() {
SessionStore.get().getBookmarkStore().isBookmarked(mViewModel.getUrl().getValue().toString()).thenAcceptAsync(bookmarked -> {
if (bookmarked) {
mViewModel.setIsBookmarked(true);

} else {
mViewModel.setIsBookmarked(false);
}
}, mUIThreadExecutor).exceptionally(throwable -> {
Log.d(LOGTAG, "Error checking bookmark: " + throwable.getLocalizedMessage());
throwable.printStackTrace();
return null;
});
}

private void hideContextMenus() {
if (mContextMenu != null) {
if (!mContextMenu.isReleased()) {
Expand Down

0 comments on commit 4fd4f0c

Please sign in to comment.