Skip to content

Commit

Permalink
Fix item not being set before the menu measure is called (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Sep 4, 2019
1 parent 66a6788 commit be4f30e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
Expand Up @@ -104,7 +104,7 @@ public int itemCount() {

public int getItemPosition(String id) {
for (int position=0; position<mBookmarkList.size(); position++)
if (mBookmarkList.get(position).getGuid() == id)
if (mBookmarkList.get(position).getGuid().equalsIgnoreCase(id))
return position;
return 0;
}
Expand Down
Expand Up @@ -5,6 +5,7 @@

package org.mozilla.vrbrowser.ui.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -53,6 +54,7 @@ public BookmarksView(Context aContext, AttributeSet aAttrs, int aDefStyle) {
initialize(aContext);
}

@SuppressLint("ClickableViewAccessibility")
private void initialize(Context aContext) {
mAudio = AudioEngine.fromContext(aContext);

Expand Down Expand Up @@ -115,7 +117,8 @@ public void onMore(View view, BookmarkNode item) {
boolean isLastVisibleItem = false;
if (mBinding.bookmarksList.getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.bookmarksList.getLayoutManager();
if (rowPosition == layoutManager.findLastVisibleItemPosition()) {
int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
if (rowPosition == layoutManager.findLastVisibleItemPosition() && rowPosition != lastVisibleItem) {
isLastVisibleItem = true;
}
}
Expand Down
Expand Up @@ -121,7 +121,8 @@ public void onMore(View view, VisitInfo item) {
boolean isLastVisibleItem = false;
if (mBinding.historyList.getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.historyList.getLayoutManager();
if (rowPosition == layoutManager.findLastVisibleItemPosition()) {
int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
if (rowPosition == layoutManager.findLastVisibleItemPosition() && rowPosition != lastVisibleItem) {
isLastVisibleItem = true;
}
}
Expand Down
Expand Up @@ -79,8 +79,8 @@ private void initialize(Context aContext) {
}

public void setItem(@NonNull LibraryContextMenuItem item) {
mBinding.setItem(item);
SessionStore.get().getBookmarkStore().isBookmarked(item.getUrl()).thenAccept((isBookmarked -> {
mBinding.setItem(item);
mBinding.setIsBookmarked(isBookmarked);
mBinding.bookmark.setText(isBookmarked ? R.string.history_context_remove_bookmarks : R.string.history_context_add_bookmarks);
invalidate();
Expand All @@ -96,6 +96,10 @@ public void setContextMenuClickCallback(LibraryItemContextMenuClickCallback call
}

public int getMenuHeight() {
if (mBinding.getItem() == null) {
throw new IllegalStateException("setItem must be called before getMenuHeight");

}
switch (mBinding.getItem().getType()) {
case BOOKMARKS:
mBinding.bookmarkLayout.setVisibility(GONE);
Expand Down
Expand Up @@ -1148,6 +1148,7 @@ private void showLibraryItemContextMenu(@NotNull View view, LibraryItemContextMe
offsetDescendantRectToMyCoords(view, offsetViewBounds);

mLibraryItemContextMenu = new LibraryItemContextMenuWidget(getContext());
mLibraryItemContextMenu.setItem(item);
mLibraryItemContextMenu.mWidgetPlacement.parentHandle = getHandle();

PointF position;
Expand All @@ -1165,7 +1166,6 @@ private void showLibraryItemContextMenu(@NotNull View view, LibraryItemContextMe
}

mLibraryItemContextMenu.setPosition(position);
mLibraryItemContextMenu.setItem(item);
mLibraryItemContextMenu.setHistoryContextMenuItemCallback((new LibraryItemContextMenuClickCallback() {
@Override
public void onOpenInNewWindowClick(LibraryItemContextMenu.LibraryContextMenuItem item) {
Expand Down
Expand Up @@ -26,7 +26,6 @@ public class LibraryItemContextMenuWidget extends UIWidget implements WidgetMana
private LibraryItemContextMenu mContextMenu;
private int mMaxHeight;
private PointF mTranslation;
private int height;

public LibraryItemContextMenuWidget(Context aContext) {
super(aContext);
Expand Down

0 comments on commit be4f30e

Please sign in to comment.