Skip to content

Commit 78ee38b

Browse files
Add ability to multiselect groups
1 parent 920df1d commit 78ee38b

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

app/src/main/java/com/beemdevelopment/aegis/Preferences.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ public boolean isTapToRevealEnabled() {
8686
return _prefs.getBoolean("pref_tap_to_reveal", false);
8787
}
8888

89+
public boolean isGroupMultiselectEnabled() {
90+
return _prefs.getBoolean("pref_groups_multiselect", false);
91+
}
92+
8993
public boolean isEntryHighlightEnabled() {
9094
return _prefs.getBoolean("pref_highlight_entry", false);
9195
}

app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ public void setGroups(Collection<VaultGroup> groups) {
274274

275275
private void initializeGroups() {
276276
_groupChip.removeAllViews();
277+
_groupChip.setSingleSelection(!_prefs.isGroupMultiselectEnabled());
277278

278279
for (VaultGroup group : _groups) {
279280
addChipTo(_groupChip, new VaultGroupModel(group));
@@ -313,29 +314,24 @@ private void addChipTo(ChipGroup chipGroup, VaultGroupModel group) {
313314
}
314315

315316
chip.setOnCheckedChangeListener((group1, isChecked) -> {
316-
Set<UUID> groupFilter = new HashSet<>();
317317
if (_actionMode != null) {
318318
_actionMode.finish();
319319
}
320320

321321
setSaveChipVisibility(true);
322322

323-
if (!isChecked) {
324-
group1.setChecked(false);
323+
// Reset group filter if last checked group gets unchecked
324+
if (!isChecked && _groupFilter.size() == 1) {
325+
Set<UUID> groupFilter = new HashSet<>();
326+
327+
chipGroup.clearCheck();
325328
_groupFilter = groupFilter;
326329
_entryListView.setGroupFilter(groupFilter);
327330
return;
328331
}
329332

330-
Object chipTag = group1.getTag();
331-
if (chipTag == GroupPlaceholderType.NO_GROUP) {
332-
groupFilter.add(null);
333-
} else {
334-
groupFilter = getGroupFilter(chipGroup);
335-
}
336-
337-
_groupFilter = groupFilter;
338-
_entryListView.setGroupFilter(groupFilter);
333+
_groupFilter = getGroupFilter(chipGroup);
334+
_entryListView.setGroupFilter(_groupFilter);
339335
});
340336

341337
chipGroup.addView(chip);
@@ -368,16 +364,17 @@ private void setSaveChipVisibility(boolean visible) {
368364

369365
private static Set<UUID> getGroupFilter(ChipGroup chipGroup) {
370366
return chipGroup.getCheckedChipIds().stream()
367+
.filter(Objects::nonNull)
371368
.map(i -> {
372369
Chip chip = chipGroup.findViewById(i);
370+
373371
if (chip.getTag() instanceof VaultGroupModel) {
374372
VaultGroupModel group = (VaultGroupModel) chip.getTag();
375373
return group.getUUID();
376374
}
377375

378376
return null;
379377
})
380-
.filter(Objects::nonNull)
381378
.collect(Collectors.toSet());
382379
}
383380

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
android:id="@+id/groupChipGroup"
4040
android:layout_width="match_parent"
4141
android:layout_height="wrap_content"
42-
app:selectionRequired="true"
43-
app:singleSelection="true"/>
42+
app:selectionRequired="true"/>
4443
</LinearLayout>
4544
</HorizontalScrollView>
4645
</com.google.android.material.appbar.AppBarLayout>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@
373373

374374
<string name="pref_highlight_entry_title">Highlight tokens when tapped</string>
375375
<string name="pref_highlight_entry_summary">Make tokens easier to distinguish from each other by temporarily highlighting them when tapped</string>
376+
<string name="pref_groups_multiselect_title">Multiselect groups</string>
377+
<string name="pref_groups_multiselect_summary">Allow the selection of multiple groups at the same time</string>
376378
<string name="pref_minimize_on_copy_title">Minimize on copy</string>
377379
<string name="pref_minimize_on_copy_summary">Minimize the app after copying a token</string>
378380
<string name="pref_copy_behavior_title">Copy tokens to the clipboard</string>

app/src/main/res/xml/preferences_behavior.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
android:title="@string/pref_copy_behavior_title"
2727
app:iconSpaceReserved="false"/>
2828

29+
<androidx.preference.SwitchPreferenceCompat
30+
android:defaultValue="false"
31+
android:key="pref_groups_multiselect"
32+
android:title="@string/pref_groups_multiselect_title"
33+
android:summary="@string/pref_groups_multiselect_summary"
34+
app:iconSpaceReserved="false"/>
35+
2936
<androidx.preference.SwitchPreferenceCompat
3037
android:defaultValue="false"
3138
android:key="pref_highlight_entry"

0 commit comments

Comments
 (0)