Skip to content

Commit

Permalink
Fixes #2250 Fixes #2431 Library panels polishing (#2657)
Browse files Browse the repository at this point in the history
* Improve the way we show/hide the context menu

* Avoid hiding the context menu for the last row
  • Loading branch information
keianhzo committed Feb 5, 2020
1 parent e84c0fb commit b73b391
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
Expand Up @@ -109,11 +109,7 @@ public void updateUI() {
mBinding.setCallback(mBookmarksCallback);
mBookmarkAdapter = new BookmarkAdapter(mBookmarkItemCallback, getContext());
mBinding.bookmarksList.setAdapter(mBookmarkAdapter);
mBinding.bookmarksList.setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
});
mBinding.bookmarksList.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> mBookmarksViewListeners.forEach((listener) -> listener.onHideContextMenu(v)));
mBinding.bookmarksList.addOnScrollListener(mScrollListener);
mBinding.bookmarksList.setHasFixedSize(true);
mBinding.bookmarksList.setItemViewCacheSize(20);
mBinding.bookmarksList.setDrawingCacheEnabled(true);
Expand Down Expand Up @@ -151,12 +147,25 @@ public void onShow() {
public void onDestroy() {
SessionStore.get().getBookmarkStore().removeListener(this);

mBinding.bookmarksList.removeOnScrollListener(mScrollListener);

if (ACCOUNTS_UI_ENABLED) {
mAccounts.removeAccountListener(mAccountListener);
mAccounts.removeSyncListener(mSyncListener);
}
}

private RecyclerView.OnScrollListener mScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_SETTLING) {
recyclerView.requestFocus();
}
}
};

private final BookmarkItemCallback mBookmarkItemCallback = new BookmarkItemCallback() {
@Override
public void onClick(@NonNull View view, @NonNull Bookmark item) {
Expand Down Expand Up @@ -184,8 +193,10 @@ public void onMore(@NonNull View view, @NonNull Bookmark item) {
boolean isLastVisibleItem = false;
if (mBinding.bookmarksList.getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.bookmarksList.getLayoutManager();
int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
if (rowPosition == layoutManager.findLastVisibleItemPosition() && rowPosition != lastVisibleItem) {
int lastItem = mBookmarkAdapter.getItemCount();
if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() ||
rowPosition == layoutManager.findLastVisibleItemPosition()-1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition()-1)
&& rowPosition != lastItem) {
isLastVisibleItem = true;
}
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;

import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
Expand Down Expand Up @@ -113,11 +114,7 @@ public void updateUI() {
mBinding.setCallback(mHistoryCallback);
mHistoryAdapter = new HistoryAdapter(mHistoryItemCallback, getContext());
mBinding.historyList.setAdapter(mHistoryAdapter);
mBinding.historyList.setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
});
mBinding.historyList.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> mHistoryViewListeners.forEach((listener) -> listener.onHideContextMenu(v)));
mBinding.historyList.addOnScrollListener(mScrollListener);
mBinding.historyList.setHasFixedSize(true);
mBinding.historyList.setItemViewCacheSize(20);
mBinding.historyList.setDrawingCacheEnabled(true);
Expand Down Expand Up @@ -149,6 +146,8 @@ public void updateUI() {
public void onDestroy() {
SessionStore.get().getHistoryStore().removeListener(this);

mBinding.historyList.removeOnScrollListener(mScrollListener);

if (ACCOUNTS_UI_ENABLED) {
mAccounts.removeAccountListener(mAccountListener);
mAccounts.removeSyncListener(mSyncListener);
Expand All @@ -159,6 +158,17 @@ public void onShow() {
updateLayout();
}

private OnScrollListener mScrollListener = new OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);

if (recyclerView.getScrollState() != RecyclerView.SCROLL_STATE_SETTLING) {
recyclerView.requestFocus();
}
}
};

private final HistoryItemCallback mHistoryItemCallback = new HistoryItemCallback() {
@Override
public void onClick(View view, VisitInfo item) {
Expand Down Expand Up @@ -186,8 +196,10 @@ public void onMore(View view, VisitInfo item) {
boolean isLastVisibleItem = false;
if (mBinding.historyList.getLayoutManager() instanceof LinearLayoutManager) {
LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.historyList.getLayoutManager();
int lastVisibleItem = layoutManager.findLastCompletelyVisibleItemPosition();
if (rowPosition == layoutManager.findLastVisibleItemPosition() && rowPosition != lastVisibleItem) {
int lastItem = mHistoryAdapter.getItemCount();
if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() ||
rowPosition == layoutManager.findLastVisibleItemPosition()-1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition()-1)
&& rowPosition != lastItem) {
isLastVisibleItem = true;
}
}
Expand Down
Expand Up @@ -1081,7 +1081,7 @@ public void onUnstackSession(Session aSession, Session aParent) {
public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
Log.d(LOGTAG, "BrowserWidget onCreateInputConnection");
GeckoSession session = mSession.getGeckoSession();
if (session == null) {
if (session == null || mView != null) {
return null;
}
return session.getTextInput().onCreateInputConnection(outAttrs);
Expand Down

0 comments on commit b73b391

Please sign in to comment.