Merge pull request #588 from ismailnurudeen/fix/dialer-issues

Fix/dialer shortcut & call confirmation dialog
This commit is contained in:
Tibor Kaputa 2023-04-19 16:04:14 +02:00 committed by GitHub
commit 79407efbb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import android.view.ViewConfiguration
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.contacts.Contact
@ -287,7 +288,14 @@ class DialpadActivity : SimpleActivity() {
})
ContactsAdapter(this, filtered, dialpad_list, null, text) {
startCallIntent((it as Contact).phoneNumbers.first().normalizedNumber)
val contact = it as Contact
if (config.showCallConfirmation) {
CallConfirmationDialog(this@DialpadActivity, contact.getNameToDisplay()) {
startCallIntent(contact.getPrimaryNumber() ?: return@CallConfirmationDialog)
}
} else {
startCallIntent(contact.getPrimaryNumber() ?: return@ContactsAdapter)
}
}.apply {
dialpad_list.adapter = this
}
@ -306,9 +314,21 @@ class DialpadActivity : SimpleActivity() {
private fun initCall(number: String = dialpad_input.value, handleIndex: Int) {
if (number.isNotEmpty()) {
if (handleIndex != -1 && areMultipleSIMsAvailable()) {
callContactWithSim(number, handleIndex == 0)
if (config.showCallConfirmation) {
CallConfirmationDialog(this, number) {
callContactWithSim(number, handleIndex == 0)
}
}else{
callContactWithSim(number, handleIndex == 0)
}
} else {
startCallIntent(number)
if (config.showCallConfirmation) {
CallConfirmationDialog(this, number) {
startCallIntent(number)
}
}else{
startCallIntent(number)
}
}
}
}

View File

@ -224,9 +224,7 @@ class ContactsAdapter(
private fun getSelectedItems() = contacts.filter { selectedKeys.contains(it.rawId) } as ArrayList<Contact>
private fun getSelectedPhoneNumber(): String? {
val numbers = getSelectedItems().firstOrNull()?.phoneNumbers
val primaryNumber = numbers?.firstOrNull { it.isPrimary }
return primaryNumber?.normalizedNumber ?: numbers?.firstOrNull()?.normalizedNumber
return getSelectedItems().firstOrNull()?.getPrimaryNumber()
}
private fun tryCreateShortcut() {
@ -247,7 +245,7 @@ class ContactsAdapter(
activity.handlePermission(PERMISSION_CALL_PHONE) { hasPermission ->
val action = if (hasPermission) Intent.ACTION_CALL else Intent.ACTION_DIAL
val intent = Intent(action).apply {
data = Uri.fromParts("tel", contact.phoneNumbers.first().normalizedNumber, null)
data = Uri.fromParts("tel", getSelectedPhoneNumber(), null)
}
val shortcut = ShortcutInfo.Builder(activity, contact.hashCode().toString())