handle batch removing contacts from groups

This commit is contained in:
tibbi 2018-03-20 12:22:40 +01:00
parent 911cd99703
commit 4fca6ce711
2 changed files with 14 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class GroupContactsActivity : SimpleActivity() {
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
ContactsHelper(this).apply {
addContactsToGroup(addedContacts, group.id)
removeContactsFromGroup(removedContacts, group.id)
}
refreshContacts()
}

View File

@ -760,6 +760,19 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
}
fun removeContactsFromGroup(contacts: ArrayList<Contact>, groupId: Long) {
val operations = ArrayList<ContentProviderOperation>()
contacts.forEach {
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ? AND ${ContactsContract.Data.DATA1} = ?"
val selectionArgs = arrayOf(it.id.toString(), CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE, groupId.toString())
withSelection(selection, selectionArgs)
operations.add(build())
}
}
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
}
fun insertContact(contact: Contact): Boolean {
return if (contact.source == SMT_PRIVATE) {
insertLocalContact(contact)