properly handle generating contact uri for local contacts

This commit is contained in:
tibbi 2018-11-30 17:18:51 +01:00
parent 8fa8e05a7c
commit a8c3dcf23a
3 changed files with 14 additions and 7 deletions

View File

@ -128,7 +128,11 @@ class EditContactActivity : ContactActivity() {
val data = intent.data
if (data != null) {
val rawId = if (data.path.contains("lookup")) {
getLookupUriRawId(data)
if (data.pathSegments.last().startsWith("local_")) {
data.path.substringAfter("local_").toInt()
} else {
getLookupUriRawId(data)
}
} else {
getContactUriRawId(data)
}

View File

@ -13,10 +13,7 @@ import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ContactsAdapter
import com.simplemobiletools.contacts.pro.extensions.config
import com.simplemobiletools.contacts.pro.extensions.getContactPublicUri
import com.simplemobiletools.contacts.pro.helpers.ADD_NEW_CONTACT_NUMBER
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
import com.simplemobiletools.contacts.pro.helpers.LOCATION_INSERT_OR_EDIT
import com.simplemobiletools.contacts.pro.helpers.*
import com.simplemobiletools.contacts.pro.models.Contact
import kotlinx.android.synthetic.main.activity_insert_edit_contact.*
@ -59,10 +56,12 @@ 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
Intent(applicationContext, EditContactActivity::class.java).apply {
data = getContactPublicUri(it as Contact)
data = getContactPublicUri(contact)
action = ADD_NEW_CONTACT_NUMBER
putExtra(KEY_PHONE, getPhoneNumberFromIntent(intent))
putExtra(IS_PRIVATE, contact.source == SMT_PRIVATE)
startActivityForResult(this, START_EDIT_ACTIVITY)
}
}.apply {

View File

@ -278,7 +278,11 @@ fun Context.removeContactsFromGroup(contacts: ArrayList<Contact>, groupId: Long)
}
fun Context.getContactPublicUri(contact: Contact): Uri {
val lookupKey = ContactsHelper(this).getContactLookupKey(contact.id.toString())
val lookupKey = if (contact.source == SMT_PRIVATE) {
"local_${contact.id}"
} else {
ContactsHelper(this).getContactLookupKey(contact.id.toString())
}
return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
}