From 0eab858ca30a1a896341f5313acb9afaa005c473 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 18 Sep 2020 22:11:24 +0200 Subject: [PATCH] fix #95, do not require the Contacts permission at local contacts --- .../dialer/fragments/ContactsFragment.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 2a2c1d9a..bef68c09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/fragments/ContactsFragment.kt @@ -104,20 +104,19 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag val currAdapter = fragment_list.adapter if (currAdapter == null) { ContactsAdapter(activity as SimpleActivity, contacts, fragment_list, this) { - val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((it as SimpleContact).rawId.toString()) - val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) + 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 (lookupKey.isEmpty() && it.rawId > 1000000 && it.contactId > 1000000 && it.rawId == it.contactId && + 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(publicUri, "vnd.android.cursor.dir/person") + setDataAndType(ContactsContract.Contacts.CONTENT_LOOKUP_URI, "vnd.android.cursor.dir/person") if (resolveActivity(context.packageManager) != null) { activity?.startActivity(this) } else { @@ -125,6 +124,8 @@ class ContactsFragment(context: Context, attributeSet: AttributeSet) : MyViewPag } } } else { + val lookupKey = SimpleContactsHelper(activity!!).getContactLookupKey((contact).rawId.toString()) + val publicUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey) activity!!.launchViewContactIntent(publicUri) } }.apply {