From f8e3e72c185cbbd7fa0b6a41f23e60f9493814bb Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Mon, 13 Jan 2020 19:00:20 -0500 Subject: [PATCH] Fix conversation swipe actions --- .../QKSMS/feature/conversations/ConversationsAdapter.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt index cf741f84..8f1c0041 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt @@ -45,6 +45,11 @@ class ConversationsAdapter @Inject constructor( private val phoneNumberUtils: PhoneNumberUtils ) : QkRealmAdapter() { + init { + // This is how we access the threadId for the swipe actions + setHasStableIds(true) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { val layoutInflater = LayoutInflater.from(parent.context) val view = layoutInflater.inflate(R.layout.conversation_list_item, parent, false) @@ -109,6 +114,10 @@ class ConversationsAdapter @Inject constructor( holder.unread.setTint(colors.theme(recipient).theme) } + override fun getItemId(position: Int): Long { + return getItem(position)?.id ?: -1 + } + override fun getItemViewType(position: Int): Int { return if (getItem(position)?.unread == false) 0 else 1 }