diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 542d4940..d9206503 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -1645,8 +1645,7 @@ class BaresipService: Service() { val messageUpdate = MutableLiveData() val contactUpdate = MutableLiveData() val registrationUpdate = MutableLiveData() - @SuppressLint("MutableCollectionMutableState") - val baresipContacts = mutableStateOf(mutableListOf()) + val baresipContacts = mutableStateOf(emptyList()) val androidContacts = mutableStateOf(emptyList()) val contactNames = mutableStateOf(emptyList()) var contactsMode = "baresip" diff --git a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt index 8c4362fd..0d520dc6 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Contact.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Contact.kt @@ -244,7 +244,7 @@ sealed class Contact { Log.e(TAG, "Could not read avatar image from file $id.png: ${e.message}") } } - BaresipService.baresipContacts.value.add(contact) + BaresipService.baresipContacts.value += contact } } return true @@ -267,22 +267,26 @@ sealed class Contact { } fun addBaresipContact(contact: BaresipContact) { - BaresipService.baresipContacts.value.add(contact) + BaresipService.baresipContacts.value += contact saveBaresipContacts() contactsUpdate() } fun updateBaresipContact(contact: BaresipContact) { - val newContact = contact.copy() as BaresipContact - BaresipService.baresipContacts.value.removeIf { it.id == contact.id } - newContact.id = System.currentTimeMillis() - BaresipService.baresipContacts.value.add(newContact) + val updatedContacts = BaresipService.baresipContacts.value.toMutableList() + val updatedContact = contact.copy() as BaresipContact + updatedContact.id = System.currentTimeMillis() + updatedContacts.removeIf { it.id == contact.id } + updatedContacts.add(updatedContact) + BaresipService.baresipContacts.value = updatedContacts saveBaresipContacts() contactsUpdate() } fun removeBaresipContact(contact: BaresipContact) { - BaresipService.baresipContacts.value.removeIf { it.id == contact.id } + val removed = BaresipService.baresipContacts.value.toMutableList() + removed.removeIf { it.id == contact.id } + BaresipService.baresipContacts.value = removed.toList() saveBaresipContacts() contactsUpdate() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt index 8d8a8717..2a5d64b0 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt @@ -340,7 +340,6 @@ class ContactsActivity : ComponentActivity() { } } Contact.removeBaresipContact(contact) - //Contact.contactsUpdate() } DialogInterface.BUTTON_NEUTRAL -> {