Skip to content

Commit

Permalink
Add ability to multiselect groups
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelschattgen committed Dec 22, 2024
1 parent 920df1d commit 9fcc064
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/beemdevelopment/aegis/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public boolean isTapToRevealEnabled() {
return _prefs.getBoolean("pref_tap_to_reveal", false);
}

public boolean isGroupMultiselectEnabled() {
return _prefs.getBoolean("pref_groups_multiselect", false);
}

public boolean isEntryHighlightEnabled() {
return _prefs.getBoolean("pref_highlight_entry", false);
}
Expand Down
25 changes: 9 additions & 16 deletions app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ private void initializeGroups() {
GroupPlaceholderType placeholderType = GroupPlaceholderType.NO_GROUP;
addChipTo(_groupChip, new VaultGroupModel(this, placeholderType));
addSaveChip(_groupChip);

_groupChip.setSingleSelection(!_prefs.isGroupMultiselectEnabled());
}

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

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

setSaveChipVisibility(true);

if (!isChecked) {
// Reset group filter if last checked group gets unchecked
if (!isChecked && _groupFilter.size() == 1) {
Set<UUID> groupFilter = new HashSet<>();

group1.setChecked(false);
_groupFilter = groupFilter;
_entryListView.setGroupFilter(groupFilter);
return;
}

Object chipTag = group1.getTag();
if (chipTag == GroupPlaceholderType.NO_GROUP) {
groupFilter.add(null);
} else {
groupFilter = getGroupFilter(chipGroup);
}

_groupFilter = groupFilter;
_entryListView.setGroupFilter(groupFilter);
_groupFilter = getGroupFilter(chipGroup);
_entryListView.setGroupFilter(_groupFilter);
});

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

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

return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
android:id="@+id/groupChipGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:selectionRequired="true"
app:singleSelection="true"/>
app:selectionRequired="true"/>
</LinearLayout>
</HorizontalScrollView>
</com.google.android.material.appbar.AppBarLayout>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@

<string name="pref_highlight_entry_title">Highlight tokens when tapped</string>
<string name="pref_highlight_entry_summary">Make tokens easier to distinguish from each other by temporarily highlighting them when tapped</string>
<string name="pref_groups_multiselect_title">Multiselect groups</string>
<string name="pref_groups_multiselect_summary">Allow the selection of multiple groups at the same time</string>
<string name="pref_minimize_on_copy_title">Minimize on copy</string>
<string name="pref_minimize_on_copy_summary">Minimize the app after copying a token</string>
<string name="pref_copy_behavior_title">Copy tokens to the clipboard</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/preferences_behavior.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
android:title="@string/pref_copy_behavior_title"
app:iconSpaceReserved="false"/>

<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_groups_multiselect"
android:title="@string/pref_groups_multiselect_title"
android:summary="@string/pref_groups_multiselect_summary"
app:iconSpaceReserved="false"/>

<androidx.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_highlight_entry"
Expand Down

0 comments on commit 9fcc064

Please sign in to comment.