From 503ce87c9115fb5c6abd7495ff50d3082f68674c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4ttgen?= Date: Mon, 25 Nov 2024 00:17:37 +0100 Subject: [PATCH] Improve search feature for better UX --- .../aegis/ui/MainActivity.java | 3 +++ .../aegis/ui/views/EntryAdapter.java | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index 9710201738..2083a75116 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -930,6 +930,7 @@ public boolean onCreateOptionsMenu(Menu menu) { _searchView.setOnCloseListener(() -> { boolean enabled = _submittedSearchQuery != null; _searchViewBackPressHandler.setEnabled(enabled); + _groupChip.setVisibility(_groups.isEmpty() ? View.GONE : View.VISIBLE); return false; }); @@ -963,6 +964,7 @@ public boolean onQueryTextChange(String s) { }); _searchView.setOnSearchClickListener(v -> { String query = _submittedSearchQuery != null ? _submittedSearchQuery : _pendingSearchQuery; + _groupChip.setVisibility(View.GONE); _searchView.setQuery(query, false); }); @@ -1028,6 +1030,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void collapseSearchView() { + _groupChip.setVisibility(_groups.isEmpty() ? View.GONE : View.VISIBLE); _searchView.setQuery(null, false); _searchView.setIconified(true); } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java index 480ba2670c..9fce5424aa 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/views/EntryAdapter.java @@ -37,6 +37,7 @@ import com.beemdevelopment.aegis.vault.VaultGroup; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -196,6 +197,19 @@ private boolean isEntryFiltered(VaultEntry entry) { String name = entry.getName().toLowerCase(); String note = entry.getNote().toLowerCase(); + if (_searchFilter != null) { + String[] tokens = _searchFilter.toLowerCase().split("\\s+"); + + // Return true if not all tokens match at least one of the relevant fields + return !Arrays.stream(tokens) + .allMatch(token -> + ((_searchBehaviorMask & Preferences.SEARCH_IN_ISSUER) != 0 && issuer.contains(token)) || + ((_searchBehaviorMask & Preferences.SEARCH_IN_NAME) != 0 && name.contains(token)) || + ((_searchBehaviorMask & Preferences.SEARCH_IN_NOTE) != 0 && note.contains(token)) || + ((_searchBehaviorMask & Preferences.SEARCH_IN_GROUPS) != 0 && doesAnyGroupMatchSearchFilter(groups, token)) + ); + } + if (!_groupFilter.isEmpty()) { if (groups.isEmpty() && !_groupFilter.contains(null)) { return true; @@ -205,14 +219,7 @@ private boolean isEntryFiltered(VaultEntry entry) { } } - if (_searchFilter == null) { - return false; - } - - return ((_searchBehaviorMask & Preferences.SEARCH_IN_ISSUER) == 0 || !issuer.contains(_searchFilter)) - && ((_searchBehaviorMask & Preferences.SEARCH_IN_NAME) == 0 || !name.contains(_searchFilter)) - && ((_searchBehaviorMask & Preferences.SEARCH_IN_NOTE) == 0 || !note.contains(_searchFilter)) - && ((_searchBehaviorMask & Preferences.SEARCH_IN_GROUPS) == 0 || !doesAnyGroupMatchSearchFilter(entry.getGroups(), _searchFilter)); + return false; } private boolean doesAnyGroupMatchSearchFilter(Set entryGroupUUIDs, String searchFilter) {