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
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.content.res.ResourcesCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.reddit.indicatorfastscroll.FastScrollItemIndicator import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.dialogs.CallConfirmationDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.contacts.Contact import com.simplemobiletools.commons.models.contacts.Contact
@@ -287,7 +288,14 @@ class DialpadActivity : SimpleActivity() {
}) })
ContactsAdapter(this, filtered, dialpad_list, null, text) { 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 { }.apply {
dialpad_list.adapter = this dialpad_list.adapter = this
} }
@@ -306,12 +314,24 @@ class DialpadActivity : SimpleActivity() {
private fun initCall(number: String = dialpad_input.value, handleIndex: Int) { private fun initCall(number: String = dialpad_input.value, handleIndex: Int) {
if (number.isNotEmpty()) { if (number.isNotEmpty()) {
if (handleIndex != -1 && areMultipleSIMsAvailable()) { if (handleIndex != -1 && areMultipleSIMsAvailable()) {
if (config.showCallConfirmation) {
CallConfirmationDialog(this, number) {
callContactWithSim(number, handleIndex == 0) callContactWithSim(number, handleIndex == 0)
}
}else{
callContactWithSim(number, handleIndex == 0)
}
} else {
if (config.showCallConfirmation) {
CallConfirmationDialog(this, number) {
startCallIntent(number)
}
}else{ }else{
startCallIntent(number) startCallIntent(number)
} }
} }
} }
}
private fun speedDial(id: Int): Boolean { private fun speedDial(id: Int): Boolean {
if (dialpad_input.value.length == 1) { if (dialpad_input.value.length == 1) {

View File

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