From 0e115c35af1193eac1d5b6a90d88952cf5b939f9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 31 Dec 2020 16:12:59 +0100 Subject: [PATCH] make sure View Contact Details works on private contacts too --- .../dialer/adapters/ContactsAdapter.kt | 8 +--- .../dialer/extensions/Activity.kt | 39 +++++++++++++++++-- .../dialer/fragments/ContactsFragment.kt | 30 +------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt index 3e59aa46..5fcd6a93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/adapters/ContactsAdapter.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.content.pm.ShortcutInfo import android.graphics.drawable.Icon import android.net.Uri -import android.provider.ContactsContract import android.text.TextUtils import android.util.TypedValue import android.view.Menu @@ -26,6 +25,7 @@ import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.activities.SimpleActivity +import com.simplemobiletools.dialer.extensions.startContactDetailsIntent import com.simplemobiletools.dialer.interfaces.RefreshItemsListener class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList, recyclerView: MyRecyclerView, val refreshItemsListener: RefreshItemsListener? = null, @@ -106,11 +106,7 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList 1000000 && contact.contactId > 1000000 && contact.rawId == contact.contactId && + (isPackageInstalled(simpleContacts) || isPackageInstalled(simpleContactsDebug))) { + Intent().apply { + action = Intent.ACTION_VIEW + putExtra(CONTACT_ID, contact.rawId) + putExtra(IS_PRIVATE, true) + `package` = if (isPackageInstalled(simpleContacts)) simpleContacts else simpleContactsDebug + setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person") + if (resolveActivity(packageManager) != null) { + startActivity(this) + } else { + toast(R.string.no_app_found) + } + } + } else { + ensureBackgroundThread { + val lookupKey = SimpleContactsHelper(this).getContactLookupKey((contact).rawId.toString()) + val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) + runOnUiThread { + launchViewContactIntent(publicUri) + } + } + } +} + // used at devices with multiple SIM cards @SuppressLint("MissingPermission") fun SimpleActivity.getHandleToUse(intent: Intent?, phoneNumber: String, callback: (handle: PhoneAccountHandle) -> Unit) { diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt index f3afd3cb..5c10ced1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.dialer.fragments import android.content.Context import android.content.Intent -import android.net.Uri import android.provider.ContactsContract import android.util.AttributeSet import com.reddit.indicatorfastscroll.FastScrollItemIndicator @@ -14,6 +13,7 @@ import com.simplemobiletools.dialer.R import com.simplemobiletools.dialer.activities.SimpleActivity import com.simplemobiletools.dialer.adapters.ContactsAdapter import com.simplemobiletools.dialer.extensions.config +import com.simplemobiletools.dialer.extensions.startContactDetailsIntent import com.simplemobiletools.dialer.interfaces.RefreshItemsListener import kotlinx.android.synthetic.main.fragment_letters_layout.view.* import java.util.* @@ -101,33 +101,7 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag if (currAdapter == null) { ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this) { val contact = it as SimpleContact - - // handle private contacts differently, only Simple Contacts Pro can open them - val simpleContacts = "com.simplemobiletools.contacts.pro" - val simpleContactsDebug = "com.simplemobiletools.contacts.pro.debug" - if (it.rawId > 1000000 && it.contactId > 1000000 && it.rawId == it.contactId && - (context.isPackageInstalled(simpleContacts) || context.isPackageInstalled(simpleContactsDebug))) { - Intent().apply { - action = Intent.ACTION_VIEW - putExtra(CONTACT_ID, it.rawId) - putExtra(IS_PRIVATE, true) - `package` = if (context.isPackageInstalled(simpleContacts)) simpleContacts else simpleContactsDebug - setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person") - if (resolveActivity(context.packageManager) != null) { - activity?.startActivity(this) - } else { - context.toast(R.string.no_app_found) - } - } - } else { - ensureBackgroundThread { - val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((contact).rawId.toString()) - val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) - activity?.runOnUiThread { - activity!!.launchViewContactIntent(publicUri) - } - } - } + activity?.startContactDetailsIntent(contact) }.apply { fragment_list.adapter = this }