From 25d48ba08c632422f35827c266117cc2e937f04c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 13 Apr 2018 20:13:04 +0200 Subject: [PATCH] parse a couple additional fields from WhatsApp Add Contact intent --- .../activities/EditContactActivity.kt | 26 ++++++++++++------- .../contacts/helpers/Constants.kt | 9 +++++++ .../contacts/helpers/ContactsHelper.kt | 12 ++++----- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index ffc236d4..031f561f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -37,11 +37,6 @@ import org.joda.time.format.DateTimeFormat import java.util.* 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_CHOOSE_PHOTO = 2 private val INTENT_CROP_PHOTO = 3 @@ -936,6 +931,8 @@ class EditContactActivity : ContactActivity() { CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE -> parseAddress(it) CommonDataKinds.Organization.CONTENT_ITEM_TYPE -> parseOrganization(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) { 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) contact!!.addresses.add(address) } private fun parseOrganization(contentValues: ContentValues) { - val company = contentValues.getAsString(CommonDataKinds.Organization.DATA5) - val jobPosition = contentValues.getAsString(CommonDataKinds.Organization.DATA4) + val company = contentValues.getAsString(CommonDataKinds.Organization.DATA1) ?: "" + val jobPosition = contentValues.getAsString(CommonDataKinds.Organization.DATA4) ?: "" contact!!.organization = Organization(company, jobPosition) } private fun parseEvent(contentValues: ContentValues) { 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) 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() { val uri = getCachePhotoUri() lastPhotoIntentUri = uri diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index 670aedad..a4f0b9b7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -1,5 +1,7 @@ package com.simplemobiletools.contacts.helpers +import android.provider.ContactsContract.CommonDataKinds + // shared prefs const val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails" 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_CONTACT_SOURCE_FIELD = 4096 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index b88454ed..fc09e35d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -839,9 +839,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) { val selectionArgs = arrayOf(contact.id.toString(), CommonDataKinds.Organization.CONTENT_ITEM_TYPE) withSelection(selection, selectionArgs) 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.TYPE, CommonDataKinds.Organization.TYPE_WORK) + withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) operations.add(build()) } @@ -859,7 +859,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { 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) + withValue(CommonDataKinds.Website.TYPE, DEFAULT_WEBSITE_TYPE) operations.add(build()) } } @@ -1064,9 +1064,9 @@ class ContactsHelper(val activity: BaseSimpleActivity) { withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE) 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.TYPE, CommonDataKinds.Organization.TYPE_WORK) + withValue(CommonDataKinds.Organization.TYPE, DEFAULT_ORGANIZATION_TYPE) operations.add(build()) } @@ -1076,7 +1076,7 @@ class ContactsHelper(val activity: BaseSimpleActivity) { 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) + withValue(CommonDataKinds.Website.TYPE, DEFAULT_WEBSITE_TYPE) operations.add(build()) } }