mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-09 16:18:55 +01:00
Merge pull request #994 from Merkost/master
Extracted call functions in commons library
This commit is contained in:
commit
a2257344ee
@ -236,7 +236,7 @@ class ViewContactActivity : ContactActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
contact_send_sms.setOnClickListener { trySendSMS() }
|
contact_send_sms.setOnClickListener { trySendSMS() }
|
||||||
contact_start_call.setOnClickListener { tryStartCall(contact!!) }
|
contact_start_call.setOnClickListener { tryInitiateCall(contact!!) { startCallIntent(it) } }
|
||||||
contact_send_email.setOnClickListener { trySendEmail() }
|
contact_send_email.setOnClickListener { trySendEmail() }
|
||||||
|
|
||||||
contact_send_sms.setOnLongClickListener { toast(R.string.send_sms); true; }
|
contact_send_sms.setOnLongClickListener { toast(R.string.send_sms); true; }
|
||||||
|
@ -4,7 +4,6 @@ import android.app.Activity
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
|
|
||||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
@ -28,37 +27,6 @@ fun SimpleActivity.startCallIntent(recipient: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun SimpleActivity.tryStartCall(contact: Contact) {
|
|
||||||
if (config.showCallConfirmation) {
|
|
||||||
CallConfirmationDialog(this, contact.getNameToDisplay()) {
|
|
||||||
startCall(contact)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
startCall(contact)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun SimpleActivity.startCall(contact: Contact) {
|
|
||||||
val numbers = contact.phoneNumbers
|
|
||||||
if (numbers.size == 1) {
|
|
||||||
startCallIntent(numbers.first().value)
|
|
||||||
} else if (numbers.size > 1) {
|
|
||||||
val primaryNumber = contact.phoneNumbers.find { it.isPrimary }
|
|
||||||
if (primaryNumber != null) {
|
|
||||||
startCallIntent(primaryNumber.value)
|
|
||||||
} else {
|
|
||||||
val items = ArrayList<RadioItem>()
|
|
||||||
numbers.forEachIndexed { index, phoneNumber ->
|
|
||||||
items.add(RadioItem(index, "${phoneNumber.value} (${getPhoneNumberTypeText(phoneNumber.type, phoneNumber.label)})", phoneNumber.value))
|
|
||||||
}
|
|
||||||
|
|
||||||
RadioGroupDialog(this, items) {
|
|
||||||
startCallIntent(it as String)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (newSource: String) -> Unit) {
|
||||||
ContactsHelper(this).getSaveableContactSources { sources ->
|
ContactsHelper(this).getSaveableContactSources { sources ->
|
||||||
val items = ArrayList<RadioItem>()
|
val items = ArrayList<RadioItem>()
|
||||||
@ -116,7 +84,7 @@ fun SimpleActivity.handleGenericContactClick(contact: Contact) {
|
|||||||
fun SimpleActivity.callContact(contact: Contact) {
|
fun SimpleActivity.callContact(contact: Contact) {
|
||||||
hideKeyboard()
|
hideKeyboard()
|
||||||
if (contact.phoneNumbers.isNotEmpty()) {
|
if (contact.phoneNumbers.isNotEmpty()) {
|
||||||
tryStartCall(contact)
|
tryInitiateCall(contact) { startCallIntent(it) }
|
||||||
} else {
|
} else {
|
||||||
toast(R.string.no_phone_number_found)
|
toast(R.string.no_phone_number_found)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user