Always take favorites into account when sorting the entry list

This commit is contained in:
Alexander Bakker 2022-11-28 18:13:33 +01:00
parent ef759eb15e
commit 9d318a0d54

View file

@ -208,16 +208,12 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
_shownEntries.set(position, newEntry); _shownEntries.set(position, newEntry);
notifyItemChanged(position); notifyItemChanged(position);
if (_sortCategory != null) { }
Comparator<VaultEntry> comparator = _sortCategory.getComparator();
if (comparator != null) { sortShownEntries();
Collections.sort(_shownEntries, comparator); int newPosition = _shownEntries.indexOf(newEntry);
int newPosition = _shownEntries.indexOf(newEntry); if (position != newPosition) {
if (position != newPosition) { notifyItemMoved(position, newPosition);
notifyItemMoved(position, newPosition);
}
}
}
} }
} else if (!isEntryFiltered(newEntry)) { } else if (!isEntryFiltered(newEntry)) {
_shownEntries.add(newEntry); _shownEntries.add(newEntry);
@ -305,17 +301,21 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} }
// sort the remaining list of entries sortShownEntries();
Comparator<VaultEntry> comparator = _sortCategory.getComparator(); _view.onListChange();
if (comparator != null) { notifyDataSetChanged();
Collections.sort(_shownEntries, comparator); }
private void sortShownEntries() {
if (_sortCategory != null) {
Comparator<VaultEntry> comparator = _sortCategory.getComparator();
if (comparator != null) {
Collections.sort(_shownEntries, comparator);
}
} }
Comparator<VaultEntry> favoriteComparator = new FavoriteComparator(); Comparator<VaultEntry> favoriteComparator = new FavoriteComparator();
Collections.sort(_shownEntries, favoriteComparator); Collections.sort(_shownEntries, favoriteComparator);
_view.onListChange();
notifyDataSetChanged();
} }
public void setViewMode(ViewMode viewMode) { public void setViewMode(ViewMode viewMode) {