tweak the way adapters are updated

This commit is contained in:
tibbi 2021-05-23 17:53:18 +02:00
parent 9c0ef0fbe9
commit b02b54b055
2 changed files with 6 additions and 4 deletions

View File

@ -209,10 +209,11 @@ class ConversationsAdapter(
}
fun updateConversations(newConversations: ArrayList<Conversation>) {
val latestConversations = newConversations.clone() as ArrayList<Conversation>
val oldHashCode = conversations.hashCode()
val newHashCode = newConversations.hashCode()
val newHashCode = latestConversations.hashCode()
if (newHashCode != oldHashCode) {
conversations = newConversations
conversations = latestConversations
notifyDataSetChanged()
}
}

View File

@ -201,10 +201,11 @@ class ThreadAdapter(
private fun isThreadDateTime(position: Int) = messages.getOrNull(position) is ThreadDateTime
fun updateMessages(newMessages: ArrayList<ThreadItem>) {
val latestMessages = newMessages.clone() as ArrayList<ThreadItem>
val oldHashCode = messages.hashCode()
val newHashCode = newMessages.hashCode()
val newHashCode = latestMessages.hashCode()
if (newHashCode != oldHashCode) {
messages = newMessages
messages = latestMessages
notifyDataSetChanged()
recyclerView.scrollToPosition(messages.size - 1)
}