From b069d2c4b1fffbb0eac5ca6fd48fa6feb0e6a15c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 29 Nov 2018 20:45:13 +0100 Subject: [PATCH] handle ahandle a new way of creating new contacts from numbers --- .../pro/activities/EditContactActivity.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt index 5ce6b5c1..b5bc3492 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt @@ -164,7 +164,7 @@ class EditContactActivity : ContactActivity() { } val action = intent.action - if ((contact!!.id == 0 && intent.extras != null && intent.extras.containsKey(KEY_PHONE) && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) { + if ((contact!!.id == 0 && intent.extras != null && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) { val phone = intent.extras.get(KEY_PHONE) if (phone != null) { val phoneNumber = phone.toString() @@ -172,6 +172,20 @@ class EditContactActivity : ContactActivity() { if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) { highlightLastPhoneNumber = true } + } else { + // sample contact number from Google Contacts: + // data: [data1=+123 456 789 mimetype=vnd.android.cursor.item/phone_v2 _id=-1 data2=0] + val data = intent.extras.get("data") + if (data != null) { + val contentValues = (data as? ArrayList)?.firstOrNull() as? ContentValues + if (contentValues != null && contentValues.containsKey("data1")) { + val phoneNumber = contentValues.getAsString("data1") + contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, "", phoneNumber.normalizeNumber())) + if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) { + highlightLastPhoneNumber = true + } + } + } } val firstName = intent.extras.get(KEY_NAME)