handle ahandle a new way of creating new contacts from numbers

This commit is contained in:
tibbi 2018-11-29 20:45:13 +01:00
parent ff0a08862c
commit b069d2c4b1
1 changed files with 15 additions and 1 deletions

View File

@ -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<Any>)?.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)