properly handle contact groups at editing, or inserting a new one

This commit is contained in:
tibbi 2018-03-18 17:57:43 +01:00
parent 9d9495ea80
commit 6750512f11
1 changed files with 28 additions and 0 deletions

View File

@ -633,6 +633,24 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// delete groups
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ? "
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
withSelection(selection, selectionArgs)
operations.add(build())
}
// add groups
contact.groups.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.GroupMembership.GROUP_ROW_ID, it.id)
operations.add(build())
}
}
// favorite
try {
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contact.contactId.toString())
@ -767,6 +785,16 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// groups
contact.groups.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.GroupMembership.GROUP_ROW_ID, it.id)
operations.add(build())
}
}
// photo (inspired by https://gist.github.com/slightfoot/5985900)
var fullSizePhotoData: ByteArray? = null
var scaledSizePhotoData: ByteArray?