Fixed long-term presence icon not refreshed in contacts list

This commit is contained in:
Sylvain Berfini 2023-05-23 11:52:08 +02:00
parent 6dba85d41b
commit e841a8fbc8
3 changed files with 8 additions and 8 deletions

View file

@ -34,7 +34,7 @@ import org.linphone.activities.main.contact.data.ContactNumberOrAddressData
import org.linphone.activities.main.viewmodels.MessageNotifierViewModel
import org.linphone.contact.ContactDataInterface
import org.linphone.contact.ContactsUpdatedListenerStub
import org.linphone.contact.hasPresence
import org.linphone.contact.hasLongTermPresence
import org.linphone.core.*
import org.linphone.core.tools.Log
import org.linphone.utils.Event
@ -81,6 +81,8 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier
val readOnlyNativeAddressBook = MutableLiveData<Boolean>()
val hasLongTermPresence = MutableLiveData<Boolean>()
private val chatRoomListener = object : ChatRoomListenerStub() {
override fun onStateChanged(chatRoom: ChatRoom, state: ChatRoom.State) {
if (state == ChatRoom.State.Created) {
@ -147,16 +149,19 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier
isNativeContact.postValue(friend.refKey != null)
presenceStatus.postValue(friend.consolidatedPresence)
readOnlyNativeAddressBook.postValue(corePreferences.readOnlyNativeContacts)
hasLongTermPresence.postValue(friend.hasLongTermPresence())
} else {
contact.value = friend
displayName.value = friend.name
isNativeContact.value = friend.refKey != null
presenceStatus.value = friend.consolidatedPresence
readOnlyNativeAddressBook.value = corePreferences.readOnlyNativeContacts
hasLongTermPresence.value = friend.hasLongTermPresence()
}
friend.addListener {
presenceStatus.value = it.consolidatedPresence
hasLongTermPresence.value = it.hasLongTermPresence()
}
}
@ -269,8 +274,4 @@ class ContactViewModel(friend: Friend, async: Boolean = false) : MessageNotifier
}
numbersAndAddresses.postValue(list)
}
fun hasPresence(): Boolean {
return contact.value?.hasPresence() ?: false
}
}

View file

@ -35,7 +35,6 @@ import androidx.core.app.Person
import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.MutableLiveData
import java.io.IOException
import kotlinx.coroutines.*
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
@ -378,7 +377,7 @@ fun Friend.getContactForPhoneNumberOrAddress(value: String): String? {
return null
}
fun Friend.hasPresence(): Boolean {
fun Friend.hasLongTermPresence(): Boolean {
for (address in addresses) {
val presenceModel = getPresenceModelForUriOrTel(address.asStringUriOnly())
if (presenceModel != null && presenceModel.basicStatus == PresenceBasicStatus.Open) return true

View file

@ -72,7 +72,7 @@
android:src="@drawable/linphone_logo_tinted"
android:layout_marginRight="10dp"
android:contentDescription="@string/content_description_linphone_user"
android:visibility="@{viewModel.hasPresence() ? View.VISIBLE : View.GONE}" />
android:visibility="@{viewModel.hasLongTermPresence ? View.VISIBLE : View.GONE, default=gone}" />
<CheckBox
android:onClick="@{() -> selectionListViewModel.onToggleSelect(position)}"