From 002aad00e59ef1686e4a7ea643bc2c43ad5564b1 Mon Sep 17 00:00:00 2001 From: Daron Walters Date: Mon, 15 Jun 2020 07:40:39 -0400 Subject: [PATCH] Fixes #2960 - Updated code to increase number/index of the last row item that would display menu below item instead of on top (#3499) --- .../ui/views/library/DownloadsView.java | 26 +++++++++---------- .../ui/views/library/HistoryView.java | 16 ++++++------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/DownloadsView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/DownloadsView.java index 6bb30446c..c1d8308a3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/DownloadsView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/DownloadsView.java @@ -78,7 +78,7 @@ protected void initialize() { mDownloadsManager = ((VRBrowserActivity) getContext()).getServicesProvider().getDownloadsManager(); mViewModel = new ViewModelProvider( - (VRBrowserActivity)getContext(), + (VRBrowserActivity) getContext(), ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication())) .get(DownloadsViewModel.class); @@ -95,7 +95,7 @@ public void updateUI() { // Inflate this data binding layout mBinding = DataBindingUtil.inflate(inflater, R.layout.downloads, this, true); - mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); + mBinding.setLifecycleOwner((VRBrowserActivity) getContext()); mBinding.setCallback(mDownloadsCallback); mBinding.setDownloadsViewModel(mViewModel); mDownloadsAdapter = new DownloadsAdapter(mDownloadItemCallback, getContext()); @@ -180,8 +180,8 @@ public void onMore(@NonNull View view, @NonNull Download item) { LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.downloadsList.getLayoutManager(); int lastItem = mDownloadsAdapter.getItemCount(); if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() || - rowPosition == layoutManager.findLastVisibleItemPosition()-1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition()-1) - && rowPosition != lastItem) { + rowPosition == layoutManager.findLastVisibleItemPosition() - 1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() - 1) + && ((rowPosition == (lastItem - 1)) && rowPosition > 2)) { isLastVisibleItem = true; } } @@ -252,7 +252,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto @Override protected void updateLayout() { post(() -> { - double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density); + double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density); boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; if (isNarrow != mViewModel.getIsNarrow().getValue().get()) { @@ -329,8 +329,8 @@ protected void showSortingContextMenu(@NonNull View view) { PointF position = new PointF( (offsetViewBounds.left + view.getWidth()) * ratio, -(offsetViewBounds.top + view.getHeight()) * ratio); - menu.getPlacement().translationX = position.x - (menu.getWidth()/menu.getPlacement().density); - menu.getPlacement().translationY = position.y + getResources().getDimension(R.dimen.library_menu_top_margin)/menu.getPlacement().density; + menu.getPlacement().translationX = position.x - (menu.getWidth() / menu.getPlacement().density); + menu.getPlacement().translationY = position.y + getResources().getDimension(R.dimen.library_menu_top_margin) / menu.getPlacement().density; menu.show(UIWidget.REQUEST_FOCUS); } @@ -355,12 +355,12 @@ private Comparator getSorting(@SortingContextMenuWidget.Order int orde // DownloadsManager.DownloadsListener - private Comparator mDownloadIdComparator = (o1, o2) -> (int)(o1.getId() - o2.getId()); + private Comparator mDownloadIdComparator = (o1, o2) -> (int) (o1.getId() - o2.getId()); private Comparator mAZFileNameComparator = (o1, o2) -> { int nameDiff = o1.getFilename().compareTo(o2.getFilename()); if (nameDiff == 0) { - return mDownloadIdComparator.compare(o1, o2); + return mDownloadIdComparator.compare(o1, o2); } else { return nameDiff; @@ -369,7 +369,7 @@ private Comparator getSorting(@SortingContextMenuWidget.Order int orde private Comparator mZAFilenameComparator = (o1, o2) -> { int nameDiff = o2.getFilename().compareTo(o1.getFilename()); if (nameDiff == 0) { - return mDownloadIdComparator.compare(o1, o2); + return mDownloadIdComparator.compare(o1, o2); } else { return nameDiff; @@ -378,16 +378,16 @@ private Comparator getSorting(@SortingContextMenuWidget.Order int orde private Comparator mDownloadDateAscComparator = (o1, o2) -> mDownloadIdComparator.compare(o1, o2); private Comparator mDownloadDateDescComparator = (o1, o2) -> mDownloadIdComparator.compare(o2, o1); private Comparator mDownloadSizeAscComparator = (o1, o2) -> { - int sizeDiff = (int)(o1.getSizeBytes() - o2.getSizeBytes()); + int sizeDiff = (int) (o1.getSizeBytes() - o2.getSizeBytes()); if (sizeDiff == 0) { - return mDownloadIdComparator.compare(o1, o2); + return mDownloadIdComparator.compare(o1, o2); } else { return sizeDiff; } }; private Comparator mDownloadSizeDescComparator = (o1, o2) -> { - int sizeDiff = (int)(o2.getSizeBytes() - o1.getSizeBytes()); + int sizeDiff = (int) (o2.getSizeBytes() - o1.getSizeBytes()); if (sizeDiff == 0) { return mDownloadIdComparator.compare(o1, o2); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/HistoryView.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/HistoryView.java index 2c50da42c..e4de81be6 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/HistoryView.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/library/HistoryView.java @@ -96,14 +96,14 @@ public HistoryView(Context aContext, AttributeSet aAttrs, int aDefStyle) { protected void initialize() { super.initialize(); - mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts(); + mAccounts = ((VRBrowserApplication) getContext().getApplicationContext()).getAccounts(); if (ACCOUNTS_UI_ENABLED) { mAccounts.addAccountListener(mAccountListener); mAccounts.addSyncListener(mSyncListener); } mViewModel = new ViewModelProvider( - (VRBrowserActivity)getContext(), + (VRBrowserActivity) getContext(), ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication())) .get(HistoryViewModel.class); @@ -120,7 +120,7 @@ public void updateUI() { // Inflate this data binding layout mBinding = DataBindingUtil.inflate(inflater, R.layout.history, this, true); - mBinding.setLifecycleOwner((VRBrowserActivity)getContext()); + mBinding.setLifecycleOwner((VRBrowserActivity) getContext()); mBinding.setHistoryViewModel(mViewModel); mBinding.setCallback(mHistoryCallback); mHistoryAdapter = new HistoryAdapter(mHistoryItemCallback, getContext()); @@ -203,8 +203,8 @@ public void onMore(View view, VisitInfo item) { LinearLayoutManager layoutManager = (LinearLayoutManager) mBinding.historyList.getLayoutManager(); int lastItem = mHistoryAdapter.getItemCount(); if ((rowPosition == layoutManager.findLastVisibleItemPosition() || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() || - rowPosition == layoutManager.findLastVisibleItemPosition()-1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition()-1) - && (rowPosition != lastItem && rowPosition != 1)) { + rowPosition == layoutManager.findLastVisibleItemPosition() - 1 || rowPosition == layoutManager.findLastCompletelyVisibleItemPosition() - 1) + && (rowPosition != lastItem && rowPosition > 2)) { isLastVisibleItem = true; } } @@ -372,7 +372,7 @@ private void updateHistory() { SessionStore.get().getHistoryStore().getDetailedHistory().thenAcceptAsync((items) -> { List orderedItems = items.stream() .sorted(Comparator.comparing(VisitInfo::getVisitTime) - .reversed()) + .reversed()) .filter(distinctByUrl(VisitInfo::getUrl)) .collect(Collectors.toList()); @@ -391,7 +391,7 @@ private void updateHistory() { } private void addSection(final @NonNull List items, @NonNull String section, long rangeStart, long rangeEnd) { - for (int i=0; i< items.size(); i++) { + for (int i = 0; i < items.size(); i++) { if (items.get(i).getVisitTime() == rangeStart && items.get(i).getVisitType() == VisitType.NOT_A_VISIT) break; @@ -424,7 +424,7 @@ private void showHistory(List historyItems) { @Override protected void updateLayout() { post(() -> { - double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density); + double width = Math.ceil(getWidth() / getContext().getResources().getDisplayMetrics().density); boolean isNarrow = width < SettingsStore.WINDOW_WIDTH_DEFAULT; if (isNarrow != mViewModel.getIsNarrow().getValue().get()) {