handle website at contact update/insert

This commit is contained in:
tibbi 2018-04-13 14:23:35 +02:00
parent 97bd5dacef
commit 4962a955e5
2 changed files with 44 additions and 0 deletions

View File

@ -710,6 +710,7 @@ class EditContactActivity : ContactActivity() {
source = contact!!.source
starred = if (isContactStarred()) 1 else 0
notes = contact_notes.value
websites = getFilledWebsites()
val company = contact_organization_company.value
val jobPosition = contact_organization_job_position.value
@ -788,6 +789,19 @@ class EditContactActivity : ContactActivity() {
return events
}
private fun getFilledWebsites(): ArrayList<String> {
val websites = ArrayList<String>()
val websitesCount = contact_websites_holder.childCount
for (i in 0 until websitesCount) {
val websiteHolder = contact_websites_holder.getChildAt(i)
val website = websiteHolder.contact_website.value
if (website.isNotEmpty()) {
websites.add(website)
}
}
return websites
}
private fun insertNewContact() {
isSaving = true
toast(R.string.inserting)

View File

@ -845,6 +845,25 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// delete websites
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.Website.CONTENT_ITEM_TYPE)
withSelection(selection, selectionArgs)
operations.add(build())
}
// add websites
contact.websites.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.Website.URL, it)
withValue(CommonDataKinds.Website.TYPE, CommonDataKinds.Website.TYPE_HOMEPAGE)
operations.add(build())
}
}
// delete groups
val relevantGroupIDs = getStoredGroups().map { it.id }
if (relevantGroupIDs.isNotEmpty()) {
@ -1051,6 +1070,17 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
operations.add(build())
}
// websites
contact.websites.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
withValue(CommonDataKinds.Website.URL, it)
withValue(CommonDataKinds.Website.TYPE, CommonDataKinds.Website.TYPE_HOMEPAGE)
operations.add(build())
}
}
// groups
contact.groups.forEach {
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).apply {