Prompt user for telephony provider account if such is needed to make the call
This commit is contained in:
@@ -198,6 +198,14 @@ class Account(val accp: String) {
|
|||||||
return res
|
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? {
|
fun ofAor(aor: String): Account? {
|
||||||
for (ua in UserAgent.uas())
|
for (ua in UserAgent.uas())
|
||||||
if (ua.account.aor == aor) return ua.account
|
if (ua.account.aor == aor) return ua.account
|
||||||
|
|||||||
@@ -76,23 +76,9 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
i.putExtra("action", "call")
|
i.putExtra("action", "call")
|
||||||
else
|
else
|
||||||
i.putExtra("action", "message")
|
i.putExtra("action", "message")
|
||||||
var ua = UserAgent.ofAor(aor)
|
val ua = UserAgent.ofAor(aor)
|
||||||
if (ua == null) {
|
if (ua == null) {
|
||||||
Log.w(TAG, "onClickListener did not find AoR $aor")
|
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 {
|
} else {
|
||||||
BaresipService.activities.clear()
|
BaresipService.activities.clear()
|
||||||
i.putExtra("uap", ua.uap)
|
i.putExtra("uap", ua.uap)
|
||||||
|
|||||||
@@ -1388,16 +1388,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
uriText = ContactsActivity.findContactUri(uriText) ?: uriText
|
uriText = ContactsActivity.findContactUri(uriText) ?: uriText
|
||||||
if (Utils.isTelNumber(uriText))
|
if (Utils.isTelNumber(uriText))
|
||||||
uriText = "tel:$uriText"
|
uriText = "tel:$uriText"
|
||||||
val uri = if (Utils.isTelUri(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
|
|
||||||
}
|
|
||||||
Utils.telToSip(uriText, ua.account)
|
Utils.telToSip(uriText, ua.account)
|
||||||
} else {
|
else
|
||||||
Utils.uriComplete(uriText, Utils.aorDomain(ua.account.aor))
|
Utils.uriComplete(uriText, Utils.aorDomain(ua.account.aor))
|
||||||
}
|
|
||||||
if (!Utils.checkUri(uri)) {
|
if (!Utils.checkUri(uri)) {
|
||||||
Utils.alertView(this@MainActivity, getString(R.string.notice),
|
Utils.alertView(this@MainActivity, getString(R.string.notice),
|
||||||
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
|
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
|
||||||
@@ -1684,8 +1678,22 @@ class MainActivity : AppCompatActivity() {
|
|||||||
uriText = "tel:$uriText"
|
uriText = "tel:$uriText"
|
||||||
val uri = if (Utils.isTelUri(uriText)) {
|
val uri = if (Utils.isTelUri(uriText)) {
|
||||||
if (ua.account.telProvider == "") {
|
if (ua.account.telProvider == "") {
|
||||||
Utils.alertView(this, getString(R.string.notice),
|
val telAccounts = Account.telProviderAccounts()
|
||||||
String.format(getString(R.string.no_telephony_provider)))
|
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
|
return
|
||||||
}
|
}
|
||||||
Utils.telToSip(uriText, ua.account)
|
Utils.telToSip(uriText, ua.account)
|
||||||
@@ -1715,8 +1723,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (latest != null)
|
if (latest != null)
|
||||||
callUri.setText(
|
callUri.setText(
|
||||||
Utils.friendlyUri(
|
Utils.friendlyUri(
|
||||||
ContactsActivity.contactName(latest.peerUri),
|
ContactsActivity.contactName(latest.peerUri), Utils.aorDomain(aor)
|
||||||
Utils.aorDomain(ua.account.aor)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isTelNumber(no: String): Boolean {
|
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 {
|
fun isTelUri(uri: String): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user