Merge pull request #994 from Merkost/master

Extracted call functions in commons library
This commit is contained in:
Tibor Kaputa 2023-06-29 14:43:30 +02:00 committed by GitHub
commit a2257344ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 34 deletions

View file

@ -236,7 +236,7 @@ class ViewContactActivity : ContactActivity() {
}
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_sms.setOnLongClickListener { toast(R.string.send_sms); true; }

View file

@ -4,7 +4,6 @@ import android.app.Activity
import android.content.Intent
import android.net.Uri
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
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) {
ContactsHelper(this).getSaveableContactSources { sources ->
val items = ArrayList<RadioItem>()
@ -116,7 +84,7 @@ fun SimpleActivity.handleGenericContactClick(contact: Contact) {
fun SimpleActivity.callContact(contact: Contact) {
hideKeyboard()
if (contact.phoneNumbers.isNotEmpty()) {
tryStartCall(contact)
tryInitiateCall(contact) { startCallIntent(it) }
} else {
toast(R.string.no_phone_number_found)
}