Skip to content

Commit

Permalink
update chatHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
rlam20 committed Jul 2, 2024
1 parent 33cf79b commit 2fb2be2
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,23 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List
}

fun updateChatHistory(newChatHistory: List<RealmChatHistory>) {
val oldListSize = chatHistory.size
val newListSize = newChatHistory.size
chatHistory = newChatHistory
filteredChatHistory = newChatHistory
notifyDataSetChanged()
if(oldListSize<newListSize){
notifyItemRangeInserted(oldListSize,newListSize-oldListSize)
}
else if(oldListSize>newListSize){
notifyItemRangeRemoved(newListSize,oldListSize-newListSize)
}
else{
for(i in 0 until newListSize){
if(chatHistory[i] != newChatHistory[i]){
notifyItemChanged(i)
}
}
}
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
Expand Down

0 comments on commit 2fb2be2

Please sign in to comment.