- In chat and call lists, if userpart of peer URI is an E.164 number,

show only the userpart.
- In chat list, show only the first line of the message.
This commit is contained in:
Juha Heinanen
2019-11-20 09:28:43 +02:00
parent e00c9a4590
commit 1876dd76a2
5 changed files with 14 additions and 24 deletions

View File

@ -27,10 +27,7 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList<Call
peer = contact.name
avatarBackground.setColor(contact.color)
} else {
if (Utils.uriHostPart(callRow.peerUri) == Utils.uriHostPart(callRow.aor))
peer = Utils.uriUserPart(callRow.peerUri)
else
peer = Utils.uriAor(callRow.peerUri)
peer = Utils.friendlyUri(callRow.peerUri, callRow.aor)
avatarBackground.setColor(Utils.randomColor())
}
avatarView.text = "${peer[0]}"

View File

@ -56,15 +56,10 @@ class ChatActivity : AppCompatActivity() {
this@ChatActivity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
var chatPeer = ContactsActivity.contactName(peerUri)
if (chatPeer.startsWith("sip:")) {
if (Utils.checkTelNo(Utils.uriUserPart(peerUri)) ||
(Utils.uriHostPart(peerUri) == Utils.aorDomain(aor)))
chatPeer = Utils.uriUserPart(peerUri)
else
chatPeer = chatPeer.substring(4)
}
if (chatPeer.startsWith("sip:"))
chatPeer = Utils.friendlyUri(chatPeer, Utils.aorDomain(aor))
setTitle(String.format(getString(R.string.chat_with), chatPeer))
title = String.format(getString(R.string.chat_with), chatPeer)
val headerView = findViewById(R.id.account) as TextView
val headerText = "${getString(R.string.account)} ${aor.substringAfter(":")}"

View File

@ -35,11 +35,8 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
peer = contact.name
avatarBackground.setColor(contact.color)
} else {
if (Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor))
peer = Utils.uriUserPart(message.peerUri)
else
peer = Utils.uriAor(message.peerUri)
avatarBackground.setColor(Color.RED)
peer = Utils.friendlyUri(message.peerUri, message.aor)
avatarBackground.setColor(Utils.randomColor())
}
avatarView.text = "${peer[0]}"
if (message.direction == R.drawable.arrow_down_green) {

View File

@ -67,11 +67,8 @@ object Utils {
return uri.substringAfter(":").substringBefore("@")
}
fun uriAor(uri: String): String {
return uriUserPart(uri) + "@" + uriHostPart(uri)
}
fun friendlyUri(uri: String, domain: String): String {
Log.d("Baresip", "Checking uri $uri and domain $domain")
var u = uri
if (uri.startsWith("<") && (uri.endsWith(">")))
u = uri.substring(1).substringBeforeLast(">")
@ -79,7 +76,10 @@ object Utils {
!u.contains(";")) {
val user = uriUserPart(u)
val host = uriHostPart(u)
if (host == domain) return user else return "$user@$host"
if (checkE164Number(user) || (host == domain))
return user
else
return "$user@$host"
} else {
return uri
}
@ -104,8 +104,8 @@ object Utils {
checkPort(parts[1])
}
fun checkTelNo(no: String): Boolean {
return Regex("^[+]?[0-9]{1,16}\$").matches(no)
fun checkE164Number(no: String): Boolean {
return Regex("^[+][1-9][0-9]{0,14}\$").matches(no)
}
fun checkIpV4(ip: String): Boolean {

View File

@ -64,6 +64,7 @@
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:textSize="16sp"
android:singleLine="true"
android:text="" >
</TextView>