parse a couple additional fields from WhatsApp Add Contact intent
This commit is contained in:
parent
401f0aed6e
commit
25d48ba08c
|
@ -37,11 +37,6 @@ import org.joda.time.format.DateTimeFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class EditContactActivity : ContactActivity() {
|
class EditContactActivity : ContactActivity() {
|
||||||
private val DEFAULT_EMAIL_TYPE = CommonDataKinds.Email.TYPE_HOME
|
|
||||||
private val DEFAULT_PHONE_NUMBER_TYPE = CommonDataKinds.Phone.TYPE_MOBILE
|
|
||||||
private val DEFAULT_ADDRESS_TYPE = CommonDataKinds.StructuredPostal.TYPE_HOME
|
|
||||||
private val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
|
||||||
|
|
||||||
private val INTENT_TAKE_PHOTO = 1
|
private val INTENT_TAKE_PHOTO = 1
|
||||||
private val INTENT_CHOOSE_PHOTO = 2
|
private val INTENT_CHOOSE_PHOTO = 2
|
||||||
private val INTENT_CROP_PHOTO = 3
|
private val INTENT_CROP_PHOTO = 3
|
||||||
|
@ -936,6 +931,8 @@ class EditContactActivity : ContactActivity() {
|
||||||
CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE -> parseAddress(it)
|
CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE -> parseAddress(it)
|
||||||
CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> parseOrganization(it)
|
CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> parseOrganization(it)
|
||||||
CommonDataKinds.Event.CONTENT_ITEM_TYPE -> parseEvent(it)
|
CommonDataKinds.Event.CONTENT_ITEM_TYPE -> parseEvent(it)
|
||||||
|
CommonDataKinds.Website.CONTENT_ITEM_TYPE -> parseWebsite(it)
|
||||||
|
CommonDataKinds.Note.CONTENT_ITEM_TYPE -> parseNote(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -949,24 +946,35 @@ class EditContactActivity : ContactActivity() {
|
||||||
|
|
||||||
private fun parseAddress(contentValues: ContentValues) {
|
private fun parseAddress(contentValues: ContentValues) {
|
||||||
val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE
|
val type = contentValues.getAsInteger(CommonDataKinds.StructuredPostal.DATA2) ?: DEFAULT_ADDRESS_TYPE
|
||||||
val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4) ?: return
|
val addressValue = contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA4)
|
||||||
|
?: contentValues.getAsString(CommonDataKinds.StructuredPostal.DATA1) ?: return
|
||||||
val address = Address(addressValue, type)
|
val address = Address(addressValue, type)
|
||||||
contact!!.addresses.add(address)
|
contact!!.addresses.add(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseOrganization(contentValues: ContentValues) {
|
private fun parseOrganization(contentValues: ContentValues) {
|
||||||
val company = contentValues.getAsString(CommonDataKinds.Organization.DATA5)
|
val company = contentValues.getAsString(CommonDataKinds.Organization.DATA1) ?: ""
|
||||||
val jobPosition = contentValues.getAsString(CommonDataKinds.Organization.DATA4)
|
val jobPosition = contentValues.getAsString(CommonDataKinds.Organization.DATA4) ?: ""
|
||||||
contact!!.organization = Organization(company, jobPosition)
|
contact!!.organization = Organization(company, jobPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseEvent(contentValues: ContentValues) {
|
private fun parseEvent(contentValues: ContentValues) {
|
||||||
val type = contentValues.getAsInteger(CommonDataKinds.Event.DATA2) ?: DEFAULT_EVENT_TYPE
|
val type = contentValues.getAsInteger(CommonDataKinds.Event.DATA2) ?: DEFAULT_EVENT_TYPE
|
||||||
val eventValue = contentValues.getAsString(CommonDataKinds.Event.DATA1)
|
val eventValue = contentValues.getAsString(CommonDataKinds.Event.DATA1) ?: return
|
||||||
val event = Event(eventValue, type)
|
val event = Event(eventValue, type)
|
||||||
contact!!.events.add(event)
|
contact!!.events.add(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseWebsite(contentValues: ContentValues) {
|
||||||
|
val website = contentValues.getAsString(CommonDataKinds.Website.DATA1) ?: return
|
||||||
|
contact!!.websites.add(website)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseNote(contentValues: ContentValues) {
|
||||||
|
val note = contentValues.getAsString(CommonDataKinds.Note.DATA1) ?: return
|
||||||
|
contact!!.notes = note
|
||||||
|
}
|
||||||
|
|
||||||
private fun startTakePhotoIntent() {
|
private fun startTakePhotoIntent() {
|
||||||
val uri = getCachePhotoUri()
|
val uri = getCachePhotoUri()
|
||||||
lastPhotoIntentUri = uri
|
lastPhotoIntentUri = uri
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.simplemobiletools.contacts.helpers
|
package com.simplemobiletools.contacts.helpers
|
||||||
|
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds
|
||||||
|
|
||||||
// shared prefs
|
// shared prefs
|
||||||
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
|
||||||
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
|
const val SHOW_PHONE_NUMBERS = "show_phone_numbers"
|
||||||
|
@ -84,3 +86,10 @@ const val SHOW_ORGANIZATION_FIELD = 1024
|
||||||
const val SHOW_GROUPS_FIELD = 2048
|
const val SHOW_GROUPS_FIELD = 2048
|
||||||
const val SHOW_CONTACT_SOURCE_FIELD = 4096
|
const val SHOW_CONTACT_SOURCE_FIELD = 4096
|
||||||
const val SHOW_WEBSITES_FIELD = 8192
|
const val SHOW_WEBSITES_FIELD = 8192
|
||||||
|
|
||||||
|
const val DEFAULT_EMAIL_TYPE = CommonDataKinds.Email.TYPE_HOME
|
||||||
|
const val DEFAULT_PHONE_NUMBER_TYPE = CommonDataKinds.Phone.TYPE_MOBILE
|
||||||
|
const val DEFAULT_ADDRESS_TYPE = CommonDataKinds.StructuredPostal.TYPE_HOME
|
||||||
|
const val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
||||||
|
const val DEFAULT_ORGANIZATION_TYPE = CommonDataKinds.Organization.TYPE_WORK
|
||||||
|
const val DEFAULT_WEBSITE_TYPE = CommonDataKinds.Website.TYPE_HOMEPAGE
|
||||||
|
|
|
@ -839,9 +839,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
||||||
withSelection(selection, selectionArgs)
|
withSelection(selection, selectionArgs)
|
||||||
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
|
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
|
||||||
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
|
withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE)
|
||||||
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
|
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
|
||||||
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
|
withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +859,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
|
withValue(ContactsContract.Data.RAW_CONTACT_ID, contact.id)
|
||||||
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
|
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
|
||||||
withValue(CommonDataKinds.Website.URL, it)
|
withValue(CommonDataKinds.Website.URL, it)
|
||||||
withValue(CommonDataKinds.Website.TYPE, CommonDataKinds.Website.TYPE_HOMEPAGE)
|
withValue(CommonDataKinds.Website.TYPE, DEFAULT_WEBSITE_TYPE)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1064,9 +1064,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||||
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
||||||
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
|
withValue(CommonDataKinds.Organization.COMPANY, contact.organization.company)
|
||||||
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
|
withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE)
|
||||||
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
|
withValue(CommonDataKinds.Organization.TITLE, contact.organization.jobPosition)
|
||||||
withValue(CommonDataKinds.Organization.TYPE, CommonDataKinds.Organization.TYPE_WORK)
|
withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,7 +1076,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
||||||
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||||
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
|
withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Website.CONTENT_ITEM_TYPE)
|
||||||
withValue(CommonDataKinds.Website.URL, it)
|
withValue(CommonDataKinds.Website.URL, it)
|
||||||
withValue(CommonDataKinds.Website.TYPE, CommonDataKinds.Website.TYPE_HOMEPAGE)
|
withValue(CommonDataKinds.Website.TYPE, DEFAULT_WEBSITE_TYPE)
|
||||||
operations.add(build())
|
operations.add(build())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue