Added support for call transfer to contact with multiple numbers

This commit is contained in:
Juha Heinanen
2023-03-07 07:26:20 +02:00
parent cbd3ae228d
commit 48ef1d4e2a
3 changed files with 50 additions and 26 deletions
@@ -1449,34 +1449,30 @@ class MainActivity : AppCompatActivity() {
var uriText = transferUri.text.toString().trim() var uriText = transferUri.text.toString().trim()
if (uriText.isNotEmpty()) { if (uriText.isNotEmpty()) {
val uris = Contact.contactUris(uriText) val uris = Contact.contactUris(uriText)
if (uris.size >= 1) if (uris.size > 1) {
val destinationBuilder = MaterialAlertDialogBuilder(
this@MainActivity,
R.style.AlertDialogTheme
)
with(destinationBuilder) {
setTitle(R.string.choose_destination_uri)
setItems(uris.toTypedArray()) { _, which ->
uriText = uris[which]
transfer(
ua,
if (Utils.isTelNumber(uriText)) "tel:$uriText" else uriText,
attended.isChecked
)
}
setNeutralButton(getString(R.string.cancel)) { _: DialogInterface, _: Int -> }
show()
}
} else {
if (uris.size == 1)
uriText = uris[0] uriText = uris[0]
if (Utils.isTelNumber(uriText))
uriText = "tel:$uriText"
val uri = if (Utils.isTelUri(uriText))
Utils.telToSip(uriText, ua.account)
else
Utils.uriComplete(uriText, ua.account.aor)
if (!Utils.checkUri(uri)) {
Utils.alertView(this@MainActivity, getString(R.string.notice),
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
} else {
val call = ua.currentCall()
if (call != null) {
if (attended.isChecked) {
if (call.hold()) {
call.referTo = uri
call(ua, uri, call)
}
} else {
if (!call.transfer(uri)) {
Utils.alertView(this@MainActivity, getString(R.string.notice),
String.format(getString(R.string.transfer_failed)))
}
}
showCall(ua)
}
} }
transfer(ua, if (Utils.isTelNumber(uriText)) "tel:$uriText" else uriText,
attended.isChecked)
} }
} }
setNeutralButton(android.R.string.cancel) { dialog, _ -> setNeutralButton(android.R.string.cancel) { dialog, _ ->
@@ -1511,6 +1507,32 @@ class MainActivity : AppCompatActivity() {
alertDialog.show() alertDialog.show()
} }
private fun transfer(ua: UserAgent, uriText: String, attended: Boolean) {
val uri = if (Utils.isTelUri(uriText))
Utils.telToSip(uriText, ua.account)
else
Utils.uriComplete(uriText, ua.account.aor)
if (!Utils.checkUri(uri)) {
Utils.alertView(this@MainActivity, getString(R.string.notice),
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
} else {
val call = ua.currentCall()
if (call != null) {
if (attended) {
if (call.hold()) {
call.referTo = uri
call(ua, uri, call)
}
} else {
if (!call.transfer(uri)) {
Utils.alertView(this@MainActivity, getString(R.string.notice),
String.format(getString(R.string.transfer_failed)))
}
}
showCall(ua)
}
}
}
private fun askPassword(title: String, ua: UserAgent? = null) { private fun askPassword(title: String, ua: UserAgent? = null) {
val layout = LayoutInflater.from(this) val layout = LayoutInflater.from(this)
.inflate(R.layout.password_dialog, findViewById(android.R.id.content), .inflate(R.layout.password_dialog, findViewById(android.R.id.content),
@@ -1767,7 +1789,7 @@ class MainActivity : AppCompatActivity() {
else if (uris.size > 1) { else if (uris.size > 1) {
val builder = MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme) val builder = MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)
with(builder) { with(builder) {
setTitle("Choose Destination") setTitle(R.string.choose_destination_uri)
setItems(uris.toTypedArray()) { _, which -> setItems(uris.toTypedArray()) { _, which ->
callUri.setText(uris[which]) callUri.setText(uris[which])
makeCall(false) makeCall(false)
+1
View File
@@ -479,6 +479,7 @@
<string name="blind">Sokeasti</string> <string name="blind">Sokeasti</string>
<string name="attended">Osallistu</string> <string name="attended">Osallistu</string>
<string name="transfer_destination">Siirron kohde</string> <string name="transfer_destination">Siirron kohde</string>
<string name="choose_destination_uri">Valitse kohteen URI</string>
<string name="transfer">Siirto</string> <string name="transfer">Siirto</string>
<string name="transfer_failed">Siirto epäonnistui</string> <string name="transfer_failed">Siirto epäonnistui</string>
<string name="dtmf">DTMF</string> <string name="dtmf">DTMF</string>
+1
View File
@@ -452,6 +452,7 @@
<string name="blind">Blind</string> <string name="blind">Blind</string>
<string name="attended">Attended</string> <string name="attended">Attended</string>
<string name="transfer_destination">Transfer destination</string> <string name="transfer_destination">Transfer destination</string>
<string name="choose_destination_uri">Choose destination URI</string>
<string name="transfer">Transfer</string> <string name="transfer">Transfer</string>
<string name="transfer_failed">Transfer failed</string> <string name="transfer_failed">Transfer failed</string>
<string name="dtmf">DTMF</string> <string name="dtmf">DTMF</string>