Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive #1530

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Archive #1530

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 @@ -142,10 +142,20 @@ public void testOverall() {
onView(withId(R.id.action_share_qr)).perform(click());
onView(withId(R.id.btnNext)).perform(click()).perform(click()).perform(click());

onView(withId(R.id.rvKeyProfiles)).perform(RecyclerViewActions.actionOnItemAtPosition(entryPosOffset + 0, longClick()));
onView(withId(R.id.rvKeyProfiles)).perform(RecyclerViewActions.actionOnItemAtPosition(entryPosOffset, longClick()));
onView(withId(R.id.rvKeyProfiles)).perform(RecyclerViewActions.actionOnItemAtPosition(entryPosOffset + 1, click()));
onView(allOf(isDescendantOfA(withClassName(containsString("ActionBarContextView"))), withClassName(containsString("OverflowMenuButton")))).perform(click());
onView(withText(R.string.action_delete)).perform(click());
onView(withId(android.R.id.button1)).perform(click());
onView(withText(R.string.archive)).perform(click());
onView(withId(R.id.rvKeyProfiles)).perform(RecyclerViewActions.actionOnItemAtPosition(entryPosOffset, longClick()));
onView(allOf(isDescendantOfA(withClassName(containsString("ActionBarContextView"))), withClassName(containsString("OverflowMenuButton")))).perform(click());
onView(withText(R.string.action_delete)).perform(click());
onView(withId(android.R.id.button1)).perform(click());
onView(withId(R.id.rvKeyProfiles)).perform(RecyclerViewActions.actionOnItemAtPosition(entryPosOffset, longClick()));
onView(allOf(isDescendantOfA(withClassName(containsString("ActionBarContextView"))), withClassName(containsString("OverflowMenuButton")))).perform(click());
onView(withText(R.string.action_restore)).perform(click());
onView(withText(R.string.archive)).perform(click());

openContextualActionModeOverflowMenu();
onView(withText(R.string.lock)).perform(click());
Expand Down
81 changes: 68 additions & 13 deletions app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
private boolean _isDPadPressed;
private boolean _isDoingIntro;
private boolean _isAuthenticating;
private boolean _isArchiveEnabled;

private String _submittedSearchQuery;
private String _pendingSearchQuery;
Expand Down Expand Up @@ -187,6 +188,7 @@ protected void onCreate(Bundle savedInstanceState) {
_isDPadPressed = false;
_isDoingIntro = false;
_isAuthenticating = false;
_isArchiveEnabled = false;
if (savedInstanceState != null) {
_isRecreated = true;
_pendingSearchQuery = savedInstanceState.getString("pendingSearchQuery");
Expand Down Expand Up @@ -249,7 +251,6 @@ protected void onCreate(Bundle savedInstanceState) {

public void setGroups(Collection<VaultGroup> groups) {
_groups = groups;
_groupChip.setVisibility(_groups.isEmpty() ? View.GONE : View.VISIBLE);

if (_prefGroupFilter != null) {
Set<UUID> groupFilter = cleanGroupFilter(_prefGroupFilter);
Expand All @@ -273,13 +274,17 @@ public void setGroups(Collection<VaultGroup> groups) {
private void initializeGroups() {
_groupChip.removeAllViews();

addArchiveChip(_groupChip);

for (VaultGroup group : _groups) {
addChipTo(_groupChip, new VaultGroupModel(group));
}

GroupPlaceholderType placeholderType = GroupPlaceholderType.NO_GROUP;
addChipTo(_groupChip, new VaultGroupModel(this, placeholderType));
addSaveChip(_groupChip);
if (!_groups.isEmpty()) {
GroupPlaceholderType placeholderType = GroupPlaceholderType.NO_GROUP;
addChipTo(_groupChip, new VaultGroupModel(this, placeholderType));
addSaveChip(_groupChip);
}
}

private Set<UUID> cleanGroupFilter(Set<UUID> groupFilter) {
Expand All @@ -290,6 +295,21 @@ private Set<UUID> cleanGroupFilter(Set<UUID> groupFilter) {
.collect(Collectors.toSet());
}

private void addArchiveChip(ChipGroup chipGroup) {
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.chip_group_filter, null, false);
chip.setText(getString(R.string.archive));
chip.setCheckedIconVisible(false);
chip.setOnCheckedChangeListener((button, isChecked) -> {
_isArchiveEnabled = isChecked;
if (_actionMode != null) {
_actionMode.finish();
}
chip.setChecked(isChecked);
_entryListView.enableArchive(isChecked);
});
chipGroup.addView(chip);
}

private void addChipTo(ChipGroup chipGroup, VaultGroupModel group) {
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.chip_group_filter, null, false);
chip.setText(group.getName());
Expand Down Expand Up @@ -1153,6 +1173,7 @@ public void onEntryClick(VaultEntry entry) {
} else {
setFavoriteMenuItemVisiblity();
setIsMultipleSelected(_selectedEntries.size() > 1);
setRestoreMenuItemVisibility();
}
}
}
Expand Down Expand Up @@ -1195,6 +1216,11 @@ private void setFavoriteMenuItemVisiblity() {
}
}

private void setRestoreMenuItemVisibility() {
MenuItem restoreMenuItem = _actionMode.getMenu().findItem(R.id.action_restore);
restoreMenuItem.setVisible(_isArchiveEnabled);
}

@Override
public void onLongEntryClick(VaultEntry entry) {
if (!_selectedEntries.isEmpty()) {
Expand All @@ -1211,6 +1237,7 @@ private void startActionMode() {
_actionModeBackPressHandler.setEnabled(true);
setFavoriteMenuItemVisiblity();
setAssignIconsMenuItemVisibility();
setRestoreMenuItemVisibility();
}

@Override
Expand Down Expand Up @@ -1298,6 +1325,40 @@ private void copyEntryCode(VaultEntry entry) {
}
}

private void onActionRestore(ActionMode mode) {
for (VaultEntry entry : _selectedEntries) {
entry.setIsArchived(false);
}
saveAndBackupVault();
_entryListView.setGroups(_vaultManager.getVault().getUsedGroups());
_entryListView.setEntries(_vaultManager.getVault().getEntries());
mode.finish();
}

private void onActionDelete(ActionMode mode) {
if (_isArchiveEnabled) {
Dialogs.showDeleteEntriesDialog(MainActivity.this, _selectedEntries, (d, which) -> {
for (VaultEntry entry : _selectedEntries) {
_vaultManager.getVault().removeEntry(entry);
}
saveAndBackupVault();
_entryListView.setGroups(_vaultManager.getVault().getUsedGroups());
_entryListView.setEntries(_vaultManager.getVault().getEntries());
mode.finish();
});
} else {
Dialogs.showArchiveEntriesDialog(MainActivity.this, _selectedEntries.size(), (dialog, which) -> {
for (VaultEntry entry : _selectedEntries) {
entry.setIsArchived(true);
}
saveAndBackupVault();
_entryListView.setGroups(_vaultManager.getVault().getUsedGroups());
_entryListView.setEntries(_vaultManager.getVault().getEntries());
mode.finish();
});
}
}

private class SearchViewBackPressHandler extends OnBackPressedCallback {
public SearchViewBackPressHandler() {
super(false);
Expand Down Expand Up @@ -1394,16 +1455,10 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
startActivity(intent);

mode.finish();
} else if (itemId == R.id.action_restore) {
onActionRestore(mode);
} else if (itemId == R.id.action_delete) {
Dialogs.showDeleteEntriesDialog(MainActivity.this, _selectedEntries, (d, which) -> {
for (VaultEntry entry : _selectedEntries) {
_vaultManager.getVault().removeEntry(entry);
}
saveAndBackupVault();
_entryListView.setGroups(_vaultManager.getVault().getUsedGroups());
_entryListView.setEntries(_vaultManager.getVault().getEntries());
mode.finish();
});
onActionDelete(mode);
} else if (itemId == R.id.action_select_all) {
_selectedEntries = _entryListView.selectAllEntries();
setFavoriteMenuItemVisiblity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ public static void showDeleteEntriesDialog(Context context, List<VaultEntry> ser
.create());
}

public static void showArchiveEntriesDialog(Context context, int count, DialogInterface.OnClickListener onArchive) {
String title = context.getResources().getQuantityString(R.plurals.archive_entry, count);
String message = context.getResources().getQuantityString(R.plurals.archive_entry_description, count);
Dialog dialog = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Aegis_AlertDialog_Warning)
.setTitle(title)
.setMessage(message)
.setIconAttribute(android.R.attr.alertDialogIcon)
.setPositiveButton(android.R.string.ok, onArchive)
.setNegativeButton(android.R.string.no, null)
.create();
showSecureDialog(dialog);
}

private static String getVaultEntryName(Context context, VaultEntry entry) {
if (!entry.getIssuer().isEmpty() && !entry.getName().isEmpty()) {
return String.format("%s (%s)", entry.getIssuer(), entry.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class EntryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private Handler _dimHandler;
private Handler _doubleTapHandler;
private boolean _pauseFocused;
private boolean _isArchiveEnabled;

// keeps track of the EntryHolders that are currently bound
private List<EntryHolder> _holders;
Expand Down Expand Up @@ -196,7 +197,13 @@ private boolean isEntryFiltered(VaultEntry entry) {
String name = entry.getName().toLowerCase();
String note = entry.getNote().toLowerCase();

if (!_groupFilter.isEmpty()) {
if (!_isArchiveEnabled && entry.isArchived()) {
return true;
}

if (_isArchiveEnabled && !entry.isArchived()) {
return true;
} else if (!_groupFilter.isEmpty()) {
if (groups.isEmpty() && !_groupFilter.contains(null)) {
return true;
}
Expand Down Expand Up @@ -774,6 +781,11 @@ public boolean isErrorCardShown() {
return _entryList.isErrorCardShown();
}

public void enableArchive(boolean enable) {
_isArchiveEnabled = enable;
refreshEntryList();
}

private class FooterView extends RecyclerView.ViewHolder {
View _footerView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.ViewGroup;
import android.view.animation.LayoutAnimationController;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -72,6 +73,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
private boolean _showExpirationState;
private ViewMode _viewMode;
private LinearLayout _emptyStateView;
private boolean _isArchiveEnabled;
private TextView _archiveEmptyText;

private UiRefresher _refresher;

Expand Down Expand Up @@ -150,6 +153,7 @@ public long getMillisTillNextRefresh() {
});

_emptyStateView = view.findViewById(R.id.vEmptyList);
_archiveEmptyText = view.findViewById(R.id.archive_empty_text);
return view;
}

Expand Down Expand Up @@ -471,6 +475,12 @@ public void runEntriesAnimation() {
_recyclerView.scheduleLayoutAnimation();
}

public void enableArchive(boolean enable) {
_isArchiveEnabled = enable;
_adapter.enableArchive(enable);
updateEmptyState();
}

private void setShowProgress(boolean showProgress) {
_showProgress = showProgress;
updateDividerDecoration();
Expand All @@ -495,9 +505,12 @@ private void updateEmptyState() {
if (_adapter.getShownEntriesCount() > 0) {
_recyclerView.setVisibility(View.VISIBLE);
_emptyStateView.setVisibility(View.GONE);
} else {
if (Strings.isNullOrEmpty(_adapter.getSearchFilter())) {
_recyclerView.setVisibility(View.GONE);
_archiveEmptyText.setVisibility(View.GONE);
} else if (Strings.isNullOrEmpty(_adapter.getSearchFilter())) {
_recyclerView.setVisibility(View.GONE);
if (_isArchiveEnabled) {
_archiveEmptyText.setVisibility(View.VISIBLE);
} else {
_emptyStateView.setVisibility(View.VISIBLE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class VaultEntry extends UUIDMap.Value {
private String _note = "";
private String _oldGroup;
private Set<UUID> _groups = new TreeSet<>();
private boolean _isArchived;

private VaultEntry(UUID uuid, OtpInfo info) {
super(uuid);
Expand Down Expand Up @@ -66,6 +67,7 @@ public JSONObject toJson() {
groupUuids.put(uuid.toString());
}
obj.put("groups", groupUuids);
obj.put("archived", _isArchived);

} catch (JSONException e) {
throw new RuntimeException(e);
Expand All @@ -90,6 +92,7 @@ public static VaultEntry fromJson(JSONObject obj) throws VaultEntryException {
entry.setIssuer(obj.getString("issuer"));
entry.setNote(obj.optString("note", ""));
entry.setIsFavorite(obj.optBoolean("favorite", false));
entry.setIsArchived(obj.optBoolean("archived", false));

// If the entry contains a list of group UUID's, assume conversion from the
// old group system has already taken place and ignore the old group field.
Expand Down Expand Up @@ -148,6 +151,10 @@ public boolean isFavorite() {
return _isFavorite;
}

public boolean isArchived() {
return _isArchived;
}

public void setName(String name) {
_name = name;
}
Expand Down Expand Up @@ -200,6 +207,10 @@ public void setIsFavorite(boolean isFavorite) {
_isFavorite = isFavorite;
}

public void setIsArchived(boolean isArchived) {
_isArchived = isArchived;
}

void setOldGroup(String oldGroup) {
_oldGroup = oldGroup;
}
Expand Down Expand Up @@ -230,7 +241,8 @@ && getInfo().equals(entry.getInfo())
&& Objects.equals(getIcon(), entry.getIcon())
&& getNote().equals(entry.getNote())
&& isFavorite() == entry.isFavorite()
&& getGroups().equals(entry.getGroups());
&& getGroups().equals(entry.getGroups())
&& isArchived() == entry.isArchived();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ public Collection<VaultGroup> getGroups() {
public Collection<VaultGroup> getUsedGroups() {
Set<UUID> usedGroups = new HashSet<>();
for (VaultEntry entry : getEntries()) {
usedGroups.addAll(entry.getGroups());
if (!entry.isArchived()) {
usedGroups.addAll(entry.getGroups());
}
}

return getGroups().stream()
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/fragment_entry_list_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,13 @@
</LinearLayout>

</LinearLayout>

<TextView
android:id="@+id/archive_empty_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/archive_empty"
android:gravity="center"
android:visibility="gone" />

</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/menu/menu_action_mode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
android:icon="@drawable/ic_outline_qr_code_2_24"
app:showAsAction="always"/>

<item
android:id="@+id/action_restore"
android:title="@string/action_restore"
android:orderInCategory="120"
android:icon="@drawable/ic_outline_refresh_24"
app:showAsAction="ifRoom"/>

<item
android:id="@+id/action_delete"
android:title="@string/action_delete"
Expand Down
Loading