handle batch adding contacts to a group
This commit is contained in:
parent
5e585eec71
commit
911cd99703
|
@ -31,6 +31,9 @@ class GroupContactsActivity : SimpleActivity() {
|
||||||
refreshContacts()
|
refreshContacts()
|
||||||
group_contacts_fab.setOnClickListener {
|
group_contacts_fab.setOnClickListener {
|
||||||
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
||||||
|
ContactsHelper(this).apply {
|
||||||
|
addContactsToGroup(addedContacts, group.id)
|
||||||
|
}
|
||||||
refreshContacts()
|
refreshContacts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -747,6 +747,19 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
return operations
|
return operations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun addContactsToGroup(contacts: ArrayList<Contact>, groupId: Long) {
|
||||||
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
|
contacts.forEach {
|
||||||
|
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
|
||||||
|
withValue(ContactsContract.Data.RAW_CONTACT_ID, it.id)
|
||||||
|
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
|
||||||
|
withValue(CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId)
|
||||||
|
operations.add(build())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activity.contentResolver.applyBatch(ContactsContract.AUTHORITY, operations)
|
||||||
|
}
|
||||||
|
|
||||||
fun insertContact(contact: Contact): Boolean {
|
fun insertContact(contact: Contact): Boolean {
|
||||||
return if (contact.source == SMT_PRIVATE) {
|
return if (contact.source == SMT_PRIVATE) {
|
||||||
insertLocalContact(contact)
|
insertLocalContact(contact)
|
||||||
|
|
Loading…
Reference in New Issue