Commit a3e1058c authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Improve code.

parent c0b2083b
...@@ -809,39 +809,46 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -809,39 +809,46 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view.addOnScrollListener(fabScrollListener) recycler_view.addOnScrollListener(fabScrollListener)
if (!isReadOnly) { if (!isReadOnly) {
val touchCallback: ItemTouchHelper.SimpleCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) { val touchCallback: ItemTouchHelper.SimpleCallback =
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
return true override fun onMove(
} recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
var replyId: String? = null var replyId: String? = null
when (viewHolder) { when (viewHolder) {
is MessageViewHolder -> replyId = viewHolder.data?.messageId is MessageViewHolder -> replyId = viewHolder.data?.messageId
is AttachmentViewHolder -> replyId = viewHolder.data?.messageId is AttachmentViewHolder -> replyId = viewHolder.data?.messageId
} }
replyId?.let {
citeMessage(chatRoomName, chatRoomType, it, true)
}
replyId?.let { adapter.notifyItemChanged(viewHolder.adapterPosition)
citeMessage(chatRoomName, chatRoomType, it, true)
} }
adapter.notifyItemChanged(viewHolder.adapterPosition) override fun getSwipeDirs(
} recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder
): Int {
// Currently enable swipes for text and attachment messages only
override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { if (viewHolder is MessageViewHolder || viewHolder is AttachmentViewHolder) {
// Currently enable swipes for text and attachment messages only return super.getSwipeDirs(recyclerView, viewHolder)
}
if (viewHolder is MessageViewHolder || viewHolder is AttachmentViewHolder) { return 0
return super.getSwipeDirs(recyclerView, viewHolder)
} }
return 0
} }
}
val itemTouchHelper = ItemTouchHelper(touchCallback) ItemTouchHelper(touchCallback).attachToRecyclerView(recycler_view)
itemTouchHelper.attachToRecyclerView(recycler_view)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment