@@ -96,6 +96,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
96
96
private boolean _isDPadPressed ;
97
97
private boolean _isDoingIntro ;
98
98
private boolean _isAuthenticating ;
99
+ private boolean _isArchiveEnabled ;
99
100
100
101
private String _submittedSearchQuery ;
101
102
private String _pendingSearchQuery ;
@@ -187,6 +188,7 @@ protected void onCreate(Bundle savedInstanceState) {
187
188
_isDPadPressed = false ;
188
189
_isDoingIntro = false ;
189
190
_isAuthenticating = false ;
191
+ _isArchiveEnabled = false ;
190
192
if (savedInstanceState != null ) {
191
193
_isRecreated = true ;
192
194
_pendingSearchQuery = savedInstanceState .getString ("pendingSearchQuery" );
@@ -249,7 +251,6 @@ protected void onCreate(Bundle savedInstanceState) {
249
251
250
252
public void setGroups (Collection <VaultGroup > groups ) {
251
253
_groups = groups ;
252
- _groupChip .setVisibility (_groups .isEmpty () ? View .GONE : View .VISIBLE );
253
254
254
255
if (_prefGroupFilter != null ) {
255
256
Set <UUID > groupFilter = cleanGroupFilter (_prefGroupFilter );
@@ -273,13 +274,17 @@ public void setGroups(Collection<VaultGroup> groups) {
273
274
private void initializeGroups () {
274
275
_groupChip .removeAllViews ();
275
276
277
+ addArchiveChip (_groupChip );
278
+
276
279
for (VaultGroup group : _groups ) {
277
280
addChipTo (_groupChip , new VaultGroupModel (group ));
278
281
}
279
282
280
- GroupPlaceholderType placeholderType = GroupPlaceholderType .NO_GROUP ;
281
- addChipTo (_groupChip , new VaultGroupModel (this , placeholderType ));
282
- addSaveChip (_groupChip );
283
+ if (!_groups .isEmpty ()) {
284
+ GroupPlaceholderType placeholderType = GroupPlaceholderType .NO_GROUP ;
285
+ addChipTo (_groupChip , new VaultGroupModel (this , placeholderType ));
286
+ addSaveChip (_groupChip );
287
+ }
283
288
}
284
289
285
290
private Set <UUID > cleanGroupFilter (Set <UUID > groupFilter ) {
@@ -290,6 +295,21 @@ private Set<UUID> cleanGroupFilter(Set<UUID> groupFilter) {
290
295
.collect (Collectors .toSet ());
291
296
}
292
297
298
+ private void addArchiveChip (ChipGroup chipGroup ) {
299
+ Chip chip = (Chip ) getLayoutInflater ().inflate (R .layout .chip_group_filter , null , false );
300
+ chip .setText (getString (R .string .archive ));
301
+ chip .setCheckedIconVisible (false );
302
+ chip .setOnCheckedChangeListener ((button , isChecked ) -> {
303
+ _isArchiveEnabled = isChecked ;
304
+ if (_actionMode != null ) {
305
+ _actionMode .finish ();
306
+ }
307
+ chip .setChecked (isChecked );
308
+ _entryListView .enableArchive (isChecked );
309
+ });
310
+ chipGroup .addView (chip );
311
+ }
312
+
293
313
private void addChipTo (ChipGroup chipGroup , VaultGroupModel group ) {
294
314
Chip chip = (Chip ) getLayoutInflater ().inflate (R .layout .chip_group_filter , null , false );
295
315
chip .setText (group .getName ());
@@ -1153,6 +1173,7 @@ public void onEntryClick(VaultEntry entry) {
1153
1173
} else {
1154
1174
setFavoriteMenuItemVisiblity ();
1155
1175
setIsMultipleSelected (_selectedEntries .size () > 1 );
1176
+ setRestoreMenuItemVisibility ();
1156
1177
}
1157
1178
}
1158
1179
}
@@ -1195,6 +1216,11 @@ private void setFavoriteMenuItemVisiblity() {
1195
1216
}
1196
1217
}
1197
1218
1219
+ private void setRestoreMenuItemVisibility () {
1220
+ MenuItem restoreMenuItem = _actionMode .getMenu ().findItem (R .id .action_restore );
1221
+ restoreMenuItem .setVisible (_isArchiveEnabled );
1222
+ }
1223
+
1198
1224
@ Override
1199
1225
public void onLongEntryClick (VaultEntry entry ) {
1200
1226
if (!_selectedEntries .isEmpty ()) {
@@ -1211,6 +1237,7 @@ private void startActionMode() {
1211
1237
_actionModeBackPressHandler .setEnabled (true );
1212
1238
setFavoriteMenuItemVisiblity ();
1213
1239
setAssignIconsMenuItemVisibility ();
1240
+ setRestoreMenuItemVisibility ();
1214
1241
}
1215
1242
1216
1243
@ Override
@@ -1298,6 +1325,40 @@ private void copyEntryCode(VaultEntry entry) {
1298
1325
}
1299
1326
}
1300
1327
1328
+ private void onActionRestore (ActionMode mode ) {
1329
+ for (VaultEntry entry : _selectedEntries ) {
1330
+ entry .setIsArchived (false );
1331
+ }
1332
+ saveAndBackupVault ();
1333
+ _entryListView .setGroups (_vaultManager .getVault ().getUsedGroups ());
1334
+ _entryListView .setEntries (_vaultManager .getVault ().getEntries ());
1335
+ mode .finish ();
1336
+ }
1337
+
1338
+ private void onActionDelete (ActionMode mode ) {
1339
+ if (_isArchiveEnabled ) {
1340
+ Dialogs .showDeleteEntriesDialog (MainActivity .this , _selectedEntries , (d , which ) -> {
1341
+ for (VaultEntry entry : _selectedEntries ) {
1342
+ _vaultManager .getVault ().removeEntry (entry );
1343
+ }
1344
+ saveAndBackupVault ();
1345
+ _entryListView .setGroups (_vaultManager .getVault ().getUsedGroups ());
1346
+ _entryListView .setEntries (_vaultManager .getVault ().getEntries ());
1347
+ mode .finish ();
1348
+ });
1349
+ } else {
1350
+ Dialogs .showArchiveEntriesDialog (MainActivity .this , _selectedEntries .size (), (dialog , which ) -> {
1351
+ for (VaultEntry entry : _selectedEntries ) {
1352
+ entry .setIsArchived (true );
1353
+ }
1354
+ saveAndBackupVault ();
1355
+ _entryListView .setGroups (_vaultManager .getVault ().getUsedGroups ());
1356
+ _entryListView .setEntries (_vaultManager .getVault ().getEntries ());
1357
+ mode .finish ();
1358
+ });
1359
+ }
1360
+ }
1361
+
1301
1362
private class SearchViewBackPressHandler extends OnBackPressedCallback {
1302
1363
public SearchViewBackPressHandler () {
1303
1364
super (false );
@@ -1394,16 +1455,10 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
1394
1455
startActivity (intent );
1395
1456
1396
1457
mode .finish ();
1458
+ } else if (itemId == R .id .action_restore ) {
1459
+ onActionRestore (mode );
1397
1460
} else if (itemId == R .id .action_delete ) {
1398
- Dialogs .showDeleteEntriesDialog (MainActivity .this , _selectedEntries , (d , which ) -> {
1399
- for (VaultEntry entry : _selectedEntries ) {
1400
- _vaultManager .getVault ().removeEntry (entry );
1401
- }
1402
- saveAndBackupVault ();
1403
- _entryListView .setGroups (_vaultManager .getVault ().getUsedGroups ());
1404
- _entryListView .setEntries (_vaultManager .getVault ().getEntries ());
1405
- mode .finish ();
1406
- });
1461
+ onActionDelete (mode );
1407
1462
} else if (itemId == R .id .action_select_all ) {
1408
1463
_selectedEntries = _entryListView .selectAllEntries ();
1409
1464
setFavoriteMenuItemVisiblity ();
0 commit comments