Should prevent ANRs
This commit is contained in:
parent
c5a34363a3
commit
312ae2eaf0
4 changed files with 49 additions and 41 deletions
|
@ -466,30 +466,34 @@ private class ChatMessageDiffCallback : DiffUtil.ItemCallback<EventLogData>() {
|
|||
oldItem: EventLogData,
|
||||
newItem: EventLogData
|
||||
): Boolean {
|
||||
return if (oldItem.eventLog.type == EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.eventLog.type == EventLog.Type.ConferenceChatMessage
|
||||
return if (oldItem.type == EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.type == EventLog.Type.ConferenceChatMessage
|
||||
) {
|
||||
oldItem.eventLog.chatMessage?.time == newItem.eventLog.chatMessage?.time &&
|
||||
oldItem.eventLog.chatMessage?.isOutgoing == newItem.eventLog.chatMessage?.isOutgoing
|
||||
} else oldItem.eventLog.notifyId == newItem.eventLog.notifyId
|
||||
val oldData = (oldItem.data as ChatMessageData)
|
||||
val newData = (newItem.data as ChatMessageData)
|
||||
|
||||
oldData.time.value == newData.time.value &&
|
||||
oldData.isOutgoing == newData.isOutgoing
|
||||
} else oldItem.notifyId == newItem.notifyId
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(
|
||||
oldItem: EventLogData,
|
||||
newItem: EventLogData
|
||||
): Boolean {
|
||||
return if (oldItem.eventLog.type == EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.eventLog.type == EventLog.Type.ConferenceChatMessage
|
||||
return if (oldItem.type == EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.type == EventLog.Type.ConferenceChatMessage
|
||||
) {
|
||||
val oldData = (oldItem.data as ChatMessageData)
|
||||
val newData = (newItem.data as ChatMessageData)
|
||||
|
||||
val previous = oldData.hasPreviousMessage == newData.hasPreviousMessage
|
||||
val next = oldData.hasNextMessage == newData.hasNextMessage
|
||||
newItem.eventLog.chatMessage?.state == ChatMessage.State.Displayed && previous && next
|
||||
val isDisplayed = newData.isDisplayed.value == true
|
||||
isDisplayed && previous && next
|
||||
} else {
|
||||
oldItem.eventLog.type != EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.eventLog.type != EventLog.Type.ConferenceChatMessage
|
||||
oldItem.type != EventLog.Type.ConferenceChatMessage &&
|
||||
newItem.type != EventLog.Type.ConferenceChatMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,10 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
|||
|
||||
val replyData = MutableLiveData<ChatMessageData>()
|
||||
|
||||
val isDisplayed = MutableLiveData<Boolean>()
|
||||
|
||||
val isOutgoing = chatMessage.isOutgoing
|
||||
|
||||
var hasPreviousMessage = false
|
||||
var hasNextMessage = false
|
||||
|
||||
|
@ -168,6 +172,8 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
|||
ChatMessage.State.Displayed -> R.drawable.chat_read
|
||||
else -> R.drawable.chat_error
|
||||
}
|
||||
|
||||
isDisplayed.value = state == ChatMessage.State.Displayed
|
||||
}
|
||||
|
||||
private fun updateContentsList() {
|
||||
|
|
|
@ -23,7 +23,11 @@ import org.linphone.contact.GenericContactData
|
|||
import org.linphone.core.EventLog
|
||||
|
||||
class EventLogData(val eventLog: EventLog) {
|
||||
val data: GenericContactData = if (eventLog.type == EventLog.Type.ConferenceChatMessage) {
|
||||
val type: EventLog.Type = eventLog.type
|
||||
|
||||
val notifyId = eventLog.notifyId
|
||||
|
||||
val data: GenericContactData = if (type == EventLog.Type.ConferenceChatMessage) {
|
||||
ChatMessageData(eventLog.chatMessage!!)
|
||||
} else {
|
||||
EventData(eventLog)
|
||||
|
|
|
@ -331,28 +331,24 @@ private suspend fun loadContactPictureWithCoil(
|
|||
color: Int = 0,
|
||||
textColor: Int = 0
|
||||
) {
|
||||
coroutineScope {
|
||||
withContext(Dispatchers.IO) {
|
||||
if (contact != null) {
|
||||
val context = imageView.context
|
||||
val displayName = contact.contact.value?.name ?: contact.displayName.value.orEmpty()
|
||||
val source = contact.contact.value?.getPictureUri(useThumbnail)
|
||||
imageView.load(source) {
|
||||
transformations(CircleCropTransformation())
|
||||
error(
|
||||
if (contact.showGroupChatAvatar) {
|
||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||
withContext(Dispatchers.Main) {
|
||||
imageView.background = bg
|
||||
}
|
||||
AppCompatResources.getDrawable(context, R.drawable.icon_multiple_contacts_avatar)
|
||||
} else if (displayName.isEmpty() || AppUtils.getInitials(displayName) == "+") {
|
||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||
withContext(Dispatchers.Main) {
|
||||
imageView.background = bg
|
||||
}
|
||||
AppCompatResources.getDrawable(context, R.drawable.icon_single_contact_avatar)
|
||||
} else {
|
||||
if (contact != null) {
|
||||
val context = imageView.context
|
||||
val displayName = contact.contact.value?.name ?: contact.displayName.value.orEmpty()
|
||||
val source = contact.contact.value?.getPictureUri(useThumbnail)
|
||||
imageView.load(source) {
|
||||
transformations(CircleCropTransformation())
|
||||
error(
|
||||
if (contact.showGroupChatAvatar) {
|
||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||
imageView.background = bg
|
||||
AppCompatResources.getDrawable(context, R.drawable.icon_multiple_contacts_avatar)
|
||||
} else if (displayName.isEmpty() || AppUtils.getInitials(displayName) == "+") {
|
||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||
imageView.background = bg
|
||||
AppCompatResources.getDrawable(context, R.drawable.icon_single_contact_avatar)
|
||||
} else {
|
||||
coroutineScope {
|
||||
withContext(Dispatchers.IO) {
|
||||
val builder = ContactAvatarGenerator(context)
|
||||
builder.setLabel(displayName)
|
||||
if (size > 0) {
|
||||
|
@ -369,16 +365,14 @@ private suspend fun loadContactPictureWithCoil(
|
|||
}
|
||||
builder.build()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val bg = AppCompatResources.getDrawable(imageView.context, R.drawable.generated_avatar_bg)
|
||||
withContext(Dispatchers.Main) {
|
||||
imageView.background = bg
|
||||
}
|
||||
imageView.load(R.drawable.icon_single_contact_avatar)
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val bg = AppCompatResources.getDrawable(imageView.context, R.drawable.generated_avatar_bg)
|
||||
imageView.background = bg
|
||||
imageView.load(R.drawable.icon_single_contact_avatar)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue