mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Allow filtering by "No group"
This is a continuation of #830 Close #826, #830
This commit is contained in:
parent
e73de453c6
commit
ce9a15b7bc
3 changed files with 26 additions and 16 deletions
|
@ -347,7 +347,7 @@ public class Preferences {
|
||||||
JSONArray json = new JSONArray(raw);
|
JSONArray json = new JSONArray(raw);
|
||||||
List<String> filter = new ArrayList<>();
|
List<String> filter = new ArrayList<>();
|
||||||
for (int i = 0; i < json.length(); i++) {
|
for (int i = 0; i < json.length(); i++) {
|
||||||
filter.add(json.getString(i));
|
filter.add(json.isNull(i) ? null : json.optString(i));
|
||||||
}
|
}
|
||||||
return filter;
|
return filter;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
|
@ -220,7 +220,7 @@ public class EntryAdapter extends RecyclerView.Adapter<EntryHolder> implements I
|
||||||
String name = entry.getName().toLowerCase();
|
String name = entry.getName().toLowerCase();
|
||||||
|
|
||||||
if (!_groupFilter.isEmpty()) {
|
if (!_groupFilter.isEmpty()) {
|
||||||
if (group == null || !_groupFilter.contains(group)) {
|
if (!_groupFilter.contains(group)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.beemdevelopment.aegis.ui.views;
|
package com.beemdevelopment.aegis.ui.views;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -388,6 +387,20 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
_recyclerView.scheduleLayoutAnimation();
|
_recyclerView.scheduleLayoutAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addChipTo(ChipGroup chipGroup, String group) {
|
||||||
|
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.chip_material, null, false);
|
||||||
|
chip.setText(group == null ? getString(R.string.no_group) : group);
|
||||||
|
chip.setCheckable(true);
|
||||||
|
chip.setChecked(_groupFilter != null && _groupFilter.contains(group));
|
||||||
|
chip.setCheckedIconVisible(true);
|
||||||
|
chip.setOnCheckedChangeListener((group1, checkedId) -> {
|
||||||
|
List<String> groupFilter = getGroupFilter(chipGroup);
|
||||||
|
setGroupFilter(groupFilter, true);
|
||||||
|
});
|
||||||
|
chip.setTag(group == null ? new Object() : null);
|
||||||
|
chipGroup.addView(chip);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeGroupChip() {
|
private void initializeGroupChip() {
|
||||||
View view = getLayoutInflater().inflate(R.layout.dialog_select_groups, null);
|
View view = getLayoutInflater().inflate(R.layout.dialog_select_groups, null);
|
||||||
BottomSheetDialog dialog = new BottomSheetDialog(requireContext());
|
BottomSheetDialog dialog = new BottomSheetDialog(requireContext());
|
||||||
|
@ -415,18 +428,9 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
chipGroup.removeAllViews();
|
chipGroup.removeAllViews();
|
||||||
|
|
||||||
for (String group : _groups) {
|
for (String group : _groups) {
|
||||||
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.chip_material, null, false);
|
addChipTo(chipGroup, group);
|
||||||
chip.setText(group);
|
|
||||||
chip.setCheckable(true);
|
|
||||||
chip.setChecked(_groupFilter != null && _groupFilter.contains(group));
|
|
||||||
chip.setCheckedIconVisible(true);
|
|
||||||
chip.setOnCheckedChangeListener((group1, checkedId) -> {
|
|
||||||
List<String> groupFilter = getGroupFilter(chipGroup);
|
|
||||||
setGroupFilter(groupFilter, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
chipGroup.addView(chip);
|
|
||||||
}
|
}
|
||||||
|
addChipTo(chipGroup, null);
|
||||||
|
|
||||||
Dialogs.showSecureDialog(dialog);
|
Dialogs.showSecureDialog(dialog);
|
||||||
});
|
});
|
||||||
|
@ -434,7 +438,13 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
|
|
||||||
private static List<String> getGroupFilter(ChipGroup chipGroup) {
|
private static List<String> getGroupFilter(ChipGroup chipGroup) {
|
||||||
return chipGroup.getCheckedChipIds().stream()
|
return chipGroup.getCheckedChipIds().stream()
|
||||||
.map(i -> ((Chip) chipGroup.findViewById(i)).getText().toString())
|
.map(i -> {
|
||||||
|
Chip chip = chipGroup.findViewById(i);
|
||||||
|
if (chip.getTag() != null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return chip. getText().toString();
|
||||||
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +482,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
|
|
||||||
private List<String> cleanGroupFilter(List<String> groupFilter) {
|
private List<String> cleanGroupFilter(List<String> groupFilter) {
|
||||||
return groupFilter.stream()
|
return groupFilter.stream()
|
||||||
.filter(g -> _groups.contains(g))
|
.filter(g -> g == null || _groups.contains(g))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue