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
recycler_view.addOnScrollListener(fabScrollListener)
if (!isReadOnly) {
val touchCallback: ItemTouchHelper.SimpleCallback = object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
return true
}
val touchCallback: ItemTouchHelper.SimpleCallback =
object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
): Boolean {
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
var replyId: String? = null
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
var replyId: String? = null
when (viewHolder) {
is MessageViewHolder -> replyId = viewHolder.data?.messageId
is AttachmentViewHolder -> replyId = viewHolder.data?.messageId
}
when (viewHolder) {
is MessageViewHolder -> replyId = viewHolder.data?.messageId
is AttachmentViewHolder -> replyId = viewHolder.data?.messageId
}
replyId?.let {
citeMessage(chatRoomName, chatRoomType, it, true)
}
replyId?.let {
citeMessage(chatRoomName, chatRoomType, it, true)
adapter.notifyItemChanged(viewHolder.adapterPosition)
}
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 {
// Currently enable swipes for text and attachment messages only
if (viewHolder is MessageViewHolder || viewHolder is AttachmentViewHolder) {
return super.getSwipeDirs(recyclerView, viewHolder)
}
if (viewHolder is MessageViewHolder || viewHolder is AttachmentViewHolder) {
return super.getSwipeDirs(recyclerView, viewHolder)
return 0
}
return 0
}
}
val itemTouchHelper = ItemTouchHelper(touchCallback)
itemTouchHelper.attachToRecyclerView(recycler_view)
ItemTouchHelper(touchCallback).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