Apply country code also to chat peer's URI in order to find proper contact
This commit is contained in:
@@ -2,7 +2,6 @@ package com.tutpro.baresip
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
@@ -18,7 +17,6 @@ import android.widget.Toast
|
|||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import com.tutpro.baresip.databinding.ActivityChatBinding
|
import com.tutpro.baresip.databinding.ActivityChatBinding
|
||||||
|
|
||||||
class ChatActivity : AppCompatActivity() {
|
class ChatActivity : AppCompatActivity() {
|
||||||
@@ -75,7 +73,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
this@ChatActivity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
|
this@ChatActivity.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
|
||||||
|
|
||||||
val chatPeer = Utils.friendlyUri(this, peerUri, userAgent.account)
|
val chatPeer = Utils.friendlyUri(this, peerUri, userAgent.account, true)
|
||||||
|
|
||||||
title = String.format(getString(R.string.chat_with), chatPeer)
|
title = String.format(getString(R.string.chat_with), chatPeer)
|
||||||
|
|
||||||
@@ -90,7 +88,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
listView = binding.messages
|
listView = binding.messages
|
||||||
|
|
||||||
chatMessages = uaPeerMessages(aor, peerUri)
|
chatMessages = uaPeerMessages(aor, peerUri)
|
||||||
mlAdapter = MessageListAdapter(this, peerUri, chatMessages)
|
mlAdapter = MessageListAdapter(this, peerUri, chatPeer, chatMessages)
|
||||||
|
|
||||||
val messagesObserver = Observer<Long> {
|
val messagesObserver = Observer<Long> {
|
||||||
chatMessages.clear()
|
chatMessages.clear()
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
|
|||||||
|
|
||||||
val message = rows[position]
|
val message = rows[position]
|
||||||
|
|
||||||
Utils.setAvatar(ctx, viewHolder.imageAvatarView, viewHolder.textAvatarView, message.peerUri)
|
viewHolder.peerView.text = Utils.friendlyUri(ctx, message.peerUri, account, true)
|
||||||
|
Utils.setAvatar(ctx, viewHolder.imageAvatarView, viewHolder.textAvatarView,
|
||||||
|
if (Contact.contactName(message.peerUri) == message.peerUri)
|
||||||
|
Utils.e164Uri(message.peerUri, account.countryCode)
|
||||||
|
else
|
||||||
|
message.peerUri)
|
||||||
|
|
||||||
if ((message.direction == R.drawable.arrow_down_green) ||
|
if ((message.direction == R.drawable.arrow_down_green) ||
|
||||||
(message.direction == R.drawable.arrow_down_red))
|
(message.direction == R.drawable.arrow_down_red))
|
||||||
@@ -52,8 +57,6 @@ class ChatListAdapter(private val ctx: Context, private val account: Account, pr
|
|||||||
else
|
else
|
||||||
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
||||||
|
|
||||||
viewHolder.peerView.text = Utils.friendlyUri(ctx, message.peerUri, account)
|
|
||||||
|
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
cal.timeInMillis = message.timeStamp
|
cal.timeInMillis = message.timeStamp
|
||||||
val fmt: DateFormat = if (isToday(message.timeStamp))
|
val fmt: DateFormat = if (isToday(message.timeStamp))
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class ChatsActivity: AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var binding: ActivityChatsBinding
|
private lateinit var binding: ActivityChatsBinding
|
||||||
private lateinit var uaMessages: ArrayList<Message>
|
private lateinit var uaMessages: ArrayList<Message>
|
||||||
internal lateinit var listView: ListView
|
private lateinit var listView: ListView
|
||||||
private lateinit var clAdapter: ChatListAdapter
|
private lateinit var clAdapter: ChatListAdapter
|
||||||
internal lateinit var peerUri: AutoCompleteTextView
|
internal lateinit var peerUri: AutoCompleteTextView
|
||||||
private lateinit var plusButton: ImageButton
|
private lateinit var plusButton: ImageButton
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ sealed class Contact {
|
|||||||
}
|
}
|
||||||
is AndroidContact -> {
|
is AndroidContact -> {
|
||||||
for (u in c.uris)
|
for (u in c.uris)
|
||||||
if (Utils.uriMatch(u, uri))
|
if (Utils.uriMatch(u.filterNot{setOf('-', ' ', '(', ')').contains(it)}, uri))
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MessageListAdapter(private val ctx: Context, private val peerUri: String, private val rows: ArrayList<Message>) :
|
class MessageListAdapter(private val ctx: Context, private val peerUri: String,
|
||||||
|
private val chatPeer: String, private val rows: ArrayList<Message>) :
|
||||||
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
||||||
|
|
||||||
private val layoutInflater = LayoutInflater.from(context)
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
@@ -67,12 +68,11 @@ class MessageListAdapter(private val ctx: Context, private val peerUri: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val builder = MaterialAlertDialogBuilder(ctx, R.style.AlertDialogTheme)
|
val builder = MaterialAlertDialogBuilder(ctx, R.style.AlertDialogTheme)
|
||||||
val chatPeer = Contact.contactName(peerUri)
|
if (chatPeer == peerUri)
|
||||||
if (Contact.contactName(peerUri) == peerUri)
|
|
||||||
with (builder) {
|
with (builder) {
|
||||||
setTitle(R.string.confirmation)
|
setTitle(R.string.confirmation)
|
||||||
setMessage(String.format(ctx.getString(R.string.long_message_question),
|
setMessage(String.format(ctx.getString(R.string.long_message_question),
|
||||||
chatPeer))
|
peerUri))
|
||||||
setNeutralButton(ctx.getString(R.string.cancel), dialogClickListener)
|
setNeutralButton(ctx.getString(R.string.cancel), dialogClickListener)
|
||||||
setNegativeButton(ctx.getString(R.string.delete), dialogClickListener)
|
setNegativeButton(ctx.getString(R.string.delete), dialogClickListener)
|
||||||
setPositiveButton(ctx.getString(R.string.add_contact), dialogClickListener)
|
setPositiveButton(ctx.getString(R.string.add_contact), dialogClickListener)
|
||||||
@@ -100,12 +100,11 @@ class MessageListAdapter(private val ctx: Context, private val peerUri: String,
|
|||||||
val peer: String = if (down) {
|
val peer: String = if (down) {
|
||||||
lp.setMargins(0, 10, 75, 10)
|
lp.setMargins(0, 10, 75, 10)
|
||||||
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
|
||||||
val contactName = Contact.contactName(message.peerUri)
|
if (chatPeer.startsWith("sip:") &&
|
||||||
if (contactName.startsWith("sip:") &&
|
|
||||||
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
||||||
Utils.uriUserPart(message.peerUri)
|
Utils.uriUserPart(message.peerUri)
|
||||||
else
|
else
|
||||||
contactName
|
chatPeer
|
||||||
} else {
|
} else {
|
||||||
lp.setMargins(75, 10, 0, 10)
|
lp.setMargins(75, 10, 0, 10)
|
||||||
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ object Utils {
|
|||||||
u = Contact.contactName(e164Uri(uri, account.countryCode))
|
u = Contact.contactName(e164Uri(uri, account.countryCode))
|
||||||
if (u != uri)
|
if (u != uri)
|
||||||
return u
|
return u
|
||||||
|
u = friendlyUri(ctx, uri, account, false)
|
||||||
|
if (u != uri)
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
val params = uriParams(u)
|
val params = uriParams(u)
|
||||||
if (uri.startsWith("<") && (uri.endsWith(">")))
|
if (uri.startsWith("<") && (uri.endsWith(">")))
|
||||||
@@ -973,6 +976,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.S)
|
||||||
fun setCommunicationDevice(am: AudioManager, type: Int) {
|
fun setCommunicationDevice(am: AudioManager, type: Int) {
|
||||||
val current = am.communicationDevice!!.type
|
val current = am.communicationDevice!!.type
|
||||||
Log.d(TAG, "Current com dev/mode $current/${am.mode}")
|
Log.d(TAG, "Current com dev/mode $current/${am.mode}")
|
||||||
|
|||||||
Reference in New Issue
Block a user