Commit 1671adf9 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update MessageListAdapter

parent f5e4d478
package chat.rocket.android.app.chatroom package chat.rocket.android.app.chatroom
import DateTimeHelper import DateTimeHelper
import android.content.Context
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
...@@ -8,9 +9,10 @@ import android.view.ViewGroup ...@@ -8,9 +9,10 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.R import chat.rocket.android.R
import com.facebook.drawee.view.SimpleDraweeView import com.facebook.drawee.view.SimpleDraweeView
import com.stfalcon.frescoimageviewer.ImageViewer
import kotlinx.android.synthetic.main.item_message.view.* import kotlinx.android.synthetic.main.item_message.view.*
class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerView.Adapter<MessageListAdapter.ViewHolder>() { class MessageListAdapter(private val context: Context, private var dataSet: MutableList<Message>, private val listener: (Message) -> Unit) : RecyclerView.Adapter<MessageListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false) val view = LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false)
...@@ -23,7 +25,25 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi ...@@ -23,7 +25,25 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi
holder.userAvatar.setImageURI(message.user.avatarUri) holder.userAvatar.setImageURI(message.user.avatarUri)
holder.userName.text = message.user.name holder.userName.text = message.user.name
holder.time.text = DateTimeHelper.getTime(message.localDatetime) holder.time.text = DateTimeHelper.getTime(message.localDatetime)
holder.content.text = message.content
val textContent = message.textContent
if (textContent.isNullOrBlank()) {
holder.textContent.visibility = View.GONE
} else {
holder.textContent.text = textContent
}
val imageAttachmentUri = message.imageAttachmentUri
if (imageAttachmentUri.isNullOrBlank()) {
holder.imageAttachment.visibility = View.GONE
} else {
holder.imageAttachment.setImageURI(imageAttachmentUri)
holder.imageAttachment.setOnClickListener({
ImageViewer.Builder(context, listOf(imageAttachmentUri))
.hideStatusBar(false)
.show()
})
}
} }
override fun getItemCount(): Int = dataSet.size override fun getItemCount(): Int = dataSet.size
...@@ -32,6 +52,9 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi ...@@ -32,6 +52,9 @@ class MessageListAdapter(private var dataSet: MutableList<Message>) : RecyclerVi
val userAvatar: SimpleDraweeView = itemView.image_user_avatar val userAvatar: SimpleDraweeView = itemView.image_user_avatar
val userName: TextView = itemView.text_user_name val userName: TextView = itemView.text_user_name
val time: TextView = itemView.text_message_time val time: TextView = itemView.text_message_time
val content: TextView = itemView.text_content val textContent: TextView = itemView.text_content
val imageAttachment: SimpleDraweeView = itemView.image_attachment
} }
} }
\ No newline at end of file
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