Make sure contact list is immediately updated after import

This commit is contained in:
Juha Heinanen
2026-05-20 15:50:14 +03:00
parent 50806025cb
commit 932b66eccc
@@ -231,7 +231,7 @@ sealed class Contact {
val contacts = String(content) val contacts = String(content)
var contactNo = 0 var contactNo = 0
val baseId = System.currentTimeMillis() val baseId = System.currentTimeMillis()
BaresipService.baresipContacts.value = mutableListOf() val newBaresipContacts = mutableListOf<BaresipContact>()
contacts.lines().forEach { contacts.lines().forEach {
val parts = it.split("\"") val parts = it.split("\"")
if (parts.size == 3) { if (parts.size == 3) {
@@ -266,25 +266,29 @@ sealed class Contact {
Log.e(TAG, "Could not read avatar image from file $id.png: ${e.message}") Log.e(TAG, "Could not read avatar image from file $id.png: ${e.message}")
} }
} }
BaresipService.baresipContacts.value += contact newBaresipContacts.add(contact)
} }
} }
BaresipService.baresipContacts.value = newBaresipContacts.toList()
return true return true
} }
fun contactsUpdate() { fun contactsUpdate() {
BaresipService.contacts = mutableListOf() val newContacts = mutableListOf<Contact>()
if (BaresipService.contactsMode != "android") if (BaresipService.contactsMode != "android")
for (c in BaresipService.baresipContacts.value) for (c in BaresipService.baresipContacts.value)
BaresipService.contacts.add(c.copy()) newContacts.add(c.copy())
if (BaresipService.contactsMode != "baresip") if (BaresipService.contactsMode != "baresip")
for (c in BaresipService.androidContacts.value) for (c in BaresipService.androidContacts.value)
if (!nameExists(c.name, BaresipService.contacts, true)) if (!nameExists(c.name, newContacts, true))
BaresipService.contacts.add(c.copy()) newContacts.add(c.copy())
BaresipService.contacts.sortBy{ when (it) { newContacts.sortBy {
when (it) {
is BaresipContact -> if (it.favorite) "0" + it.name else "1" + it.name is BaresipContact -> if (it.favorite) "0" + it.name else "1" + it.name
is AndroidContact -> if (it.favorite) "0" + it.name else "1" + it.name is AndroidContact -> if (it.favorite) "0" + it.name else "1" + it.name
}} }
}
BaresipService.contacts = newContacts
generateContactNames() generateContactNames()
} }