Simplified Utils.friendlyUri implementation and usage
This commit is contained in:
@ -680,7 +680,7 @@ class BaresipService: Service() {
|
||||
PendingIntent.getActivity(applicationContext, CALL_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
val caller = Utils.friendlyUri(this, Contact.contactName(peerUri), Utils.aorDomain(aor))
|
||||
val caller = Utils.friendlyUri(this, peerUri, aor)
|
||||
nb.setSmallIcon(R.drawable.ic_stat_call)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
|
||||
.setContentIntent(pi)
|
||||
@ -787,7 +787,7 @@ class BaresipService: Service() {
|
||||
PendingIntent.getActivity(applicationContext, TRANSFER_REQ_CODE,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
val target = Utils.friendlyUri(this, Contact.contactName(ev[1]), Utils.aorDomain(aor))
|
||||
val target = Utils.friendlyUri(this, ev[1], aor)
|
||||
nb.setSmallIcon(R.drawable.ic_stat_call)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
|
||||
.setContentIntent(pi)
|
||||
@ -868,7 +868,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
if (!Utils.isVisible()) {
|
||||
if (missed) {
|
||||
val caller = Utils.friendlyUri(this, Contact.contactName(call.peerUri), Utils.aorDomain(aor))
|
||||
val caller = Utils.friendlyUri(this, call.peerUri, aor)
|
||||
val intent = Intent(applicationContext, MainActivity::class.java)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
@ -975,7 +975,7 @@ class BaresipService: Service() {
|
||||
PendingIntent.getActivity(applicationContext, MESSAGE_REQ_CODE, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
val sender = Utils.friendlyUri(this, Contact.contactName(peer), Utils.aorDomain(ua.account.aor))
|
||||
val sender = Utils.friendlyUri(this, peer, ua.account.aor)
|
||||
nb.setSmallIcon(R.drawable.ic_stat_message)
|
||||
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
|
||||
.setContentIntent(pi)
|
||||
|
||||
@ -62,12 +62,7 @@ class CallListAdapter(private val ctx: Context, private val aor: String, private
|
||||
if (count <= 3)
|
||||
viewHolder.etcView.text = ""
|
||||
|
||||
val contactName = Contact.contactName(callRow.peerUri)
|
||||
if (contactName.startsWith("sip:"))
|
||||
viewHolder.peerURIView.text = Utils.friendlyUri(ctx, contactName, Utils.aorDomain(callRow.aor))
|
||||
else
|
||||
viewHolder.peerURIView.text = contactName
|
||||
|
||||
viewHolder.peerURIView.text = Utils.friendlyUri(ctx, callRow.peerUri, callRow.aor)
|
||||
viewHolder.timeView.text = Utils.relativeTime(ctx, callRow.stopTime)
|
||||
|
||||
viewHolder.timeView.setOnClickListener {
|
||||
|
||||
@ -46,9 +46,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
|
||||
listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||
val peerUri = uaHistory[pos].peerUri
|
||||
var peerName = Contact.contactName(peerUri)
|
||||
if (peerName.startsWith("sip:"))
|
||||
peerName = Utils.friendlyUri(this, peerName, Utils.aorDomain(aor))
|
||||
val peerName = Utils.friendlyUri(this, peerUri, aor)
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
|
||||
@ -121,7 +119,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
with (builder) {
|
||||
setTitle(R.string.confirmation)
|
||||
setMessage(String.format(getString(R.string.calls_add_delete_question),
|
||||
Utils.friendlyUri(this@CallsActivity, peerName, Utils.aorDomain(aor)), callText))
|
||||
Utils.friendlyUri(this@CallsActivity, peerName, aor), callText))
|
||||
setNeutralButton(getString(R.string.cancel), dialogClickListener)
|
||||
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
|
||||
setNegativeButton(getString(R.string.add_contact), dialogClickListener)
|
||||
@ -131,7 +129,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
with (builder) {
|
||||
setTitle(R.string.confirmation)
|
||||
setMessage(String.format(getString(R.string.calls_delete_question),
|
||||
Utils.friendlyUri(this@CallsActivity, peerName, Utils.aorDomain(aor)), callText))
|
||||
Utils.friendlyUri(this@CallsActivity, peerName, aor), callText))
|
||||
setNeutralButton(getString(R.string.cancel), dialogClickListener)
|
||||
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
|
||||
show()
|
||||
|
||||
@ -66,9 +66,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
this@ChatActivity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
|
||||
|
||||
var chatPeer = Contact.contactName(peerUri)
|
||||
if (chatPeer.startsWith("sip:"))
|
||||
chatPeer = Utils.friendlyUri(this, chatPeer, Utils.aorDomain(aor))
|
||||
val chatPeer = Utils.friendlyUri(this, peerUri, aor)
|
||||
|
||||
title = String.format(getString(R.string.chat_with), chatPeer)
|
||||
|
||||
|
||||
@ -52,11 +52,7 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList<Mess
|
||||
else
|
||||
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
||||
|
||||
val peerName = Contact.contactName(message.peerUri)
|
||||
viewHolder.peerView.text = if (peerName !=message.peerUri )
|
||||
peerName
|
||||
else
|
||||
Utils.friendlyUri(ctx, message.peerUri, message.aor)
|
||||
viewHolder.peerView.text = Utils.friendlyUri(ctx, message.peerUri, message.aor)
|
||||
|
||||
val cal = GregorianCalendar()
|
||||
cal.timeInMillis = message.timeStamp
|
||||
|
||||
@ -101,7 +101,7 @@ class ChatsActivity: AppCompatActivity() {
|
||||
with (builder) {
|
||||
setTitle(R.string.confirmation)
|
||||
setMessage(String.format(getString(R.string.long_chat_question),
|
||||
Utils.friendlyUri(this@ChatsActivity, peer, Utils.aorDomain(aor))))
|
||||
Utils.friendlyUri(this@ChatsActivity, peer, aor)))
|
||||
setNeutralButton(getText(R.string.cancel), dialogClickListener)
|
||||
setNegativeButton(getText(R.string.delete), dialogClickListener)
|
||||
setPositiveButton(getText(R.string.add_contact), dialogClickListener)
|
||||
@ -131,7 +131,7 @@ class ChatsActivity: AppCompatActivity() {
|
||||
uri = if (Utils.isTelNumber(uriText))
|
||||
"tel:$uriText"
|
||||
else
|
||||
Utils.uriComplete(uriText, Utils.aorDomain(aor))
|
||||
Utils.uriComplete(uriText, aor)
|
||||
if (!Utils.checkUri(uri)) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
|
||||
|
||||
@ -1094,7 +1094,7 @@ class MainActivity : AppCompatActivity() {
|
||||
return
|
||||
}
|
||||
val call = Call.ofCallp(callp)!!
|
||||
val target = Utils.friendlyUri(this, Contact.contactName(ev[1]), Utils.aorDomain(aor))
|
||||
val target = Utils.friendlyUri(this, ev[1], aor)
|
||||
with(MaterialAlertDialogBuilder(this, R.style.AlertDialogTheme)) {
|
||||
setTitle(R.string.transfer_request)
|
||||
setMessage(String.format(getString(R.string.transfer_request_query),
|
||||
@ -1415,7 +1415,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val uri = if (Utils.isTelUri(uriText))
|
||||
Utils.telToSip(uriText, ua.account)
|
||||
else
|
||||
Utils.uriComplete(uriText, Utils.aorDomain(ua.account.aor))
|
||||
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))
|
||||
@ -1754,7 +1754,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
Utils.telToSip(uriText, ua.account)
|
||||
} else {
|
||||
Utils.uriComplete(uriText, Utils.aorDomain(aor))
|
||||
Utils.uriComplete(uriText, aor)
|
||||
}
|
||||
if (!Utils.checkUri(uri)) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
@ -1778,8 +1778,7 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
val latest = NewCallHistory.aorLatestHistory(aor)
|
||||
if (latest != null)
|
||||
callUri.setText(Utils.friendlyUri(this, Contact.contactName(latest.peerUri),
|
||||
Utils.aorDomain(aor)))
|
||||
callUri.setText(Utils.friendlyUri(this, latest.peerUri, aor))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1824,8 +1823,7 @@ class MainActivity : AppCompatActivity() {
|
||||
else
|
||||
getString(R.string.outgoing_call_to_dots)
|
||||
callTimer.visibility = View.INVISIBLE
|
||||
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
|
||||
Utils.aorDomain(ua.account.aor)))
|
||||
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account.aor))
|
||||
securityButton.visibility = View.INVISIBLE
|
||||
diverter.visibility = View.GONE
|
||||
callButton.visibility = View.INVISIBLE
|
||||
@ -1840,14 +1838,12 @@ class MainActivity : AppCompatActivity() {
|
||||
"incoming" -> {
|
||||
callTitle.text = getString(R.string.incoming_call_from_dots)
|
||||
callTimer.visibility = View.INVISIBLE
|
||||
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
|
||||
Utils.aorDomain(ua.account.aor)))
|
||||
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account.aor))
|
||||
callUri.setAdapter(null)
|
||||
securityButton.visibility = View.INVISIBLE
|
||||
val uri = call.diverterUri()
|
||||
if (uri != "") {
|
||||
diverterUri.text = Utils.friendlyUri(this, Contact.contactName(uri),
|
||||
Utils.aorDomain(ua.account.aor))
|
||||
diverterUri.text = Utils.friendlyUri(this, uri, ua.account.aor)
|
||||
diverter.visibility = View.VISIBLE
|
||||
} else {
|
||||
diverter.visibility = View.GONE
|
||||
@ -1868,16 +1864,14 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
if (call.referTo != "") {
|
||||
callTitle.text = getString(R.string.transferring_call_to_dots)
|
||||
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.referTo),
|
||||
Utils.aorDomain(ua.account.aor)))
|
||||
callUri.setText(Utils.friendlyUri(this, call.referTo, ua.account.aor))
|
||||
transferButton.isEnabled = false
|
||||
} else {
|
||||
if (call.dir == "out")
|
||||
callTitle.text = getString(R.string.outgoing_call_to_dots)
|
||||
else
|
||||
callTitle.text = getString(R.string.incoming_call_from_dots)
|
||||
callUri.setText(Utils.friendlyUri(this, Contact.contactName(call.peerUri),
|
||||
Utils.aorDomain(ua.account.aor)))
|
||||
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account.aor))
|
||||
transferButton.isEnabled = true
|
||||
}
|
||||
if (call.onHoldCall == null)
|
||||
|
||||
@ -120,8 +120,10 @@ object Utils {
|
||||
return if (params.size == 1) listOf() else params.subList(1, params.size)
|
||||
}
|
||||
|
||||
fun friendlyUri(ctx: Context, uri: String, domain: String): String {
|
||||
var u = uri
|
||||
fun friendlyUri(ctx: Context, uri: String, aor: String): String {
|
||||
var u = Contact.contactName(uri)
|
||||
if (u != uri)
|
||||
return u
|
||||
val params = uriParams(u)
|
||||
if (uri.startsWith("<") && (uri.endsWith(">")))
|
||||
u = uri.substring(1).substringBeforeLast(">")
|
||||
@ -134,7 +136,7 @@ object Utils {
|
||||
return if (u.contains("@")) {
|
||||
val user = uriUserPart(u)
|
||||
val host = uriHostPart(u)
|
||||
if (isTelNumber(user) || host == domain)
|
||||
if (isTelNumber(user) || host == aorDomain(aor))
|
||||
user
|
||||
else
|
||||
if (host == "anonymous.invalid")
|
||||
@ -148,9 +150,9 @@ object Utils {
|
||||
}
|
||||
}
|
||||
|
||||
fun uriComplete(uri: String, domain: String): String {
|
||||
fun uriComplete(uri: String, aor: String): String {
|
||||
val res = if (!uri.startsWith("sip:")) "sip:$uri" else uri
|
||||
return if (checkUriUser(uri)) "$res@$domain" else res
|
||||
return if (checkUriUser(uri)) "$res@${aorDomain(aor)}" else res
|
||||
}
|
||||
|
||||
fun aorDomain(aor: String): String {
|
||||
|
||||
Reference in New Issue
Block a user