From ccc0471418293df1186d676dcf96107a6f7d910f Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 1 Feb 2016 07:55:04 +0100 Subject: [PATCH] Auto expand search with one result --- .../eu/faircode/netguard/RuleAdapter.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java index 90dd1a5f..78b72204 100644 --- a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java +++ b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java @@ -76,7 +76,7 @@ public class RuleAdapter extends RecyclerView.Adapter im private boolean wifiActive = true; private boolean otherActive = true; private List listAll = new ArrayList<>(); - private List listSelected = new ArrayList<>(); + private List listFiltered = new ArrayList<>(); public static class ViewHolder extends RecyclerView.ViewHolder { public View view; @@ -214,8 +214,8 @@ public class RuleAdapter extends RecyclerView.Adapter im public void set(List listRule) { listAll = listRule; - listSelected = new ArrayList<>(); - listSelected.addAll(listRule); + listFiltered = new ArrayList<>(); + listFiltered.addAll(listRule); notifyDataSetChanged(); } @@ -240,7 +240,7 @@ public class RuleAdapter extends RecyclerView.Adapter im @Override public void onBindViewHolder(final ViewHolder holder, final int position) { // Get rule - final Rule rule = listSelected.get(position); + final Rule rule = listFiltered.get(position); // Rule change listener CompoundButton.OnCheckedChangeListener cbListener = new CompoundButton.OnCheckedChangeListener() { @@ -636,12 +636,14 @@ public class RuleAdapter extends RecyclerView.Adapter im @Override protected void publishResults(CharSequence query, FilterResults result) { - listSelected.clear(); + listFiltered.clear(); if (result == null) - listSelected.addAll(listAll); - else - for (Rule rule : (List) result.values) - listSelected.add(rule); + listFiltered.addAll(listAll); + else { + listFiltered.addAll((List) result.values); + if (listFiltered.size() == 1) + listFiltered.get(0).expanded = true; + } notifyDataSetChanged(); } }; @@ -654,6 +656,6 @@ public class RuleAdapter extends RecyclerView.Adapter im @Override public int getItemCount() { - return listSelected.size(); + return listFiltered.size(); } }