Fix concurrent modification exception

This commit is contained in:
Naveen Singh 2025-03-21 02:53:32 +05:30
parent 2a9b5b6d85
commit 0f098fc1e1
No known key found for this signature in database
GPG key ID: AF5D43C216778C0B

View file

@ -30,7 +30,7 @@ abstract class BaseConversationsAdapter(
activity: SimpleActivity, activity: SimpleActivity,
recyclerView: MyRecyclerView, recyclerView: MyRecyclerView,
onRefresh: () -> Unit, onRefresh: () -> Unit,
itemClick: (Any) -> Unit itemClick: (Any) -> Unit,
) : MyRecyclerViewListAdapter<Conversation>( ) : MyRecyclerViewListAdapter<Conversation>(
activity = activity, activity = activity,
recyclerView = recyclerView, recyclerView = recyclerView,
@ -46,10 +46,8 @@ abstract class BaseConversationsAdapter(
init { init {
setupDragListener(true) setupDragListener(true)
ensureBackgroundThread {
fetchDrafts(drafts)
}
setHasStableIds(true) setHasStableIds(true)
updateDrafts()
registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onChanged() = restoreRecyclerViewState() override fun onChanged() = restoreRecyclerViewState()
@ -69,7 +67,7 @@ abstract class BaseConversationsAdapter(
fun updateConversations( fun updateConversations(
newConversations: ArrayList<Conversation>, newConversations: ArrayList<Conversation>,
commitCallback: (() -> Unit)? = null commitCallback: (() -> Unit)? = null,
) { ) {
saveRecyclerViewState() saveRecyclerViewState()
submitList(newConversations.toList(), commitCallback) submitList(newConversations.toList(), commitCallback)
@ -80,9 +78,9 @@ abstract class BaseConversationsAdapter(
ensureBackgroundThread { ensureBackgroundThread {
val newDrafts = HashMap<Long, String>() val newDrafts = HashMap<Long, String>()
fetchDrafts(newDrafts) fetchDrafts(newDrafts)
if (drafts.hashCode() != newDrafts.hashCode()) { activity.runOnUiThread {
drafts = newDrafts if (drafts.hashCode() != newDrafts.hashCode()) {
activity.runOnUiThread { drafts = newDrafts
notifyDataSetChanged() notifyDataSetChanged()
} }
} }