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(); } }