mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 19:38:08 +00:00
Prevent blinking avatars in list in case they didn't change
This commit is contained in:
parent
ab6911dd11
commit
e267f46fd7
4 changed files with 37 additions and 11 deletions
|
|
@ -431,16 +431,20 @@ class ConversationModel
|
|||
}
|
||||
|
||||
if (isGroup) {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.name = chatRoom.subject
|
||||
val model = ContactAvatarModel(fakeFriend)
|
||||
model.defaultToConversationIcon.postValue(true)
|
||||
model.updateSecurityLevelUsingConversation(chatRoom)
|
||||
avatarModel.postValue(model)
|
||||
if (avatarModel.value == null) {
|
||||
val fakeFriend = coreContext.core.createFriend()
|
||||
fakeFriend.name = chatRoom.subject
|
||||
val model = ContactAvatarModel(fakeFriend)
|
||||
model.defaultToConversationIcon.postValue(true)
|
||||
model.updateSecurityLevelUsingConversation(chatRoom)
|
||||
avatarModel.postValue(model)
|
||||
}
|
||||
} else {
|
||||
avatarModel.postValue(
|
||||
coreContext.contactsManager.getContactAvatarModelForAddress(address)
|
||||
)
|
||||
val model = coreContext.contactsManager.getContactAvatarModelForAddress(address)
|
||||
val oldModel = avatarModel.value
|
||||
if (!model.compare(oldModel)) {
|
||||
avatarModel.postValue(model)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class ContactsListAdapter(
|
|||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: ContactAvatarModel, newItem: ContactAvatarModel): Boolean {
|
||||
return false // oldItem & newItem are always the same because fetched from cache, so return false to force refresh
|
||||
return newItem.compare(oldItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package org.linphone.ui.main.contacts.model
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.annotation.AnyThread
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
|
@ -84,6 +85,27 @@ class ContactAvatarModel
|
|||
refreshSortingName()
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
fun compare(other: ContactAvatarModel?): Boolean {
|
||||
if (other == null) return false
|
||||
|
||||
val picture = picturePath.value
|
||||
val otherPicture = other.picturePath.value
|
||||
if (picture != null && otherPicture != null && picture != otherPicture) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (contactName != other.contactName) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (id != other.id) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun destroy() {
|
||||
if (friend.addresses.isNotEmpty()) {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class HistoryListAdapter : ListAdapter<CallLogModel, RecyclerView.ViewHolder>(Ca
|
|||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: CallLogModel, newItem: CallLogModel): Boolean {
|
||||
return false // ContactAvatarModel will be the same object but with an updated content
|
||||
return newItem.avatarModel.compare(oldItem.avatarModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue