From c7fa7ad15f3ab33ce5a14634278e6d96af145631 Mon Sep 17 00:00:00 2001 From: rlam20 <52076121+rlam20@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:20:27 -0400 Subject: [PATCH] chats: smoother history (fixes #3747) (#3748) Co-authored-by: Gideon Okuro Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/ui/chat/ChatAdapter.kt | 4 ++-- .../ui/chat/ChatHistoryListAdapter.kt | 20 ++++++++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 15a602428d..254c407f58 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1648 - versionName "0.16.48" + versionCode 1649 + versionName "0.16.49" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt index 61ce6f0bd5..a327aa6c5a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt @@ -77,9 +77,9 @@ class ChatAdapter(private val chatList: ArrayList, val context: Context, } fun clearData() { + val size = chatList.size chatList.clear() - notifyDataSetChanged() - scrollToLastItem() + notifyItemRangeRemoved(0, size) } private fun scrollToLastItem() { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt index b7998da7ea..8026674585 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt @@ -55,10 +55,10 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List if (chat.conversations != null && chat.conversations?.isNotEmpty() == true) { chat.conversations?.get(0)?.query?.contains(query, ignoreCase = true) == true } else { - chat.title?.contains(query, ignoreCase = true) ==true + chat.title?.contains(query, ignoreCase = true) == true } } - notifyDataSetChanged() + notifyItemRangeChanged(0, filteredChatHistory.size) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { @@ -77,9 +77,23 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List } fun updateChatHistory(newChatHistory: List) { + val oldListSize = chatHistory.size + val newListSize = newChatHistory.size chatHistory = newChatHistory filteredChatHistory = newChatHistory - notifyDataSetChanged() + if(oldListSizenewListSize){ + 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) {