handle call/sms/email actions if a contact has multiple emails/numbers
This commit is contained in:
parent
6b201213a4
commit
2ffcc10c19
|
@ -17,11 +17,16 @@ import com.bumptech.glide.request.RequestListener
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.bumptech.glide.request.target.Target
|
import com.bumptech.glide.request.target.Target
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||||
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CONTACTS
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CONTACTS
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.contacts.R
|
import com.simplemobiletools.contacts.R
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
|
import com.simplemobiletools.contacts.extensions.sendEmailIntent
|
||||||
|
import com.simplemobiletools.contacts.extensions.sendSMSIntent
|
||||||
|
import com.simplemobiletools.contacts.extensions.tryStartCall
|
||||||
import com.simplemobiletools.contacts.helpers.CONTACT_ID
|
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
|
||||||
|
@ -116,9 +121,9 @@ class ContactActivity : SimpleActivity() {
|
||||||
contact_email_add_new.background.applyColorFilter(textColor)
|
contact_email_add_new.background.applyColorFilter(textColor)
|
||||||
|
|
||||||
contact_photo.setOnClickListener { }
|
contact_photo.setOnClickListener { }
|
||||||
//contact_send_sms.setOnClickListener { sendSMSIntent(contact!!.number) }
|
contact_send_sms.setOnClickListener { trySendSMS() }
|
||||||
//contact_start_call.setOnClickListener { startCallIntent(contact!!.number) }
|
contact_start_call.setOnClickListener { tryStartCall(contact!!) }
|
||||||
//contact_send_email.setOnClickListener { sendEmailIntent(contact!!.email) }
|
contact_send_email.setOnClickListener { trySendEmail() }
|
||||||
contact_source.setOnClickListener { showAccountSourcePicker() }
|
contact_source.setOnClickListener { showAccountSourcePicker() }
|
||||||
contact_number_add_new.setOnClickListener { addNewPhoneNumberField() }
|
contact_number_add_new.setOnClickListener { addNewPhoneNumberField() }
|
||||||
contact_email_add_new.setOnClickListener { addNewEmailField() }
|
contact_email_add_new.setOnClickListener { addNewEmailField() }
|
||||||
|
@ -230,6 +235,38 @@ class ContactActivity : SimpleActivity() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun trySendSMS() {
|
||||||
|
val numbers = contact!!.phoneNumbers
|
||||||
|
if (numbers.size == 1) {
|
||||||
|
sendSMSIntent(numbers.first().value)
|
||||||
|
} else if (numbers.size > 1) {
|
||||||
|
val items = ArrayList<RadioItem>()
|
||||||
|
numbers.forEachIndexed { index, phoneNumber ->
|
||||||
|
items.add(RadioItem(index, phoneNumber.value, phoneNumber.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
RadioGroupDialog(this, items) {
|
||||||
|
sendSMSIntent(it as String)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun trySendEmail() {
|
||||||
|
val emails = contact!!.emails
|
||||||
|
if (emails.size == 1) {
|
||||||
|
sendEmailIntent(emails.first().value)
|
||||||
|
} else if (emails.size > 1) {
|
||||||
|
val items = ArrayList<RadioItem>()
|
||||||
|
emails.forEachIndexed { index, email ->
|
||||||
|
items.add(RadioItem(index, email.value, email.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
RadioGroupDialog(this, items) {
|
||||||
|
sendEmailIntent(it as String)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getEmailTextId(type: Int) = when (type) {
|
private fun getEmailTextId(type: Int) = when (type) {
|
||||||
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
|
ContactsContract.CommonDataKinds.Email.TYPE_HOME -> R.string.home
|
||||||
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
|
ContactsContract.CommonDataKinds.Email.TYPE_WORK -> R.string.work
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.simplemobiletools.contacts.activities
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
@ -16,7 +15,7 @@ import com.simplemobiletools.contacts.dialogs.ChangeSortingDialog
|
||||||
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
import com.simplemobiletools.contacts.dialogs.FilterContactSourcesDialog
|
||||||
import com.simplemobiletools.contacts.extensions.config
|
import com.simplemobiletools.contacts.extensions.config
|
||||||
import com.simplemobiletools.contacts.extensions.openContact
|
import com.simplemobiletools.contacts.extensions.openContact
|
||||||
import com.simplemobiletools.contacts.extensions.startCallIntent
|
import com.simplemobiletools.contacts.extensions.tryStartCall
|
||||||
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.*
|
||||||
|
@ -164,7 +163,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
ContactsAdapter(this, contacts, this, contacts_list) {
|
ContactsAdapter(this, contacts, this, contacts_list) {
|
||||||
if (config.callContact) {
|
if (config.callContact) {
|
||||||
//startCallIntent((it as Contact).number)
|
tryStartCall(it as Contact)
|
||||||
} else {
|
} else {
|
||||||
openContact(it as Contact)
|
openContact(it as Contact)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,12 @@ package com.simplemobiletools.contacts.extensions
|
||||||
import android.content.Intent
|
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.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
|
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.contacts.activities.SimpleActivity
|
import com.simplemobiletools.contacts.activities.SimpleActivity
|
||||||
|
import com.simplemobiletools.contacts.models.Contact
|
||||||
|
|
||||||
fun SimpleActivity.startCallIntent(recipient: String) {
|
fun SimpleActivity.startCallIntent(recipient: String) {
|
||||||
handlePermission(PERMISSION_CALL_PHONE) {
|
handlePermission(PERMISSION_CALL_PHONE) {
|
||||||
|
@ -21,3 +24,19 @@ fun SimpleActivity.startCallIntent(recipient: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun SimpleActivity.tryStartCall(contact: Contact) {
|
||||||
|
val numbers = contact.phoneNumbers
|
||||||
|
if (numbers.size == 1) {
|
||||||
|
startCallIntent(numbers.first().value)
|
||||||
|
} else if (numbers.size > 1) {
|
||||||
|
val items = ArrayList<RadioItem>()
|
||||||
|
numbers.forEachIndexed { index, phoneNumber ->
|
||||||
|
items.add(RadioItem(index, phoneNumber.value, phoneNumber.value))
|
||||||
|
}
|
||||||
|
|
||||||
|
RadioGroupDialog(this, items) {
|
||||||
|
startCallIntent(it as String)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
style="@style/MyBorderlessBackgroundStyle"
|
style="@style/MyBorderlessBackgroundStyle"
|
||||||
android:layout_width="@dimen/contact_actions_size"
|
android:layout_width="@dimen/contact_actions_size"
|
||||||
android:layout_height="@dimen/contact_actions_size"
|
android:layout_height="@dimen/contact_actions_size"
|
||||||
android:layout_marginRight="@dimen/activity_margin"
|
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
@ -42,7 +41,7 @@
|
||||||
style="@style/MyBorderlessBackgroundStyle"
|
style="@style/MyBorderlessBackgroundStyle"
|
||||||
android:layout_width="@dimen/contact_actions_size"
|
android:layout_width="@dimen/contact_actions_size"
|
||||||
android:layout_height="@dimen/contact_actions_size"
|
android:layout_height="@dimen/contact_actions_size"
|
||||||
android:layout_marginRight="@dimen/activity_margin"
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
@ -54,6 +53,7 @@
|
||||||
style="@style/MyBorderlessBackgroundStyle"
|
style="@style/MyBorderlessBackgroundStyle"
|
||||||
android:layout_width="@dimen/contact_actions_size"
|
android:layout_width="@dimen/contact_actions_size"
|
||||||
android:layout_height="@dimen/contact_actions_size"
|
android:layout_height="@dimen/contact_actions_size"
|
||||||
|
android:layout_marginLeft="@dimen/activity_margin"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:paddingLeft="@dimen/activity_margin"
|
android:paddingLeft="@dimen/activity_margin"
|
||||||
android:paddingRight="@dimen/activity_margin"
|
android:paddingRight="@dimen/activity_margin"
|
||||||
|
|
Loading…
Reference in New Issue