|
|
@ -19,6 +19,7 @@ import com.beemdevelopment.aegis.Preferences;
|
|
|
|
import com.beemdevelopment.aegis.SortCategory;
|
|
|
|
import com.beemdevelopment.aegis.SortCategory;
|
|
|
|
import com.beemdevelopment.aegis.ViewMode;
|
|
|
|
import com.beemdevelopment.aegis.ViewMode;
|
|
|
|
import com.beemdevelopment.aegis.helpers.ItemTouchHelperAdapter;
|
|
|
|
import com.beemdevelopment.aegis.helpers.ItemTouchHelperAdapter;
|
|
|
|
|
|
|
|
import com.beemdevelopment.aegis.helpers.comparators.FavoriteComparator;
|
|
|
|
import com.beemdevelopment.aegis.otp.HotpInfo;
|
|
|
|
import com.beemdevelopment.aegis.otp.HotpInfo;
|
|
|
|
import com.beemdevelopment.aegis.otp.OtpInfo;
|
|
|
|
import com.beemdevelopment.aegis.otp.OtpInfo;
|
|
|
|
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
|
|
|
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
|
|
@ -41,6 +42,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
private List<VaultEntry> _shownEntries;
|
|
|
|
private List<VaultEntry> _shownEntries;
|
|
|
|
private List<VaultEntry> _selectedEntries;
|
|
|
|
private List<VaultEntry> _selectedEntries;
|
|
|
|
private Map<UUID, Integer> _usageCounts;
|
|
|
|
private Map<UUID, Integer> _usageCounts;
|
|
|
|
|
|
|
|
private List<UUID> _favorites;
|
|
|
|
private VaultEntry _focusedEntry;
|
|
|
|
private VaultEntry _focusedEntry;
|
|
|
|
private Preferences.CodeGrouping _codeGroupSize;
|
|
|
|
private Preferences.CodeGrouping _codeGroupSize;
|
|
|
|
private boolean _showAccountName;
|
|
|
|
private boolean _showAccountName;
|
|
|
@ -111,6 +113,17 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
_pauseFocused = pauseFocused;
|
|
|
|
_pauseFocused = pauseFocused;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void toggleFavoriteState(VaultEntry entry) {
|
|
|
|
|
|
|
|
if (_favorites.contains(entry.getUUID())) {
|
|
|
|
|
|
|
|
_favorites.remove(entry.getUUID());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
_favorites.add(entry.getUUID());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entry.setIsFavorited(_favorites.contains(entry.getUUID()));
|
|
|
|
|
|
|
|
updateShownEntries();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public VaultEntry getEntryAt(int position) {
|
|
|
|
public VaultEntry getEntryAt(int position) {
|
|
|
|
return _shownEntries.get(position);
|
|
|
|
return _shownEntries.get(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -126,7 +139,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
if (comparator != null) {
|
|
|
|
if (comparator != null) {
|
|
|
|
// insert the entry in the correct order
|
|
|
|
// insert the entry in the correct order
|
|
|
|
// note: this assumes that _shownEntries has already been sorted
|
|
|
|
// note: this assumes that _shownEntries has already been sorted
|
|
|
|
for (int i = 0; i < _shownEntries.size(); i++) {
|
|
|
|
for (int i = _favorites.size(); i < _shownEntries.size(); i++) {
|
|
|
|
if (comparator.compare(_shownEntries.get(i), entry) > 0) {
|
|
|
|
if (comparator.compare(_shownEntries.get(i), entry) > 0) {
|
|
|
|
_shownEntries.add(i, entry);
|
|
|
|
_shownEntries.add(i, entry);
|
|
|
|
notifyItemInserted(i);
|
|
|
|
notifyItemInserted(i);
|
|
|
@ -156,6 +169,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
public void addEntries(Collection<VaultEntry> entries) {
|
|
|
|
public void addEntries(Collection<VaultEntry> entries) {
|
|
|
|
for (VaultEntry entry: entries) {
|
|
|
|
for (VaultEntry entry: entries) {
|
|
|
|
entry.setUsageCount(_usageCounts.containsKey(entry.getUUID()) ? _usageCounts.get(entry.getUUID()) : 0);
|
|
|
|
entry.setUsageCount(_usageCounts.containsKey(entry.getUUID()) ? _usageCounts.get(entry.getUUID()) : 0);
|
|
|
|
|
|
|
|
entry.setIsFavorited(_favorites.contains(entry.getUUID()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_entries.addAll(entries);
|
|
|
|
_entries.addAll(entries);
|
|
|
@ -166,6 +180,10 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
public void removeEntry(VaultEntry entry) {
|
|
|
|
public void removeEntry(VaultEntry entry) {
|
|
|
|
_entries.remove(entry);
|
|
|
|
_entries.remove(entry);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_favorites.contains(entry.getUUID())) {
|
|
|
|
|
|
|
|
removeFavorite(entry);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_shownEntries.contains(entry)) {
|
|
|
|
if (_shownEntries.contains(entry)) {
|
|
|
|
int position = _shownEntries.indexOf(entry);
|
|
|
|
int position = _shownEntries.indexOf(entry);
|
|
|
|
_shownEntries.remove(position);
|
|
|
|
_shownEntries.remove(position);
|
|
|
@ -303,6 +321,9 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
Collections.sort(_shownEntries, comparator);
|
|
|
|
Collections.sort(_shownEntries, comparator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Comparator<VaultEntry> favoriteComparator = new FavoriteComparator();
|
|
|
|
|
|
|
|
Collections.sort(_shownEntries, favoriteComparator);
|
|
|
|
|
|
|
|
|
|
|
|
_view.onListChange();
|
|
|
|
_view.onListChange();
|
|
|
|
notifyDataSetChanged();
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -315,6 +336,21 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
|
|
|
|
|
|
|
|
public Map<UUID, Integer> getUsageCounts() { return _usageCounts; }
|
|
|
|
public Map<UUID, Integer> getUsageCounts() { return _usageCounts; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setFavorites(List<UUID> favorites) { _favorites = favorites; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<UUID> getFavorites() { return _favorites; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void removeFavorite(VaultEntry entry) {
|
|
|
|
|
|
|
|
int position = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < _favorites.size(); i++) {
|
|
|
|
|
|
|
|
if (_favorites.get(i).equals(entry.getUUID())) {
|
|
|
|
|
|
|
|
position = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_favorites.remove(position);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGroups(TreeSet<String> groups) {
|
|
|
|
public void setGroups(TreeSet<String> groups) {
|
|
|
|
_view.setGroups(groups);
|
|
|
|
_view.setGroups(groups);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -449,7 +485,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
|
|
|
|
|
|
|
|
boolean dragEnabled = _selectedEntries.size() == 0
|
|
|
|
boolean dragEnabled = _selectedEntries.size() == 0
|
|
|
|
|| _selectedEntries.size() == 1 && _selectedEntries.get(0) == entryHolder.getEntry();
|
|
|
|
|| _selectedEntries.size() == 1 && _selectedEntries.get(0) == entryHolder.getEntry();
|
|
|
|
if (dragEnabled && isDragAndDropAllowed()) {
|
|
|
|
if (dragEnabled && isDragAndDropAllowed() && !entryHolder.getEntry().getIsFavorited()) {
|
|
|
|
_view.startDrag(_dragHandleHolder);
|
|
|
|
_view.startDrag(_dragHandleHolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -463,7 +499,8 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_MOVE
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_MOVE
|
|
|
|
&& _selectedEntries.size() == 1
|
|
|
|
&& _selectedEntries.size() == 1
|
|
|
|
&& _selectedEntries.get(0) == entryHolder.getEntry()
|
|
|
|
&& _selectedEntries.get(0) == entryHolder.getEntry()
|
|
|
|
&& isDragAndDropAllowed()) {
|
|
|
|
&& isDragAndDropAllowed()
|
|
|
|
|
|
|
|
&& !entryHolder.getEntry().getIsFavorited()) {
|
|
|
|
_view.startDrag(_dragHandleHolder);
|
|
|
|
_view.startDrag(_dragHandleHolder);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -607,7 +644,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_selectedEntries.size() == 1 && _dragHandleHolder == null) {
|
|
|
|
if (_selectedEntries.size() == 1 && _dragHandleHolder == null && !_selectedEntries.get(0).getIsFavorited()) {
|
|
|
|
// Find and enable dragging for the single selected EntryHolder
|
|
|
|
// Find and enable dragging for the single selected EntryHolder
|
|
|
|
// Not nice but this is the best method I could find
|
|
|
|
// Not nice but this is the best method I could find
|
|
|
|
for (int i = 0; i < _holders.size(); i++) {
|
|
|
|
for (int i = 0; i < _holders.size(); i++) {
|
|
|
|