diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index ad043ef4..77093cb9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt index 8a5c6028..600f161b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt @@ -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 { diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index 0c6627c9..d11db626 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index b9afa2f9..a8a2ebc9 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt index 3a0e144e..c213ae35 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt @@ -52,11 +52,7 @@ class ChatListAdapter(private val ctx: Context, private val rows: ArrayList { 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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index f036ae93..664b835e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -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 {