MCPcopy Create free account
hub / github.com/M66B/FairEmail / set

Method set

app/src/main/java/eu/faircode/email/AdapterContact.java:440–517  ·  view source on GitHub ↗
(@NonNull List<TupleContactEx> contacts)

Source from the content-addressed store, hash-verified

438 }
439
440 public void set(@NonNull List<TupleContactEx> contacts) {
441 Log.i("Set contacts=" + contacts.size() +
442 " search=" + search +
443 " account=" + account +
444 " types=" + types.size());
445
446 all = contacts;
447
448 new SimpleTask<List<TupleContactEx>>() {
449 @Override
450 protected List<TupleContactEx> onExecute(Context context, Bundle args) {
451 List<TupleContactEx> filtered;
452 if (account == null && types.size() == 0)
453 filtered = contacts;
454 else {
455 filtered = new ArrayList<>();
456 for (TupleContactEx contact : contacts)
457 if ((account == null || contact.account.equals(account)) &&
458 (types.size() == 0 || types.contains(contact.type)))
459 filtered.add(contact);
460 }
461
462 List<TupleContactEx> items;
463 if (TextUtils.isEmpty(search))
464 items = filtered;
465 else {
466 items = new ArrayList<>();
467 String query = search.toLowerCase().trim();
468 for (TupleContactEx contact : filtered)
469 if (contact.email.toLowerCase().contains(query) ||
470 (contact.name != null && contact.name.toLowerCase().contains(query)))
471 items.add(contact);
472 }
473
474 return items;
475 }
476
477 @Override
478 protected void onExecuted(Bundle args, List<TupleContactEx> items) {
479 DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false);
480
481 selected = items;
482
483 diff.dispatchUpdatesTo(new ListUpdateCallback() {
484 @Override
485 public void onInserted(int position, int count) {
486 Log.d("Inserted @" + position + " #" + count);
487 }
488
489 @Override
490 public void onRemoved(int position, int count) {
491 Log.d("Removed @" + position + " #" + count);
492 }
493
494 @Override
495 public void onMoved(int fromPosition, int toPosition) {
496 Log.d("Moved " + fromPosition + ">" + toPosition);
497 }

Callers 2

searchMethod · 0.95
filterMethod · 0.95

Calls 4

iMethod · 0.95
serialMethod · 0.80
sizeMethod · 0.65
executeMethod · 0.45

Tested by

no test coverage detected