adding a helper function for retrieving contact duplicates

This commit is contained in:
tibbi 2019-09-11 22:49:19 +02:00
parent dcd546b7cb
commit 797df0a2d7
2 changed files with 12 additions and 7 deletions

View File

@ -477,18 +477,14 @@ class ViewContactActivity : ContactActivity() {
} }
addContactSource(contact!!) addContactSource(contact!!)
ensureBackgroundThread { ContactsHelper(this).getDuplicatesOfContact(contact!!) { contacts ->
ContactsHelper(this).getContacts { contacts ->
contacts.forEach {
if (it.id != contact!!.id && it.getHashToCompare() == contact!!.getHashToCompare()) {
runOnUiThread { runOnUiThread {
contacts.forEach {
addContactSource(it) addContactSource(it)
} }
} }
} }
} }
}
}
private fun addContactSource(contact: Contact) { private fun addContactSource(contact: Contact) {
if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) { if (showFields and SHOW_CONTACT_SOURCE_FIELD != 0) {

View File

@ -1561,4 +1561,13 @@ class ContactsHelper(val context: Context) {
context.showErrorToast(e) context.showErrorToast(e)
} }
} }
fun getDuplicatesOfContact(contact: Contact, callback: (ArrayList<Contact>) -> Unit) {
ensureBackgroundThread {
getContacts { contacts ->
val duplicates = contacts.filter { it.id != contact.id && it.getHashToCompare() == contact.getHashToCompare() }.toMutableList() as ArrayList<Contact>
callback(duplicates)
}
}
}
} }