Skip to content

Commit 9fcc064

Browse files
Add ability to multiselect groups
1 parent 920df1d commit 9fcc064

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

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

+4
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

+9-16
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ private void initializeGroups() {
282282
GroupPlaceholderType placeholderType = GroupPlaceholderType.NO_GROUP;
283283
addChipTo(_groupChip, new VaultGroupModel(this, placeholderType));
284284
addSaveChip(_groupChip);
285+
286+
_groupChip.setSingleSelection(!_prefs.isGroupMultiselectEnabled());
285287
}
286288

287289
private Set<UUID> cleanGroupFilter(Set<UUID> groupFilter) {
@@ -313,29 +315,20 @@ private void addChipTo(ChipGroup chipGroup, VaultGroupModel group) {
313315
}
314316

315317
chip.setOnCheckedChangeListener((group1, isChecked) -> {
316-
Set<UUID> groupFilter = new HashSet<>();
317-
if (_actionMode != null) {
318-
_actionMode.finish();
319-
}
320-
321318
setSaveChipVisibility(true);
322319

323-
if (!isChecked) {
320+
// Reset group filter if last checked group gets unchecked
321+
if (!isChecked && _groupFilter.size() == 1) {
322+
Set<UUID> groupFilter = new HashSet<>();
323+
324324
group1.setChecked(false);
325325
_groupFilter = groupFilter;
326326
_entryListView.setGroupFilter(groupFilter);
327327
return;
328328
}
329329

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);
330+
_groupFilter = getGroupFilter(chipGroup);
331+
_entryListView.setGroupFilter(_groupFilter);
339332
});
340333

341334
chipGroup.addView(chip);
@@ -368,6 +361,7 @@ private void setSaveChipVisibility(boolean visible) {
368361

369362
private static Set<UUID> getGroupFilter(ChipGroup chipGroup) {
370363
return chipGroup.getCheckedChipIds().stream()
364+
.filter(Objects::nonNull)
371365
.map(i -> {
372366
Chip chip = chipGroup.findViewById(i);
373367
if (chip.getTag() instanceof VaultGroupModel) {
@@ -377,7 +371,6 @@ private static Set<UUID> getGroupFilter(ChipGroup chipGroup) {
377371

378372
return null;
379373
})
380-
.filter(Objects::nonNull)
381374
.collect(Collectors.toSet());
382375
}
383376

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

+1-2
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

+2
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

+7
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)