Prompt user for telephony provider account if such is needed to make the call

This commit is contained in:
Juha Heinanen
2022-02-03 11:45:05 +02:00
parent af11b18bd7
commit 5cf189a06a
4 changed files with 29 additions and 28 deletions

View File

@ -198,6 +198,14 @@ class Account(val accp: String) {
return res
}
fun telProviderAccounts(): Array<String> {
val res = ArrayList<String>()
for (account in accounts())
if (account.telProvider != "")
res.add(account.aor.substring(4))
return res.toTypedArray()
}
fun ofAor(aor: String): Account? {
for (ua in UserAgent.uas())
if (ua.account.aor == aor) return ua.account

View File

@ -76,23 +76,9 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
i.putExtra("action", "call")
else
i.putExtra("action", "message")
var ua = UserAgent.ofAor(aor)
val ua = UserAgent.ofAor(aor)
if (ua == null) {
Log.w(TAG, "onClickListener did not find AoR $aor")
} else {
if (Utils.isTelUri(contact.uri) && ua.account.telProvider == "") {
var newUa: UserAgent? = null
for (a in Account.accounts())
if (a.telProvider != "") {
newUa = UserAgent.ofAor(a.aor)
break
}
ua = newUa
}
}
if (ua == null) {
Toast.makeText(ctx, ctx.getString(R.string.no_telephony_providers),
Toast.LENGTH_LONG).show()
} else {
BaresipService.activities.clear()
i.putExtra("uap", ua.uap)

View File

@ -1388,16 +1388,10 @@ class MainActivity : AppCompatActivity() {
uriText = ContactsActivity.findContactUri(uriText) ?: uriText
if (Utils.isTelNumber(uriText))
uriText = "tel:$uriText"
val uri = if (Utils.isTelUri(uriText)) {
if (ua.account.telProvider == "") {
Utils.alertView(this@MainActivity, getString(R.string.notice),
String.format(getString(R.string.no_telephony_provider)))
return@setPositiveButton
}
val uri = if (Utils.isTelUri(uriText))
Utils.telToSip(uriText, ua.account)
} else {
else
Utils.uriComplete(uriText, Utils.aorDomain(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))
@ -1684,8 +1678,22 @@ class MainActivity : AppCompatActivity() {
uriText = "tel:$uriText"
val uri = if (Utils.isTelUri(uriText)) {
if (ua.account.telProvider == "") {
Utils.alertView(this, getString(R.string.notice),
String.format(getString(R.string.no_telephony_provider)))
val telAccounts = Account.telProviderAccounts()
if (telAccounts.isEmpty()) {
Utils.alertView(this, getString(R.string.notice),
String.format(getString(R.string.no_telephony_providers)))
} else {
val builder = AlertDialog.Builder(this)
with(builder) {
setTitle("Choose a Telephony Provider account")
setItems(telAccounts) { _, which ->
spinToAor("sip:${telAccounts[which]}")
makeCall()
}
setPositiveButton("Cancel") { _: DialogInterface, _: Int -> }
show()
}
}
return
}
Utils.telToSip(uriText, ua.account)
@ -1715,8 +1723,7 @@ class MainActivity : AppCompatActivity() {
if (latest != null)
callUri.setText(
Utils.friendlyUri(
ContactsActivity.contactName(latest.peerUri),
Utils.aorDomain(ua.account.aor)
ContactsActivity.contactName(latest.peerUri), Utils.aorDomain(aor)
)
)
}

View File

@ -291,7 +291,7 @@ object Utils {
}
fun isTelNumber(no: String): Boolean {
return Regex("^[+][1-9][0-9- ]{0,14}\$").matches(no)
return Regex("^([+][1-9])?[0-9- ]{0,15}\$").matches(no)
}
fun isTelUri(uri: String): Boolean {