Skip to content

Commit 7c6e3ae

Browse files
authored
Merge pull request #1559 from michaelschattgen/feature/multiselect-groups
Add ability to multiselect groups
2 parents 8ddf8c5 + 78ee38b commit 7c6e3ae

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

+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

+10-13
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public void setGroups(Collection<VaultGroup> groups) {
278278

279279
private void initializeGroups() {
280280
_groupChip.removeAllViews();
281+
_groupChip.setSingleSelection(!_prefs.isGroupMultiselectEnabled());
281282

282283
for (VaultGroup group : _groups) {
283284
addChipTo(_groupChip, new VaultGroupModel(group));
@@ -317,29 +318,24 @@ private void addChipTo(ChipGroup chipGroup, VaultGroupModel group) {
317318
}
318319

319320
chip.setOnCheckedChangeListener((group1, isChecked) -> {
320-
Set<UUID> groupFilter = new HashSet<>();
321321
if (_actionMode != null) {
322322
_actionMode.finish();
323323
}
324324

325325
setSaveChipVisibility(true);
326326

327-
if (!isChecked) {
328-
group1.setChecked(false);
327+
// Reset group filter if last checked group gets unchecked
328+
if (!isChecked && _groupFilter.size() == 1) {
329+
Set<UUID> groupFilter = new HashSet<>();
330+
331+
chipGroup.clearCheck();
329332
_groupFilter = groupFilter;
330333
_entryListView.setGroupFilter(groupFilter);
331334
return;
332335
}
333336

334-
Object chipTag = group1.getTag();
335-
if (chipTag == GroupPlaceholderType.NO_GROUP) {
336-
groupFilter.add(null);
337-
} else {
338-
groupFilter = getGroupFilter(chipGroup);
339-
}
340-
341-
_groupFilter = groupFilter;
342-
_entryListView.setGroupFilter(groupFilter);
337+
_groupFilter = getGroupFilter(chipGroup);
338+
_entryListView.setGroupFilter(_groupFilter);
343339
});
344340

345341
chipGroup.addView(chip);
@@ -372,16 +368,17 @@ private void setSaveChipVisibility(boolean visible) {
372368

373369
private static Set<UUID> getGroupFilter(ChipGroup chipGroup) {
374370
return chipGroup.getCheckedChipIds().stream()
371+
.filter(Objects::nonNull)
375372
.map(i -> {
376373
Chip chip = chipGroup.findViewById(i);
374+
377375
if (chip.getTag() instanceof VaultGroupModel) {
378376
VaultGroupModel group = (VaultGroupModel) chip.getTag();
379377
return group.getUUID();
380378
}
381379

382380
return null;
383381
})
384-
.filter(Objects::nonNull)
385382
.collect(Collectors.toSet());
386383
}
387384

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
@@ -375,6 +375,8 @@
375375

376376
<string name="pref_highlight_entry_title">Highlight tokens when tapped</string>
377377
<string name="pref_highlight_entry_summary">Make tokens easier to distinguish from each other by temporarily highlighting them when tapped</string>
378+
<string name="pref_groups_multiselect_title">Multiselect groups</string>
379+
<string name="pref_groups_multiselect_summary">Allow the selection of multiple groups at the same time</string>
378380
<string name="pref_minimize_on_copy_title">Minimize on copy</string>
379381
<string name="pref_minimize_on_copy_summary">Minimize the app after copying a token</string>
380382
<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)