From 2f59a847484ed09f2a3745078502ef79c79d6585 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 27 Sep 2018 14:00:55 +0200 Subject: [PATCH] avoid some null extras at third party intents --- .../contacts/activities/EditContactActivity.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 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 2e14cba5..385f155a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -153,14 +153,20 @@ class EditContactActivity : ContactActivity() { setupEditContact() } - if ((contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) { - val phoneNumber = intent.extras.get(KEY_PHONE)?.toString() ?: "" - contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, "")) - if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) { - highlightLastPhoneNumber = true + if ((contact!!.id == 0 && intent.extras != null && intent.extras.containsKey(KEY_PHONE) && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) { + val phone = intent.extras.get(KEY_PHONE) + if (phone != null) { + val phoneNumber = phone.toString() + contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, "")) + if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) { + highlightLastPhoneNumber = true + } } - contact!!.firstName = intent.extras.get(KEY_NAME)?.toString() ?: "" + val firstName = intent.extras.get(KEY_NAME) + if (firstName != null) { + contact!!.firstName = firstName.toString() + } val data = intent.extras.getParcelableArrayList("data") if (data != null) {