mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
fix #318, handle some new cases of adding numbers to contacts
This commit is contained in:
@ -164,36 +164,21 @@ class EditContactActivity : ContactActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val action = intent.action
|
val action = intent.action
|
||||||
if ((contact!!.id == 0 && intent.extras != null && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) {
|
if (((contact!!.id == 0 && action == Intent.ACTION_INSERT) || action == ADD_NEW_CONTACT_NUMBER) && intent.extras != null) {
|
||||||
val phone = intent.extras.get(KEY_PHONE)
|
val phoneNumber = getPhoneNumberFromIntent(intent)
|
||||||
if (phone != null) {
|
if (phoneNumber != null) {
|
||||||
val phoneNumber = phone.toString()
|
|
||||||
contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, "", phoneNumber.normalizeNumber()))
|
contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, "", phoneNumber.normalizeNumber()))
|
||||||
if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) {
|
if (phoneNumber.isNotEmpty() && action == ADD_NEW_CONTACT_NUMBER) {
|
||||||
highlightLastPhoneNumber = true
|
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)
|
val firstName = intent.extras!!.get(KEY_NAME)
|
||||||
if (firstName != null) {
|
if (firstName != null) {
|
||||||
contact!!.firstName = firstName.toString()
|
contact!!.firstName = firstName.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val data = intent.extras.getParcelableArrayList<ContentValues>("data")
|
val data = intent.extras!!.getParcelableArrayList<ContentValues>("data")
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
parseIntentData(data)
|
parseIntentData(data)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
|||||||
Intent().apply {
|
Intent().apply {
|
||||||
action = Intent.ACTION_INSERT
|
action = Intent.ACTION_INSERT
|
||||||
data = ContactsContract.Contacts.CONTENT_URI
|
data = ContactsContract.Contacts.CONTENT_URI
|
||||||
putExtra(KEY_PHONE, intent.getStringExtra(KEY_PHONE))
|
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
|
||||||
if (resolveActivity(packageManager) != null) {
|
if (resolveActivity(packageManager) != null) {
|
||||||
startActivityForResult(this, START_INSERT_ACTIVITY)
|
startActivityForResult(this, START_INSERT_ACTIVITY)
|
||||||
} else {
|
} else {
|
||||||
@ -62,7 +62,7 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
|||||||
Intent(applicationContext, EditContactActivity::class.java).apply {
|
Intent(applicationContext, EditContactActivity::class.java).apply {
|
||||||
data = getContactPublicUri(it as Contact)
|
data = getContactPublicUri(it as Contact)
|
||||||
action = ADD_NEW_CONTACT_NUMBER
|
action = ADD_NEW_CONTACT_NUMBER
|
||||||
putExtra(KEY_PHONE, intent.getStringExtra(KEY_PHONE))
|
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
|
||||||
startActivityForResult(this, START_EDIT_ACTIVITY)
|
startActivityForResult(this, START_EDIT_ACTIVITY)
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.simplemobiletools.contacts.pro.activities
|
package com.simplemobiletools.contacts.pro.activities
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.content.Intent
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
|
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
|
||||||
|
|
||||||
open class SimpleActivity : BaseSimpleActivity() {
|
open class SimpleActivity : BaseSimpleActivity() {
|
||||||
override fun getAppIconIDs() = arrayListOf(
|
override fun getAppIconIDs() = arrayListOf(
|
||||||
@ -27,4 +30,21 @@ open class SimpleActivity : BaseSimpleActivity() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
|
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
|
||||||
|
|
||||||
|
protected fun getPhoneNumberFromIntent(intent: Intent): String? {
|
||||||
|
if (intent.extras?.containsKey(KEY_PHONE) == true) {
|
||||||
|
return intent.getStringExtra(KEY_PHONE)
|
||||||
|
} else if (intent.extras?.containsKey("data") == true) {
|
||||||
|
// 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")) {
|
||||||
|
return contentValues.getAsString("data1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user