Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fixes #2960 - Updated code to increase number/index of the last row i… #3499

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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());
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -355,12 +355,12 @@ private Comparator<Download> getSorting(@SortingContextMenuWidget.Order int orde

// DownloadsManager.DownloadsListener

private Comparator<Download> mDownloadIdComparator = (o1, o2) -> (int)(o1.getId() - o2.getId());
private Comparator<Download> mDownloadIdComparator = (o1, o2) -> (int) (o1.getId() - o2.getId());

private Comparator<Download> 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;
Expand All @@ -369,7 +369,7 @@ private Comparator<Download> getSorting(@SortingContextMenuWidget.Order int orde
private Comparator<Download> 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;
Expand All @@ -378,16 +378,16 @@ private Comparator<Download> getSorting(@SortingContextMenuWidget.Order int orde
private Comparator<Download> mDownloadDateAscComparator = (o1, o2) -> mDownloadIdComparator.compare(o1, o2);
private Comparator<Download> mDownloadDateDescComparator = (o1, o2) -> mDownloadIdComparator.compare(o2, o1);
private Comparator<Download> 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<Download> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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());
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -372,7 +372,7 @@ private void updateHistory() {
SessionStore.get().getHistoryStore().getDetailedHistory().thenAcceptAsync((items) -> {
List<VisitInfo> orderedItems = items.stream()
.sorted(Comparator.comparing(VisitInfo::getVisitTime)
.reversed())
.reversed())
.filter(distinctByUrl(VisitInfo::getUrl))
.collect(Collectors.toList());

Expand All @@ -391,7 +391,7 @@ private void updateHistory() {
}

private void addSection(final @NonNull List<VisitInfo> 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;

Expand Down Expand Up @@ -424,7 +424,7 @@ private void showHistory(List<VisitInfo> 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()) {
Expand Down