fix #155, add an Open With button at the Edit screen too

This commit is contained in:
tibbi 2018-04-29 10:44:14 +02:00
parent 8cc0cb4a58
commit ae9edf819e
5 changed files with 24 additions and 8 deletions

View File

@ -87,6 +87,7 @@ class EditContactActivity : ContactActivity() {
if (wasActivityInitialized) {
menu.findItem(R.id.delete).isVisible = contact?.id != 0
menu.findItem(R.id.share).isVisible = contact?.id != 0
menu.findItem(R.id.open_with).isVisible = contact?.id != 0 && contact?.source != SMT_PRIVATE
}
return true
}
@ -94,8 +95,9 @@ class EditContactActivity : ContactActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.save -> saveContact()
R.id.delete -> deleteContact()
R.id.share -> shareContact()
R.id.open_with -> openWith()
R.id.delete -> deleteContact()
else -> return super.onOptionsItemSelected(item)
}
return true
@ -224,6 +226,14 @@ class EditContactActivity : ContactActivity() {
invalidateOptionsMenu()
}
private fun openWith() {
Intent().apply {
action = Intent.ACTION_EDIT
data = getContactPublicUri(contact!!)
startActivity(this)
}
}
private fun startCropPhotoIntent(uri: Uri?) {
if (uri == null) {
toast(R.string.unknown_error_occurred)

View File

@ -17,6 +17,7 @@ import com.simplemobiletools.contacts.adapters.SelectContactsAdapter
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.getContactPublicUri
import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.helpers.SMT_PRIVATE
import com.simplemobiletools.contacts.models.Contact
@ -135,8 +136,7 @@ class SelectContactActivity : SimpleActivity() {
Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, contactId)
}
else -> {
val lookupKey = ContactsHelper(this).getContactLookupKey(contact.id.toString())
Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
getContactPublicUri(contact)
}
}
}

View File

@ -2,7 +2,6 @@ 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
@ -158,12 +157,9 @@ class ViewContactActivity : ContactActivity() {
}
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
data = getContactPublicUri(contact!!)
startActivity(this)
}
}

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.extensions
import android.content.Intent
import android.net.Uri
import android.provider.ContactsContract
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.sharePathIntent
@ -175,3 +176,8 @@ fun BaseSimpleActivity.removeContactsFromGroup(contacts: ArrayList<Contact>, gro
dbHelper.removeContactsFromGroup(contacts, groupId)
}
}
fun BaseSimpleActivity.getContactPublicUri(contact: Contact): Uri {
val lookupKey = ContactsHelper(this).getContactLookupKey(contact.id.toString())
return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
}

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"