mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
delete contacts on a background thread
This commit is contained in:
@ -1044,25 +1044,27 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteContacts(contacts: ArrayList<Contact>) {
|
fun deleteContacts(contacts: ArrayList<Contact>) {
|
||||||
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id.toString() }.toTypedArray()
|
Thread {
|
||||||
activity.dbHelper.deleteContacts(localContacts)
|
val localContacts = contacts.filter { it.source == SMT_PRIVATE }.map { it.id.toString() }.toTypedArray()
|
||||||
|
activity.dbHelper.deleteContacts(localContacts)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val contactIDs = HashSet<String>()
|
val contactIDs = HashSet<String>()
|
||||||
val operations = ArrayList<ContentProviderOperation>()
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
val selection = "${ContactsContract.Data.CONTACT_ID} = ?"
|
val selection = "${ContactsContract.Data.CONTACT_ID} = ?"
|
||||||
contacts.filter { it.source != SMT_PRIVATE }.forEach {
|
contacts.filter { it.source != SMT_PRIVATE }.forEach {
|
||||||
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
|
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
|
||||||
val selectionArgs = arrayOf(it.contactId.toString())
|
val selectionArgs = arrayOf(it.contactId.toString())
|
||||||
withSelection(selection, selectionArgs)
|
withSelection(selection, selectionArgs)
|
||||||
operations.add(this.build())
|
operations.add(this.build())
|
||||||
|
}
|
||||||
|
contactIDs.add(it.id.toString())
|
||||||
}
|
}
|
||||||
contactIDs.add(it.id.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
activity.showErrorToast(e)
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user