show an Edit actionmenu item if "Call on click" is enabled

This commit is contained in:
tibbi 2017-12-11 22:35:52 +01:00
parent ffaea6c686
commit 7373cad71c
5 changed files with 31 additions and 11 deletions

View file

@ -32,5 +32,5 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:3.2.14' implementation 'com.simplemobiletools:commons:3.2.15'
} }

View file

@ -17,8 +17,8 @@ import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.adapters.ContactsAdapter import com.simplemobiletools.contacts.adapters.ContactsAdapter
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
import com.simplemobiletools.contacts.extensions.config import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.openContact
import com.simplemobiletools.contacts.extensions.startCallIntent import com.simplemobiletools.contacts.extensions.startCallIntent
import com.simplemobiletools.contacts.helpers.CONTACT_ID
import com.simplemobiletools.contacts.helpers.ContactsHelper import com.simplemobiletools.contacts.helpers.ContactsHelper
import com.simplemobiletools.contacts.models.Contact import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
@ -126,7 +126,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
if (config.callContact) { if (config.callContact) {
startCallIntent((it as Contact).number) startCallIntent((it as Contact).number)
} else { } else {
itemClicked(it as Contact) openContact(it as Contact)
} }
}.apply { }.apply {
setupDragListener(true) setupDragListener(true)
@ -143,13 +143,6 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
} }
private fun itemClicked(contact: Contact) {
Intent(applicationContext, ContactActivity::class.java).apply {
putExtra(CONTACT_ID, contact.id)
startActivity(this)
}
}
private fun addNewContact() { private fun addNewContact() {
Intent(applicationContext, ContactActivity::class.java).apply { Intent(applicationContext, ContactActivity::class.java).apply {
startActivity(this) startActivity(this)

View file

@ -16,6 +16,8 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.commons.views.MyRecyclerView
import com.simplemobiletools.contacts.R import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.openContact
import com.simplemobiletools.contacts.models.Contact import com.simplemobiletools.contacts.models.Contact
import kotlinx.android.synthetic.main.item_contact.view.* import kotlinx.android.synthetic.main.item_contact.view.*
@ -30,7 +32,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
override fun getActionMenuId() = R.menu.cab override fun getActionMenuId() = R.menu.cab
override fun prepareActionMode(menu: Menu) {} override fun prepareActionMode(menu: Menu) {
menu.apply {
findItem(R.id.cab_edit).isVisible = activity.config.callContact && isOneItemSelected()
}
}
override fun prepareItemSelection(view: View) {} override fun prepareItemSelection(view: View) {}
@ -40,6 +46,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
when (id) { when (id) {
R.id.cab_edit -> editContact()
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_delete -> askConfirmDelete() R.id.cab_delete -> askConfirmDelete()
} }
@ -69,6 +76,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
finishActMode() finishActMode()
} }
private fun editContact() {
activity.openContact(contactItems[selectedPositions.first()])
finishActMode()
}
private fun askConfirmDelete() { private fun askConfirmDelete() {
ConfirmationDialog(activity) { ConfirmationDialog(activity) {
deleteContacts() deleteContacts()

View file

@ -5,10 +5,20 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import com.simplemobiletools.commons.R import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.contacts.activities.ContactActivity
import com.simplemobiletools.contacts.helpers.CONTACT_ID
import com.simplemobiletools.contacts.helpers.Config import com.simplemobiletools.contacts.helpers.Config
import com.simplemobiletools.contacts.models.Contact
val Context.config: Config get() = Config.newInstance(applicationContext) val Context.config: Config get() = Config.newInstance(applicationContext)
fun Context.openContact(contact: Contact) {
Intent(applicationContext, ContactActivity::class.java).apply {
putExtra(CONTACT_ID, contact.id)
startActivity(this)
}
}
fun Context.sendEmailIntent(recipient: String) { fun Context.sendEmailIntent(recipient: String) {
Intent(Intent.ACTION_SENDTO).apply { Intent(Intent.ACTION_SENDTO).apply {
data = Uri.fromParts("mailto", recipient, null) data = Uri.fromParts("mailto", recipient, null)

View file

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_edit"
android:icon="@drawable/ic_rename"
android:title="@string/edit_contact"
app:showAsAction="ifRoom"/>
<item <item
android:id="@+id/cab_select_all" android:id="@+id/cab_select_all"
android:icon="@drawable/ic_select_all" android:icon="@drawable/ic_select_all"