at deleting a contact delete all duplicates too

This commit is contained in:
tibbi
2019-09-11 23:07:53 +02:00
parent 797df0a2d7
commit 8fdb6ee0a8
2 changed files with 8 additions and 9 deletions

View File

@ -477,7 +477,7 @@ class ViewContactActivity : ContactActivity() {
} }
addContactSource(contact!!) addContactSource(contact!!)
ContactsHelper(this).getDuplicatesOfContact(contact!!) { contacts -> ContactsHelper(this).getDuplicatesOfContact(contact!!, false) { contacts ->
runOnUiThread { runOnUiThread {
contacts.forEach { contacts.forEach {
addContactSource(it) addContactSource(it)

View File

@ -1524,13 +1524,9 @@ class ContactsHelper(val context: Context) {
LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites) LocalContactsHelper(context).toggleFavorites(localContacts, addToFavorites)
} }
fun deleteContact(contact: Contact) { fun deleteContact(originalContact: Contact) {
ensureBackgroundThread { getDuplicatesOfContact(originalContact, true) { contacts ->
if (contact.isPrivate()) { deleteContacts(contacts)
context.contactsDB.deleteContactId(contact.id)
} else {
deleteContacts(arrayListOf(contact))
}
} }
} }
@ -1562,10 +1558,13 @@ class ContactsHelper(val context: Context) {
} }
} }
fun getDuplicatesOfContact(contact: Contact, callback: (ArrayList<Contact>) -> Unit) { fun getDuplicatesOfContact(contact: Contact, addOriginal: Boolean, callback: (ArrayList<Contact>) -> Unit) {
ensureBackgroundThread { ensureBackgroundThread {
getContacts { contacts -> getContacts { contacts ->
val duplicates = contacts.filter { it.id != contact.id && it.getHashToCompare() == contact.getHashToCompare() }.toMutableList() as ArrayList<Contact> val duplicates = contacts.filter { it.id != contact.id && it.getHashToCompare() == contact.getHashToCompare() }.toMutableList() as ArrayList<Contact>
if (addOriginal) {
duplicates.add(contact)
}
callback(duplicates) callback(duplicates)
} }
} }