From bd90a393633bb43889cb6f3f3c8955e397a91a89 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 3 Mar 2023 06:57:41 +0200 Subject: [PATCH] More contact related improvements and fixes --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 16 ++++++++-------- .../kotlin/com/tutpro/baresip/CallListAdapter.kt | 2 +- .../kotlin/com/tutpro/baresip/CallsActivity.kt | 8 ++++---- .../kotlin/com/tutpro/baresip/ChatActivity.kt | 2 +- .../kotlin/com/tutpro/baresip/ChatListAdapter.kt | 2 +- .../kotlin/com/tutpro/baresip/ChatsActivity.kt | 6 +++--- .../main/kotlin/com/tutpro/baresip/Contact.kt | 2 +- .../kotlin/com/tutpro/baresip/MainActivity.kt | 11 +++++------ app/src/main/kotlin/com/tutpro/baresip/Utils.kt | 2 +- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 938bdb1e..b356eff2 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt index de2165f6..c49576d5 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallListAdapter.kt @@ -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 { diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index 4e40e4dc..287b1268 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -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() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index 27752aa6..317732c8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt index b8a78b4a..bd973a1e 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt index 0b0e1654..c8510558 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index d224e75a..a3949a18 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -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 diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 9e77272b..1cd41180 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -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 } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 3637691d..d63a6633 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -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