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,
|
oldItem: EventLogData,
|
||||||
newItem: EventLogData
|
newItem: EventLogData
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return if (oldItem.eventLog.type == EventLog.Type.ConferenceChatMessage &&
|
return if (oldItem.type == EventLog.Type.ConferenceChatMessage &&
|
||||||
newItem.eventLog.type == EventLog.Type.ConferenceChatMessage
|
newItem.type == EventLog.Type.ConferenceChatMessage
|
||||||
) {
|
) {
|
||||||
oldItem.eventLog.chatMessage?.time == newItem.eventLog.chatMessage?.time &&
|
val oldData = (oldItem.data as ChatMessageData)
|
||||||
oldItem.eventLog.chatMessage?.isOutgoing == newItem.eventLog.chatMessage?.isOutgoing
|
val newData = (newItem.data as ChatMessageData)
|
||||||
} else oldItem.eventLog.notifyId == newItem.eventLog.notifyId
|
|
||||||
|
oldData.time.value == newData.time.value &&
|
||||||
|
oldData.isOutgoing == newData.isOutgoing
|
||||||
|
} else oldItem.notifyId == newItem.notifyId
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun areContentsTheSame(
|
override fun areContentsTheSame(
|
||||||
oldItem: EventLogData,
|
oldItem: EventLogData,
|
||||||
newItem: EventLogData
|
newItem: EventLogData
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return if (oldItem.eventLog.type == EventLog.Type.ConferenceChatMessage &&
|
return if (oldItem.type == EventLog.Type.ConferenceChatMessage &&
|
||||||
newItem.eventLog.type == EventLog.Type.ConferenceChatMessage
|
newItem.type == EventLog.Type.ConferenceChatMessage
|
||||||
) {
|
) {
|
||||||
val oldData = (oldItem.data as ChatMessageData)
|
val oldData = (oldItem.data as ChatMessageData)
|
||||||
val newData = (newItem.data as ChatMessageData)
|
val newData = (newItem.data as ChatMessageData)
|
||||||
|
|
||||||
val previous = oldData.hasPreviousMessage == newData.hasPreviousMessage
|
val previous = oldData.hasPreviousMessage == newData.hasPreviousMessage
|
||||||
val next = oldData.hasNextMessage == newData.hasNextMessage
|
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 {
|
} else {
|
||||||
oldItem.eventLog.type != EventLog.Type.ConferenceChatMessage &&
|
oldItem.type != EventLog.Type.ConferenceChatMessage &&
|
||||||
newItem.eventLog.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 replyData = MutableLiveData<ChatMessageData>()
|
||||||
|
|
||||||
|
val isDisplayed = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
|
val isOutgoing = chatMessage.isOutgoing
|
||||||
|
|
||||||
var hasPreviousMessage = false
|
var hasPreviousMessage = false
|
||||||
var hasNextMessage = false
|
var hasNextMessage = false
|
||||||
|
|
||||||
|
@ -168,6 +172,8 @@ class ChatMessageData(val chatMessage: ChatMessage) : GenericContactData(chatMes
|
||||||
ChatMessage.State.Displayed -> R.drawable.chat_read
|
ChatMessage.State.Displayed -> R.drawable.chat_read
|
||||||
else -> R.drawable.chat_error
|
else -> R.drawable.chat_error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDisplayed.value = state == ChatMessage.State.Displayed
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateContentsList() {
|
private fun updateContentsList() {
|
||||||
|
|
|
@ -23,7 +23,11 @@ import org.linphone.contact.GenericContactData
|
||||||
import org.linphone.core.EventLog
|
import org.linphone.core.EventLog
|
||||||
|
|
||||||
class EventLogData(val eventLog: 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!!)
|
ChatMessageData(eventLog.chatMessage!!)
|
||||||
} else {
|
} else {
|
||||||
EventData(eventLog)
|
EventData(eventLog)
|
||||||
|
|
|
@ -331,8 +331,6 @@ private suspend fun loadContactPictureWithCoil(
|
||||||
color: Int = 0,
|
color: Int = 0,
|
||||||
textColor: Int = 0
|
textColor: Int = 0
|
||||||
) {
|
) {
|
||||||
coroutineScope {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
val context = imageView.context
|
val context = imageView.context
|
||||||
val displayName = contact.contact.value?.name ?: contact.displayName.value.orEmpty()
|
val displayName = contact.contact.value?.name ?: contact.displayName.value.orEmpty()
|
||||||
|
@ -342,17 +340,15 @@ private suspend fun loadContactPictureWithCoil(
|
||||||
error(
|
error(
|
||||||
if (contact.showGroupChatAvatar) {
|
if (contact.showGroupChatAvatar) {
|
||||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
imageView.background = bg
|
imageView.background = bg
|
||||||
}
|
|
||||||
AppCompatResources.getDrawable(context, R.drawable.icon_multiple_contacts_avatar)
|
AppCompatResources.getDrawable(context, R.drawable.icon_multiple_contacts_avatar)
|
||||||
} else if (displayName.isEmpty() || AppUtils.getInitials(displayName) == "+") {
|
} else if (displayName.isEmpty() || AppUtils.getInitials(displayName) == "+") {
|
||||||
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
val bg = AppCompatResources.getDrawable(context, R.drawable.generated_avatar_bg)
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
imageView.background = bg
|
imageView.background = bg
|
||||||
}
|
|
||||||
AppCompatResources.getDrawable(context, R.drawable.icon_single_contact_avatar)
|
AppCompatResources.getDrawable(context, R.drawable.icon_single_contact_avatar)
|
||||||
} else {
|
} else {
|
||||||
|
coroutineScope {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
val builder = ContactAvatarGenerator(context)
|
val builder = ContactAvatarGenerator(context)
|
||||||
builder.setLabel(displayName)
|
builder.setLabel(displayName)
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
|
@ -369,17 +365,15 @@ private suspend fun loadContactPictureWithCoil(
|
||||||
}
|
}
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val bg = AppCompatResources.getDrawable(imageView.context, R.drawable.generated_avatar_bg)
|
val bg = AppCompatResources.getDrawable(imageView.context, R.drawable.generated_avatar_bg)
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
imageView.background = bg
|
imageView.background = bg
|
||||||
}
|
|
||||||
imageView.load(R.drawable.icon_single_contact_avatar)
|
imageView.load(R.drawable.icon_single_contact_avatar)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("coilContact")
|
@BindingAdapter("coilContact")
|
||||||
|
|
Loading…
Reference in a new issue