@@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.activities
22
33import android.app.DatePickerDialog
44import android.content.ClipData
5+ import android.content.ContentValues
56import android.content.Intent
67import android.graphics.drawable.ColorDrawable
78import android.net.Uri
@@ -151,10 +152,14 @@ class EditContactActivity : ContactActivity() {
151152 if (contact!! .id == 0 && intent.extras?.containsKey(KEY_PHONE ) == true && (action == Intent .ACTION_INSERT_OR_EDIT || action == Intent .ACTION_INSERT )) {
152153 val phoneNumber = intent.extras.get(KEY_PHONE )?.toString() ? : " "
153154 contact!! .phoneNumbers.add(PhoneNumber (phoneNumber, DEFAULT_PHONE_NUMBER_TYPE ))
154- setupPhoneNumbers()
155155
156- val contactFullName = intent.extras.get(KEY_NAME )?.toString() ? : " "
157- contact_first_name.setText(contactFullName)
156+ contact!! .firstName = intent.extras.get(KEY_NAME )?.toString() ? : " "
157+
158+ val data = intent.extras.getParcelableArrayList<ContentValues >(" data" )
159+ if (data != null ) {
160+ parseIntentData(data)
161+ }
162+ setupEditContact()
158163 }
159164
160165 setupTypePickers()
@@ -308,14 +313,8 @@ class EditContactActivity : ContactActivity() {
308313 private fun setupEditContact () {
309314 window.setSoftInputMode(WindowManager .LayoutParams .SOFT_INPUT_STATE_ALWAYS_HIDDEN )
310315 supportActionBar?.title = resources.getString(R .string.edit_contact)
311- contact_prefix.setText(contact!! .prefix)
312- contact_first_name.setText(contact!! .firstName)
313- contact_middle_name.setText(contact!! .middleName)
314- contact_surname.setText(contact!! .surname)
315- contact_suffix.setText(contact!! .suffix)
316-
317- contact_source.text = getPublicContactSource(contact!! .source)
318316
317+ setupNames()
319318 setupPhoneNumbers()
320319 setupEmails()
321320 setupAddresses()
@@ -324,6 +323,17 @@ class EditContactActivity : ContactActivity() {
324323 setupWebsites()
325324 setupEvents()
326325 setupGroups()
326+ setupContactSource()
327+ }
328+
329+ private fun setupNames () {
330+ contact!! .apply {
331+ contact_prefix.setText(prefix)
332+ contact_first_name.setText(firstName)
333+ contact_middle_name.setText(middleName)
334+ contact_surname.setText(surname)
335+ contact_suffix.setText(suffix)
336+ }
327337 }
328338
329339 private fun setupPhoneNumbers () {
@@ -487,6 +497,10 @@ class EditContactActivity : ContactActivity() {
487497 }
488498 }
489499
500+ private fun setupContactSource () {
501+ contact_source.text = getPublicContactSource(contact!! .source)
502+ }
503+
490504 private fun setupNewContact () {
491505 supportActionBar?.title = resources.getString(R .string.new_contact)
492506 val contactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
@@ -915,6 +929,44 @@ class EditContactActivity : ContactActivity() {
915929 }
916930 }
917931
932+ private fun parseIntentData (data : ArrayList <ContentValues >) {
933+ data.forEach {
934+ when (it.get(CommonDataKinds .StructuredName .MIMETYPE )) {
935+ CommonDataKinds .Email .CONTENT_ITEM_TYPE -> parseEmail(it)
936+ CommonDataKinds .StructuredPostal .CONTENT_ITEM_TYPE -> parseAddress(it)
937+ CommonDataKinds .Organization .CONTENT_ITEM_TYPE -> parseOrganization(it)
938+ CommonDataKinds .Event .CONTENT_ITEM_TYPE -> parseEvent(it)
939+ }
940+ }
941+ }
942+
943+ private fun parseEmail (contentValues : ContentValues ) {
944+ val type = contentValues.getAsInteger(CommonDataKinds .Email .DATA2 ) ? : DEFAULT_EMAIL_TYPE
945+ val emailValue = contentValues.getAsString(CommonDataKinds .Email .DATA1 ) ? : return
946+ val email = Email (emailValue, type)
947+ contact!! .emails.add(email)
948+ }
949+
950+ private fun parseAddress (contentValues : ContentValues ) {
951+ val type = contentValues.getAsInteger(CommonDataKinds .StructuredPostal .DATA2 ) ? : DEFAULT_ADDRESS_TYPE
952+ val addressValue = contentValues.getAsString(CommonDataKinds .StructuredPostal .DATA4 ) ? : return
953+ val address = Address (addressValue, type)
954+ contact!! .addresses.add(address)
955+ }
956+
957+ private fun parseOrganization (contentValues : ContentValues ) {
958+ val company = contentValues.getAsString(CommonDataKinds .Organization .DATA5 )
959+ val jobPosition = contentValues.getAsString(CommonDataKinds .Organization .DATA4 )
960+ contact!! .organization = Organization (company, jobPosition)
961+ }
962+
963+ private fun parseEvent (contentValues : ContentValues ) {
964+ val type = contentValues.getAsInteger(CommonDataKinds .Event .DATA2 ) ? : DEFAULT_EVENT_TYPE
965+ val eventValue = contentValues.getAsString(CommonDataKinds .Event .DATA1 )
966+ val event = Event (eventValue, type)
967+ contact!! .events.add(event)
968+ }
969+
918970 private fun startTakePhotoIntent () {
919971 val uri = getCachePhotoUri()
920972 lastPhotoIntentUri = uri
0 commit comments