diff --git a/app/src/main/java/eu/faircode/email/AdapterContact.java b/app/src/main/java/eu/faircode/email/AdapterContact.java index 96bc0865ed..c2fa5c0250 100644 --- a/app/src/main/java/eu/faircode/email/AdapterContact.java +++ b/app/src/main/java/eu/faircode/email/AdapterContact.java @@ -65,6 +65,7 @@ import java.io.InputStream; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; public class AdapterContact extends RecyclerView.Adapter { private Fragment parentFragment; @@ -84,6 +85,9 @@ public class AdapterContact extends RecyclerView.Adapter filtered; - if (types.size() == 0) - filtered = all; - else { - filtered = new ArrayList<>(); - for (TupleContactEx contact : all) - if (types.contains(contact.type)) - filtered.add(contact); - } - - List items; - if (TextUtils.isEmpty(search)) - items = filtered; - else { - items = new ArrayList<>(); - String query = search.toLowerCase().trim(); - for (TupleContactEx contact : filtered) - if (contact.email.toLowerCase().contains(query) || - (contact.name != null && contact.name.toLowerCase().contains(query))) - items.add(contact); - } - - DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false); + new SimpleTask>() { + @Override + protected List onExecute(Context context, Bundle args) throws Throwable { + List filtered; + if (types.size() == 0) + filtered = contacts; + else { + filtered = new ArrayList<>(); + for (TupleContactEx contact : contacts) + if (types.contains(contact.type)) + filtered.add(contact); + } - selected = items; + List items; + if (TextUtils.isEmpty(search)) + items = filtered; + else { + items = new ArrayList<>(); + String query = search.toLowerCase().trim(); + for (TupleContactEx contact : filtered) + if (contact.email.toLowerCase().contains(query) || + (contact.name != null && contact.name.toLowerCase().contains(query))) + items.add(contact); + } - diff.dispatchUpdatesTo(new ListUpdateCallback() { - @Override - public void onInserted(int position, int count) { - Log.d("Inserted @" + position + " #" + count); + return items; } @Override - public void onRemoved(int position, int count) { - Log.d("Removed @" + position + " #" + count); - } + protected void onExecuted(Bundle args, List items) { + DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false); - @Override - public void onMoved(int fromPosition, int toPosition) { - Log.d("Moved " + fromPosition + ">" + toPosition); + selected = items; + + diff.dispatchUpdatesTo(new ListUpdateCallback() { + @Override + public void onInserted(int position, int count) { + Log.d("Inserted @" + position + " #" + count); + } + + @Override + public void onRemoved(int position, int count) { + Log.d("Removed @" + position + " #" + count); + } + + @Override + public void onMoved(int fromPosition, int toPosition) { + Log.d("Moved " + fromPosition + ">" + toPosition); + } + + @Override + public void onChanged(int position, int count, Object payload) { + Log.d("Changed @" + position + " #" + count); + } + }); + diff.dispatchUpdatesTo(AdapterContact.this); } @Override - public void onChanged(int position, int count, Object payload) { - Log.d("Changed @" + position + " #" + count); + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); } - }); - diff.dispatchUpdatesTo(this); + }.setExecutor(executor).execute(context, owner, new Bundle(), "contacts:filter"); } public void search(String query) {