fix #166, properly handle intents adding numbers to existing contacts

This commit is contained in:
tibbi 2018-09-26 23:02:23 +02:00
parent 78240eeb2b
commit 5e5de8b90a
3 changed files with 12 additions and 4 deletions

View File

@ -58,7 +58,7 @@ class EditContactActivity : ContactActivity() {
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
val action = intent.action
isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT
isThirdPartyIntent = action == Intent.ACTION_EDIT || action == Intent.ACTION_INSERT || action == ADD_NEW_CONTACT_NUMBER
val isFromSimpleContacts = intent.getBooleanExtra(IS_FROM_SIMPLE_CONTACTS, false)
if (isThirdPartyIntent && !isFromSimpleContacts) {
handlePermission(PERMISSION_READ_CONTACTS) {
@ -119,7 +119,7 @@ class EditContactActivity : ContactActivity() {
private fun initContact() {
var contactId = intent.getIntExtra(CONTACT_ID, 0)
val action = intent.action
if (contactId == 0 && action == Intent.ACTION_EDIT) {
if (contactId == 0 && (action == Intent.ACTION_EDIT || action == ADD_NEW_CONTACT_NUMBER)) {
val data = intent.data
if (data != null) {
val rawId = if (data.path.contains("lookup")) {
@ -149,7 +149,7 @@ class EditContactActivity : ContactActivity() {
setupEditContact()
}
if (contact!!.id == 0 && intent.extras?.containsKey(KEY_PHONE) == true && action == Intent.ACTION_INSERT) {
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, ""))

View File

@ -11,6 +11,8 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.adapters.ContactsAdapter
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.getContactPublicUri
import com.simplemobiletools.contacts.helpers.ADD_NEW_CONTACT_NUMBER
import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.helpers.KEY_PHONE
import com.simplemobiletools.contacts.helpers.LOCATION_INSERT_OR_EDIT
@ -57,7 +59,12 @@ class InsertOrEditContactActivity : SimpleActivity() {
contacts.sort()
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(it as Contact)
action = ADD_NEW_CONTACT_NUMBER
putExtra(KEY_PHONE, intent.getStringExtra(KEY_PHONE))
startActivity(this)
}
}.apply {
addVerticalDividers(true)
existing_contact_list.adapter = this

View File

@ -23,6 +23,7 @@ const val GROUP = "group"
const val FIRST_GROUP_ID = 10000
const val PHONE_NUMBER_PATTERN = "\\D+"
const val IS_FROM_SIMPLE_CONTACTS = "is_from_simple_contacts"
const val ADD_NEW_CONTACT_NUMBER = "add_new_contact_number"
// extras used at third party intents
const val KEY_PHONE = "phone"