add an Open With menu button to contacts

This commit is contained in:
tibbi 2018-04-29 10:32:18 +02:00
parent 6d7e28a3b6
commit 8cc0cb4a58
2 changed files with 21 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.activities
import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.provider.ContactsContract
import android.view.Menu
@ -49,13 +50,18 @@ class ViewContactActivity : ContactActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_view_contact, menu)
menu.apply {
findItem(R.id.open_with).isVisible = contact?.source != SMT_PRIVATE
}
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.edit -> editContact(contact!!)
R.id.share -> shareContact()
R.id.open_with -> openWith()
R.id.delete -> deleteContact()
else -> return super.onOptionsItemSelected(item)
}
@ -151,6 +157,17 @@ class ViewContactActivity : ContactActivity() {
setupContactSource()
}
private fun openWith() {
val lookupKey = ContactsHelper(this).getContactLookupKey(contact?.id.toString())
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
Intent().apply {
action = ContactsContract.QuickContact.ACTION_QUICK_CONTACT
data = uri
startActivity(this)
}
}
private fun setupFavorite() {
contact_toggle_favorite.apply {
beVisible()

View file

@ -11,6 +11,10 @@
android:icon="@drawable/ic_share"
android:title="@string/share"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/open_with"
android:title="@string/open_with"
app:showAsAction="never"/>
<item
android:id="@+id/delete"
android:icon="@drawable/ic_delete"