Filter on junk contacts

This commit is contained in:
M66B
2021-09-18 19:08:58 +02:00
parent 935882fb19
commit c2c2d131c8
3 changed files with 51 additions and 4 deletions

View File

@@ -77,6 +77,8 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
private int textColorSecondary;
private String search = null;
private List<Integer> types = new ArrayList<>();
private List<TupleContactEx> all = new ArrayList<>();
private List<TupleContactEx> selected = new ArrayList<>();
@@ -369,17 +371,28 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
}
public void set(@NonNull List<TupleContactEx> contacts) {
Log.i("Set contacts=" + contacts.size() + " search=" + search);
Log.i("Set contacts=" + contacts.size() +
" search=" + search + " types=" + types.size());
all = contacts;
List<TupleContactEx> filtered;
if (types.size() == 0)
filtered = all;
else {
filtered = new ArrayList<>();
for (TupleContactEx contact : all)
if (types.contains(contact.type))
filtered.add(contact);
}
List<TupleContactEx> items;
if (TextUtils.isEmpty(search))
items = all;
items = filtered;
else {
items = new ArrayList<>();
String query = search.toLowerCase().trim();
for (TupleContactEx contact : contacts)
for (TupleContactEx contact : filtered)
if (contact.email.toLowerCase().contains(query) ||
(contact.name != null && contact.name.toLowerCase().contains(query)))
items.add(contact);
@@ -419,6 +432,11 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
set(all);
}
public void filter(List<Integer> types) {
this.types = types;
set(all);
}
private static class DiffCallback extends DiffUtil.Callback {
private List<TupleContactEx> prev = new ArrayList<>();
private List<TupleContactEx> next = new ArrayList<>();