mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-17 12:00:39 +01:00
fix #166, properly handle intents adding numbers to existing contacts
This commit is contained in:
parent
78240eeb2b
commit
5e5de8b90a
@ -58,7 +58,7 @@ class EditContactActivity : ContactActivity() {
|
|||||||
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
|
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_cross)
|
||||||
|
|
||||||
val action = intent.action
|
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)
|
val isFromSimpleContacts = intent.getBooleanExtra(IS_FROM_SIMPLE_CONTACTS, false)
|
||||||
if (isThirdPartyIntent && !isFromSimpleContacts) {
|
if (isThirdPartyIntent && !isFromSimpleContacts) {
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
@ -119,7 +119,7 @@ class EditContactActivity : ContactActivity() {
|
|||||||
private fun initContact() {
|
private fun initContact() {
|
||||||
var contactId = intent.getIntExtra(CONTACT_ID, 0)
|
var contactId = intent.getIntExtra(CONTACT_ID, 0)
|
||||||
val action = intent.action
|
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
|
val data = intent.data
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
val rawId = if (data.path.contains("lookup")) {
|
val rawId = if (data.path.contains("lookup")) {
|
||||||
@ -149,7 +149,7 @@ class EditContactActivity : ContactActivity() {
|
|||||||
setupEditContact()
|
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() ?: ""
|
val phoneNumber = intent.extras.get(KEY_PHONE)?.toString() ?: ""
|
||||||
contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, ""))
|
contact!!.phoneNumbers.add(PhoneNumber(phoneNumber, DEFAULT_PHONE_NUMBER_TYPE, ""))
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
|||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
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.ContactsHelper
|
||||||
import com.simplemobiletools.contacts.helpers.KEY_PHONE
|
import com.simplemobiletools.contacts.helpers.KEY_PHONE
|
||||||
import com.simplemobiletools.contacts.helpers.LOCATION_INSERT_OR_EDIT
|
import com.simplemobiletools.contacts.helpers.LOCATION_INSERT_OR_EDIT
|
||||||
@ -57,7 +59,12 @@ class InsertOrEditContactActivity : SimpleActivity() {
|
|||||||
contacts.sort()
|
contacts.sort()
|
||||||
|
|
||||||
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
|
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 {
|
}.apply {
|
||||||
addVerticalDividers(true)
|
addVerticalDividers(true)
|
||||||
existing_contact_list.adapter = this
|
existing_contact_list.adapter = this
|
||||||
|
@ -23,6 +23,7 @@ const val GROUP = "group"
|
|||||||
const val FIRST_GROUP_ID = 10000
|
const val FIRST_GROUP_ID = 10000
|
||||||
const val PHONE_NUMBER_PATTERN = "\\D+"
|
const val PHONE_NUMBER_PATTERN = "\\D+"
|
||||||
const val IS_FROM_SIMPLE_CONTACTS = "is_from_simple_contacts"
|
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
|
// extras used at third party intents
|
||||||
const val KEY_PHONE = "phone"
|
const val KEY_PHONE = "phone"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user