Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to multiselect groups #1559

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 9 additions & 12 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,24 @@ 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 +365,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 +375,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
Loading