Commit 24ca7547 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Create and show a popup when clicking on a message

parent 9f22aed7
...@@ -23,6 +23,8 @@ import kotlinx.android.synthetic.main.item_message.view.* ...@@ -23,6 +23,8 @@ import kotlinx.android.synthetic.main.item_message.view.*
import kotlinx.android.synthetic.main.message_attachment.view.* import kotlinx.android.synthetic.main.message_attachment.view.*
class ChatRoomAdapter(private val serverUrl: String, class ChatRoomAdapter(private val serverUrl: String,
private val roomType: String,
private val roomName: String,
private val presenter: ChatRoomPresenter) : RecyclerView.Adapter<ChatRoomAdapter.ViewHolder>() { private val presenter: ChatRoomPresenter) : RecyclerView.Adapter<ChatRoomAdapter.ViewHolder>() {
init { init {
...@@ -32,7 +34,7 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -32,7 +34,7 @@ class ChatRoomAdapter(private val serverUrl: String,
val dataSet = ArrayList<MessageViewModel>() val dataSet = ArrayList<MessageViewModel>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(parent.inflate(R.layout.item_message), serverUrl, presenter) ViewHolder(parent.inflate(R.layout.item_message), serverUrl, roomType, roomName, presenter)
override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(dataSet[position]) override fun onBindViewHolder(holder: ViewHolder, position: Int) = holder.bind(dataSet[position])
...@@ -75,7 +77,11 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -75,7 +77,11 @@ class ChatRoomAdapter(private val serverUrl: String,
return dataSet[position].id.hashCode().toLong() return dataSet[position].id.hashCode().toLong()
} }
class ViewHolder(itemView: View, val serverUrl: String, val presenter: ChatRoomPresenter) : RecyclerView.ViewHolder(itemView) { class ViewHolder(itemView: View,
val serverUrl: String,
val roomType: String,
val roomName: String,
val presenter: ChatRoomPresenter) : RecyclerView.ViewHolder(itemView) {
fun bind(message: MessageViewModel) = with(itemView) { fun bind(message: MessageViewModel) = with(itemView) {
bindUserAvatar(message, image_avatar, image_unknown_avatar) bindUserAvatar(message, image_avatar, image_unknown_avatar)
...@@ -88,16 +94,20 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -88,16 +94,20 @@ class ChatRoomAdapter(private val serverUrl: String,
file_name) file_name)
text_content.setOnClickListener { text_content.setOnClickListener {
val popup = PopupMenu(it.context, it) if (!message.systemMessage) {
popup.menuInflater.inflate(R.menu.message_actions, popup.menu) val popup = PopupMenu(it.context, it)
popup.setOnMenuItemClickListener { popup.menuInflater.inflate(R.menu.message_actions, popup.menu)
when (it.itemId) { popup.setOnMenuItemClickListener {
R.id.action_menu_msg_delete -> presenter.deleteMessage(message.roomId, message.id) when (it.itemId) {
else -> TODO("Not implemented") R.id.action_menu_msg_delete -> presenter.deleteMessage(message.roomId, message.id)
R.id.action_menu_msg_quote -> presenter.citeMessage(serverUrl, roomType, roomName, message.id, "", false)
R.id.action_menu_msg_reply -> presenter.citeMessage(serverUrl, roomType, roomName, message.id, "", true)
else -> TODO("Not implemented")
}
true
} }
true popup.show()
} }
popup.show()
} }
} }
......
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