From 0bba1ac1f348e1feb4fb544f2e4ee1d5429e94a9 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Mar 2017 08:05:46 +0100 Subject: [PATCH] Allow searching for app name in log view --- .../java/eu/faircode/netguard/ActivityLog.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/ActivityLog.java b/app/src/main/java/eu/faircode/netguard/ActivityLog.java index 97492bc5..f58f2621 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityLog.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityLog.java @@ -332,17 +332,30 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. menuSearch = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + private String getUidForName(String query) { + if (query != null && query.length() > 0) { + for (Rule rule : Rule.getRules(true, ActivityLog.this)) + if (rule.name != null && rule.name.toLowerCase().contains(query.toLowerCase())) { + String newQuery = Integer.toString(rule.info.applicationInfo.uid); + Log.i(TAG, "Search " + query + " found " + rule.name + " new " + newQuery); + return newQuery; + } + Log.i(TAG, "Search " + query + " not found"); + } + return query; + } + @Override public boolean onQueryTextSubmit(String query) { if (adapter != null) - adapter.getFilter().filter(query); + adapter.getFilter().filter(getUidForName(query)); return true; } @Override public boolean onQueryTextChange(String newText) { if (adapter != null) - adapter.getFilter().filter(newText); + adapter.getFilter().filter(getUidForName(newText)); return true; } });