fix #464, properly handle some new contact related intents

This commit is contained in:
tibbi
2019-12-05 12:34:46 +01:00
parent 05f239293b
commit f939f77323
5 changed files with 47 additions and 3 deletions

View File

@ -170,6 +170,12 @@
<data android:mimeType="vnd.android.cursor.item/contact"/>
<data android:mimeType="vnd.android.cursor.item/raw_contact"/>
</intent-filter>
<intent-filter>
<action android:name="com.android.contacts.action.SHOW_OR_CREATE_CONTACT"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="mailto"/>
</intent-filter>
</activity>
<activity

View File

@ -47,10 +47,26 @@ class InsertOrEditContactActivity : SimpleActivity() {
updateTextColors(insert_edit_contact_holder)
new_contact_tmb.setImageDrawable(resources.getColoredDrawableWithColor(R.drawable.ic_new_contact_vector, config.textColor))
new_contact_holder.setOnClickListener {
val name = intent.getStringExtra(KEY_NAME) ?: ""
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
Intent().apply {
action = Intent.ACTION_INSERT
data = ContactsContract.Contacts.CONTENT_URI
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
if (name.isNotEmpty()) {
putExtra(KEY_NAME, name)
}
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
if (resolveActivity(packageManager) != null) {
startActivityForResult(this, START_INSERT_ACTIVITY)
} else {
@ -65,10 +81,21 @@ class InsertOrEditContactActivity : SimpleActivity() {
private fun gotContacts(contacts: ArrayList<Contact>) {
ContactsAdapter(this, contacts, null, LOCATION_INSERT_OR_EDIT, null, existing_contact_list, existing_contact_fastscroller) {
val contact = it as Contact
val phoneNumber = getPhoneNumberFromIntent(intent) ?: ""
val email = getEmailFromIntent(intent) ?: ""
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(contact)
action = ADD_NEW_CONTACT_NUMBER
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
if (phoneNumber.isNotEmpty()) {
putExtra(KEY_PHONE, phoneNumber)
}
if (email.isNotEmpty()) {
putExtra(KEY_EMAIL, email)
}
putExtra(IS_PRIVATE, contact.isPrivate())
startActivityForResult(this, START_EDIT_ACTIVITY)
}

View File

@ -3,11 +3,13 @@ package com.simplemobiletools.contacts.pro.activities
import android.annotation.TargetApi
import android.content.ContentValues
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.telecom.TelecomManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.helpers.KEY_MAILTO
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
import com.simplemobiletools.contacts.pro.helpers.REQUEST_CODE_SET_DEFAULT_DIALER
@ -53,6 +55,14 @@ open class SimpleActivity : BaseSimpleActivity() {
return null
}
protected fun getEmailFromIntent(intent: Intent): String? {
return if (intent.dataString?.startsWith("$KEY_MAILTO:") == true) {
Uri.decode(intent.dataString!!.substringAfter("$KEY_MAILTO:").trim())
} else {
null
}
}
@TargetApi(Build.VERSION_CODES.M)
protected fun launchSetDefaultDialerIntent() {
Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName).apply {

View File

@ -66,7 +66,7 @@ fun Context.editContact(contact: Contact) {
fun Context.sendEmailIntent(recipient: String) {
Intent(Intent.ACTION_SENDTO).apply {
data = Uri.fromParts("mailto", recipient, null)
data = Uri.fromParts(KEY_MAILTO, recipient, null)
if (resolveActivity(packageManager) != null) {
startActivity(this)
} else {

View File

@ -31,6 +31,7 @@ const val REQUEST_CODE_SET_DEFAULT_DIALER = 1
const val KEY_PHONE = "phone"
const val KEY_NAME = "name"
const val KEY_EMAIL = "email"
const val KEY_MAILTO = "mailto"
const val LOCATION_CONTACTS_TAB = 0
const val LOCATION_FAVORITES_TAB = 1