More contact related improvements and fixes

This commit is contained in:
Juha Heinanen
2023-03-03 06:57:41 +02:00
parent 2b05ee2fdc
commit bd90a39363
9 changed files with 25 additions and 26 deletions

View File

@ -698,7 +698,7 @@ class BaresipService: Service() {
piFlags)
val nb = NotificationCompat.Builder(this,
if (shouldVibrate()) MEDIUM_CHANNEL_ID else HIGH_CHANNEL_ID)
val caller = Utils.friendlyUri(this, peerUri, ua.account, true)
val caller = Utils.friendlyUri(this, peerUri, ua.account)
nb.setSmallIcon(R.drawable.ic_stat_call)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)
@ -956,7 +956,7 @@ class BaresipService: Service() {
@SuppressLint("UnspecifiedImmutableFlag")
@Keep
fun messageEvent(uap: Long, peer: String, msg: ByteArray) {
fun messageEvent(uap: Long, peerUri: String, msg: ByteArray) {
var text = "Decoding of message failed!"
try {
text = String(msg, StandardCharsets.UTF_8)
@ -970,8 +970,8 @@ class BaresipService: Service() {
}
val timeStamp = System.currentTimeMillis()
val timeStampString = timeStamp.toString()
Log.d(TAG, "Message event for $uap from $peer at $timeStampString")
Message(ua.account.aor, peer, text, timeStamp,
Log.d(TAG, "Message event for $uap from $peerUri at $timeStampString")
Message(ua.account.aor, peerUri, text, timeStamp,
R.drawable.arrow_down_green, 0, "", true).add()
Message.save()
ua.account.unreadMessages = true
@ -984,10 +984,10 @@ class BaresipService: Service() {
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra("action", "message show").putExtra("uap", uap)
.putExtra("peer", peer)
.putExtra("peer", peerUri)
val pi = PendingIntent.getActivity(applicationContext, MESSAGE_REQ_CODE, intent, piFlags)
val nb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
val sender = Utils.friendlyUri(this, peer, ua.account)
val sender = Utils.friendlyUri(this, peerUri, ua.account)
nb.setSmallIcon(R.drawable.ic_stat_message)
.setColor(ContextCompat.getColor(this, R.color.colorBaresip))
.setContentIntent(pi)
@ -1005,7 +1005,7 @@ class BaresipService: Service() {
replyIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK
replyIntent.putExtra("action", "message reply")
.putExtra("uap", uap).putExtra("peer", peer)
.putExtra("uap", uap).putExtra("peer", peerUri)
val rpi = PendingIntent.getActivity(applicationContext, REPLY_REQ_CODE, replyIntent,
piFlags)
val saveIntent = Intent(this, BaresipService::class.java)
@ -1031,7 +1031,7 @@ class BaresipService: Service() {
nt.play()
} else
nt.play()
postServiceEvent(ServiceEvent("message show", arrayListOf(uap, peer), System.nanoTime()))
postServiceEvent(ServiceEvent("message show", arrayListOf(uap, peerUri), System.nanoTime()))
}
@Keep

View File

@ -63,7 +63,7 @@ class CallListAdapter(private val ctx: Context, private val account: Account,
if (count <= 3)
viewHolder.etcView.text = ""
viewHolder.peerURIView.text = Utils.friendlyUri(ctx, callRow.peerUri, account, true)
viewHolder.peerURIView.text = Utils.friendlyUri(ctx, callRow.peerUri, account)
viewHolder.timeView.text = Utils.relativeTime(ctx, callRow.stopTime)
viewHolder.timeView.setOnClickListener {

View File

@ -101,7 +101,7 @@ class CallsActivity : AppCompatActivity() {
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
val peerUri = uaHistory[pos].peerUri
val peerName = Contact.contactName(peerUri)
val peerName = Utils.friendlyUri(this, peerUri, account)
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEGATIVE -> {
@ -126,11 +126,11 @@ class CallsActivity : AppCompatActivity() {
else
getString(R.string.calls_call)
val builder = MaterialAlertDialogBuilder(this@CallsActivity, R.style.AlertDialogTheme)
if (peerName.startsWith("sip:"))
if (!Contact.nameExists(peerName, false))
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.calls_add_delete_question),
Utils.friendlyUri(this@CallsActivity, peerName, account), callText))
peerName, callText))
setNeutralButton(getString(R.string.cancel), dialogClickListener)
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
setNegativeButton(getString(R.string.add_contact), dialogClickListener)
@ -140,7 +140,7 @@ class CallsActivity : AppCompatActivity() {
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.calls_delete_question),
Utils.friendlyUri(this@CallsActivity, peerName, account), callText))
peerName, callText))
setNeutralButton(getString(R.string.cancel), dialogClickListener)
setPositiveButton(String.format(getString(R.string.delete), callText), dialogClickListener)
show()

View File

@ -73,7 +73,7 @@ class ChatActivity : AppCompatActivity() {
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
this@ChatActivity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
val chatPeer = Utils.friendlyUri(this, peerUri, userAgent.account, true)
val chatPeer = Utils.friendlyUri(this, peerUri, userAgent.account)
title = String.format(getString(R.string.chat_with), chatPeer)

View File

@ -44,7 +44,7 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
val message = rows[position]
viewHolder.peerView.text = Utils.friendlyUri(ctx, message.peerUri, account, true)
viewHolder.peerView.text = Utils.friendlyUri(ctx, message.peerUri, account)
Utils.setAvatar(ctx, viewHolder.imageAvatarView, viewHolder.textAvatarView,
if (Contact.contactName(message.peerUri) == message.peerUri)
Utils.e164Uri(message.peerUri, account.countryCode)

View File

@ -107,12 +107,12 @@ class ChatsActivity: AppCompatActivity() {
}
val builder = MaterialAlertDialogBuilder(this@ChatsActivity, R.style.AlertDialogTheme)
val peer = Contact.contactName(uaMessages[pos].peerUri)
if (peer.startsWith("sip:"))
val peer = Utils.friendlyUri(this@ChatsActivity, uaMessages[pos].peerUri, account)
if (!Contact.nameExists(peer, false))
with (builder) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.long_chat_question),
Utils.friendlyUri(this@ChatsActivity, peer, account, true)))
Utils.friendlyUri(this@ChatsActivity, peer, account)))
setNeutralButton(getText(R.string.cancel), dialogClickListener)
setNegativeButton(getText(R.string.delete), dialogClickListener)
setPositiveButton(getText(R.string.add_contact), dialogClickListener)

View File

@ -147,7 +147,7 @@ sealed class Contact {
if (contact.thumbnailUri == null && thumb != null)
contact.thumbnailUri = thumb
if (mime == ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
contact.uris.add("tel:${data.filterNot{setOf('-', ' ').contains(it)}}")
contact.uris.add("tel:${data.filterNot{setOf('-', ' ', '(', ')').contains(it)}}")
else if (mime == ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
contact.uris.add("sip:$data")
else

View File

@ -522,7 +522,6 @@ class MainActivity : AppCompatActivity() {
}
chatRequests = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
Log.d(TAG, "************ activityAor = $activityAor")
spinToAor(activityAor)
updateIcons(Account.ofAor(activityAor)!!)
}
@ -1893,8 +1892,8 @@ class MainActivity : AppCompatActivity() {
else
getString(R.string.outgoing_call_to_dots)
callTimer.visibility = View.INVISIBLE
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account,
call.status == "answered"))
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account))
//call.status == "answered"))
securityButton.visibility = View.INVISIBLE
diverter.visibility = View.GONE
callButton.visibility = View.INVISIBLE
@ -1909,12 +1908,12 @@ class MainActivity : AppCompatActivity() {
"incoming" -> {
callTitle.text = getString(R.string.incoming_call_from_dots)
callTimer.visibility = View.INVISIBLE
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account, true))
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account))
callUri.setAdapter(null)
securityButton.visibility = View.INVISIBLE
val uri = call.diverterUri()
if (uri != "") {
diverterUri.text = Utils.friendlyUri(this, uri, ua.account, true)
diverterUri.text = Utils.friendlyUri(this, uri, ua.account)
diverter.visibility = View.VISIBLE
} else {
diverter.visibility = View.GONE
@ -1943,7 +1942,7 @@ class MainActivity : AppCompatActivity() {
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account))
} else {
callTitle.text = getString(R.string.incoming_call_from_dots)
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account, true))
callUri.setText(Utils.friendlyUri(this, call.peerUri, ua.account))
}
transferButton.isEnabled = true
}

View File

@ -122,7 +122,7 @@ object Utils {
return if (params.size == 1) listOf() else params.subList(1, params.size)
}
fun friendlyUri(ctx: Context, uri: String, account: Account, e164Check: Boolean = false): String {
fun friendlyUri(ctx: Context, uri: String, account: Account, e164Check: Boolean = true): String {
var u = Contact.contactName(uri)
if (u != uri)
return u