Contact selection list now contains only those Android contacts that have

exactly one URI
This commit is contained in:
Juha Heinanen
2022-02-21 11:30:25 +02:00
parent 8e8bb09c57
commit 664d857a5d
2 changed files with 18 additions and 17 deletions
@@ -62,12 +62,10 @@ sealed class Contact {
} }
is AndroidContact -> { is AndroidContact -> {
if (c.name == name) { if (c.name == name) {
if (c.uris.isNotEmpty()) { return if (c.uris.isNotEmpty())
for (u in c.uris) c.uris.first()
if (u.startsWith("sip:")) else
return u null
return c.uris.first()
}
} }
} }
} }
@@ -149,7 +147,7 @@ sealed class Contact {
} }
cur?.close() cur?.close()
for ((_, value) in contacts) for ((_, value) in contacts)
if (value.name != "") if (value.name != "" && value.uris.isNotEmpty())
BaresipService.androidContacts.add(value) BaresipService.androidContacts.add(value)
} }
@@ -208,6 +206,18 @@ sealed class Contact {
BaresipService.contactUpdate.postValue(System.nanoTime()) BaresipService.contactUpdate.postValue(System.nanoTime())
} }
fun generateContactNames () {
BaresipService.contactNames.clear()
for (c in BaresipService.contacts)
when (c) {
is BaresipContact ->
BaresipService.contactNames.add(c.name)
is AndroidContact ->
if (c.uris.size == 1)
BaresipService.contactNames.add(c.name)
}
}
private fun sortContacts() { private fun sortContacts() {
BaresipService.contacts.sortBy{ when (it) { BaresipService.contacts.sortBy{ when (it) {
is BaresipContact -> it.name is BaresipContact -> it.name
@@ -215,14 +225,5 @@ sealed class Contact {
}} }}
} }
private fun generateContactNames () {
BaresipService.contactNames.clear()
BaresipService.contactNames.addAll(
BaresipService.contacts.map {
when (it) {
is BaresipContact -> it.name
is AndroidContact -> it.name
}})
}
} }
} }
@@ -173,7 +173,7 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
} }
} }
Contact.contacts().removeAt(position) Contact.contacts().removeAt(position)
Contact.contactNames().removeAt(position) Contact.generateContactNames()
Contact.saveBaresipContacts() Contact.saveBaresipContacts()
this.notifyDataSetChanged() this.notifyDataSetChanged()
} }