Contact name <-> contact URI mapping fixes and improvements
This commit is contained in:
@ -7,4 +7,11 @@ class AndroidContact(val id: Long, var name: String, var color: Int, var thumbna
|
||||
|
||||
val uris = ArrayList<String>()
|
||||
|
||||
}
|
||||
companion object {
|
||||
|
||||
fun contacts(): ArrayList<AndroidContact> {
|
||||
return BaresipService.androidContacts
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -46,7 +46,6 @@ class AndroidContactListAdapter(private val ctx: Context,
|
||||
if (thumbNailUri != null) {
|
||||
viewHolder.imageAvatarView.setImageURI(thumbNailUri)
|
||||
} else {
|
||||
contact.color = Utils.randomColor()
|
||||
viewHolder.textAvatarView.background.setTint(contact.color)
|
||||
if (contact.name.isNotEmpty())
|
||||
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
||||
|
||||
@ -168,7 +168,7 @@ class AndroidContactsActivity : AppCompatActivity() {
|
||||
val contact = if (contacts.containsKey(id))
|
||||
contacts[id]!!
|
||||
else
|
||||
AndroidContact(id, name, 0, thumb)
|
||||
AndroidContact(id, name, Utils.randomColor(), thumb)
|
||||
if (contact.name == "" && name != "")
|
||||
contact.name = name
|
||||
if (contact.thumbnailUri == null && thumb != null)
|
||||
|
||||
@ -118,16 +118,17 @@ class ChatsActivity: AppCompatActivity() {
|
||||
peerUri = binding.peer
|
||||
peerUri.threshold = 2
|
||||
peerUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map{Contact -> Contact.name}))
|
||||
Utils.contactNames()))
|
||||
|
||||
plusButton.setOnClickListener {
|
||||
val uriText = peerUri.text.toString().trim()
|
||||
if (uriText.isNotEmpty()) {
|
||||
val contactUri = Utils.contactUri(uriText)
|
||||
val uri = if (contactUri == null)
|
||||
Utils.uriComplete(uriText, Utils.aorDomain(aor))
|
||||
else
|
||||
uriText
|
||||
var uri = Utils.contactUri(uriText)
|
||||
if (uri == null)
|
||||
uri = if (Utils.isTelNumber(uriText))
|
||||
"tel:$uriText"
|
||||
else
|
||||
Utils.uriComplete(uriText, Utils.aorDomain(aor))
|
||||
if (!Utils.checkUri(uri)) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
String.format(getString(R.string.invalid_sip_or_tel_uri), uri))
|
||||
|
||||
@ -273,7 +273,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map { Contact -> Contact.name }))
|
||||
Utils.contactNames()))
|
||||
callUri.threshold = 2
|
||||
callUri.setOnFocusChangeListener { view, b ->
|
||||
if (b) {
|
||||
@ -456,7 +456,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
contactsRequest = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map { Contact -> Contact.name }))
|
||||
Utils.contactNames()))
|
||||
}
|
||||
|
||||
contactsButton.setOnClickListener {
|
||||
@ -1403,7 +1403,7 @@ class MainActivity : AppCompatActivity() {
|
||||
titleView.text = getString(R.string.call_transfer)
|
||||
val transferUri = layout.findViewById(R.id.transferUri) as AutoCompleteTextView
|
||||
transferUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map { Contact -> Contact.name }))
|
||||
Utils.contactNames()))
|
||||
transferUri.threshold = 2
|
||||
transferUri.requestFocus()
|
||||
val builder = AlertDialog.Builder(this)
|
||||
@ -1772,7 +1772,7 @@ class MainActivity : AppCompatActivity() {
|
||||
callUri.isFocusableInTouchMode = true
|
||||
imm.hideSoftInputFromWindow(callUri.windowToken, 0)
|
||||
callUri.setAdapter(ArrayAdapter(this, android.R.layout.select_dialog_item,
|
||||
Contact.contacts().map { Contact -> Contact.name }))
|
||||
Utils.contactNames()))
|
||||
securityButton.visibility = View.INVISIBLE
|
||||
callButton.visibility = View.VISIBLE
|
||||
callButton.isEnabled = true
|
||||
|
||||
@ -295,7 +295,7 @@ object Utils {
|
||||
}
|
||||
|
||||
fun isTelNumber(no: String): Boolean {
|
||||
return Regex("^([+][1-9])?[0-9- ]{0,15}\$").matches(no)
|
||||
return no.isNotEmpty() && Regex("^([+][1-9])?[0-9- ]{0,15}\$").matches(no)
|
||||
}
|
||||
|
||||
fun isTelUri(uri: String): Boolean {
|
||||
@ -328,6 +328,11 @@ object Utils {
|
||||
return ContactsActivity.contactUri(name) ?: AndroidContactsActivity.contactUri(name)
|
||||
}
|
||||
|
||||
fun contactNames() : List<String> {
|
||||
return Contact.contacts().map{Contact -> Contact.name} +
|
||||
AndroidContact.contacts().map{AndroidContact -> AndroidContact.name}
|
||||
}
|
||||
|
||||
fun setAvatar(ctx: Context, imageView: ImageView, textView: TextView, uri: String) {
|
||||
val contact = ContactsActivity.findContact(uri)
|
||||
if (contact != null) {
|
||||
|
||||
Reference in New Issue
Block a user