handle IM fields at inserting/updating contacts

This commit is contained in:
tibbi 2018-09-04 15:36:30 +02:00
parent b4d62f64aa
commit 7eb2184285
1 changed files with 32 additions and 0 deletions

View File

@ -981,6 +981,26 @@ class ContactsHelper(val activity: Activity) {
}
}
// delete IMs
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.Im.CONTENT_ITEM_TYPE)
withSelection(selection, selectionArgs)
operations.add(build())
}
// add IMs
contact.IMs.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.Im.DATA, it.value)
withValue(CommonDataKinds.Im.PROTOCOL, it.type)
withValue(CommonDataKinds.Im.CUSTOM_PROTOCOL, it.label)
operations.add(build())
}
}
// delete events
ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI).apply {
val selection = "${ContactsContract.Data.RAW_CONTACT_ID} = ? AND ${ContactsContract.Data.MIMETYPE} = ? "
@ -1246,6 +1266,18 @@ class ContactsHelper(val activity: Activity) {
}
}
// IMs
contact.IMs.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Im.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.Im.DATA, it.value)
withValue(CommonDataKinds.Im.PROTOCOL, it.type)
withValue(CommonDataKinds.Im.CUSTOM_PROTOCOL, it.label)
operations.add(build())
}
}
// events
contact.events.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {