mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
handle batch adding contacts to a group
This commit is contained in:
@ -31,6 +31,9 @@ class GroupContactsActivity : SimpleActivity() {
|
||||
refreshContacts()
|
||||
group_contacts_fab.setOnClickListener {
|
||||
SelectContactsDialog(this, allContacts, groupContacts) { addedContacts, removedContacts ->
|
||||
ContactsHelper(this).apply {
|
||||
addContactsToGroup(addedContacts, group.id)
|
||||
}
|
||||
refreshContacts()
|
||||
}
|
||||
}
|
||||
|
@ -747,6 +747,19 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||
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 {
|
||||
return if (contact.source == SMT_PRIVATE) {
|
||||
insertLocalContact(contact)
|
||||
|
Reference in New Issue
Block a user