show an Edit actionmenu item if "Call on click" is enabled
This commit is contained in:
parent
ffaea6c686
commit
7373cad71c
|
@ -32,5 +32,5 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.2.14'
|
||||
implementation 'com.simplemobiletools:commons:3.2.15'
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import com.simplemobiletools.contacts.R
|
|||
import com.simplemobiletools.contacts.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.extensions.openContact
|
||||
import com.simplemobiletools.contacts.extensions.startCallIntent
|
||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -126,7 +126,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
if (config.callContact) {
|
||||
startCallIntent((it as Contact).number)
|
||||
} else {
|
||||
itemClicked(it as Contact)
|
||||
openContact(it as Contact)
|
||||
}
|
||||
}.apply {
|
||||
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() {
|
||||
Intent(applicationContext, ContactActivity::class.java).apply {
|
||||
startActivity(this)
|
||||
|
|
|
@ -16,6 +16,8 @@ import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
|
|||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.contacts.R
|
||||
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 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 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) {}
|
||||
|
||||
|
@ -40,6 +46,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
|
||||
override fun actionItemPressed(id: Int) {
|
||||
when (id) {
|
||||
R.id.cab_edit -> editContact()
|
||||
R.id.cab_select_all -> selectAll()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
}
|
||||
|
@ -69,6 +76,11 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
|
|||
finishActMode()
|
||||
}
|
||||
|
||||
private fun editContact() {
|
||||
activity.openContact(contactItems[selectedPositions.first()])
|
||||
finishActMode()
|
||||
}
|
||||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(activity) {
|
||||
deleteContacts()
|
||||
|
|
|
@ -5,10 +5,20 @@ import android.content.Intent
|
|||
import android.net.Uri
|
||||
import com.simplemobiletools.commons.R
|
||||
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.models.Contact
|
||||
|
||||
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) {
|
||||
Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = Uri.fromParts("mailto", recipient, null)
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
android:id="@+id/cab_select_all"
|
||||
android:icon="@drawable/ic_select_all"
|
||||
|
|
Loading…
Reference in New Issue