delete contacts from all sources at deleting from the main screen

This commit is contained in:
tibbi 2019-09-12 14:44:37 +02:00
parent 415ef33c09
commit 3d24a84248
1 changed files with 16 additions and 9 deletions

View File

@ -176,16 +176,23 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
val positions = getSelectedItemPositions()
contactItems.removeAll(contactsToRemove)
ensureBackgroundThread {
ContactsHelper(activity).deleteContacts(contactsToRemove)
ContactsHelper(activity).getContacts { allContacts ->
ensureBackgroundThread {
contactsToRemove.forEach {
val contactToRemove = it
val duplicates = allContacts.filter { it.id != contactToRemove.id && it.getHashToCompare() == contactToRemove.getHashToCompare() }.toMutableList() as ArrayList<Contact>
duplicates.add(contactToRemove)
ContactsHelper(activity).deleteContacts(duplicates)
}
activity.runOnUiThread {
if (contactItems.isEmpty()) {
refreshListener?.refreshContacts(ALL_TABS_MASK)
finishActMode()
} else {
removeSelectedItems(positions)
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
activity.runOnUiThread {
if (contactItems.isEmpty()) {
refreshListener?.refreshContacts(ALL_TABS_MASK)
finishActMode()
} else {
removeSelectedItems(positions)
refreshListener?.refreshContacts(CONTACTS_TAB_MASK or FAVORITES_TAB_MASK)
}
}
}
}