From aa3a102edbc8b0a12df9980de9197e7102564b2e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 4 Sep 2021 09:12:45 +0200 Subject: [PATCH] Prepare searching for folders --- .../java/eu/faircode/email/AdapterFolder.java | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 747d9d7253..73bfcee6a9 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -101,9 +101,10 @@ public class AdapterFolder extends RecyclerView.Adapter disabledIds = new ArrayList<>(); private List all = new ArrayList<>(); - private List items = new ArrayList<>(); + private List selected = new ArrayList<>(); private NumberFormat NF = NumberFormat.getNumberInstance(); @@ -393,7 +394,7 @@ public class AdapterFolder extends RecyclerView.Adapter folders) { - Log.i("Set folders=" + folders.size()); + Log.i("Set folders=" + folders.size() + " search=" + search); all = folders; List hierarchical; @@ -1237,9 +1238,20 @@ public class AdapterFolder extends RecyclerView.Adapter items; + if (TextUtils.isEmpty(search)) + items = hierarchical; + else { + items = new ArrayList<>(); + String query = search.toLowerCase().trim(); + for (TupleFolderEx item : hierarchical) + if (item.getDisplayName(context).toLowerCase().contains(query)) + items.add(item); + } + + DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false); - items = hierarchical; + selected = items; diff.dispatchUpdatesTo(new ListUpdateCallback() { @Override @@ -1265,6 +1277,12 @@ public class AdapterFolder extends RecyclerView.Adapter