Untitled
unknown
kotlin
16 days ago
1.2 kB
3
Indexable
class ChatMessageItem( private val message: String, private val name: String, private val color: Int, private val isSentByMe: Boolean, private val timestamp: Long = System.currentTimeMillis() ) : Item<GroupieViewHolder>() { override fun getLayout(): Int { return R.layout.item_message } override fun bind(viewHolder: GroupieViewHolder, position: Int) { val tvFrom = viewHolder.itemView.findViewById<TextView>(R.id.tvFrom) val tvMessage = viewHolder.itemView.findViewById<TextView>(R.id.tvMessage) val tvTime = viewHolder.itemView.findViewById<TextView>(R.id.tvTime) val cardRoot = viewHolder.itemView.findViewById<MaterialCardView>(R.id.cardRoot) tvFrom.text = name tvMessage.text = message cardRoot.setCardBackgroundColor(color) val sdf = SimpleDateFormat("HH:mm", Locale.getDefault()) tvTime.text = sdf.format(Date(timestamp)) val params = cardRoot.layoutParams as FrameLayout.LayoutParams params.gravity = if (isSentByMe) Gravity.START else Gravity.END cardRoot.layoutParams = params } }
Editor is loading...
Leave a Comment