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