Skip to content

Instantly share code, notes, and snippets.

@TobiAlbert
Created June 17, 2019 11:20
Show Gist options
  • Select an option

  • Save TobiAlbert/ea5dd542a5ed30838905df8f844ea6f3 to your computer and use it in GitHub Desktop.

Select an option

Save TobiAlbert/ea5dd542a5ed30838905df8f844ea6f3 to your computer and use it in GitHub Desktop.
class RoomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(message: Message, championId: String) {
val layoutParams = itemView.message_root_view.layoutParams as LinearLayoutCompat.LayoutParams
if (message.sender.id == championId) {
layoutParams.gravity = Gravity.END
itemView.message_root_view.layoutParams = layoutParams
} else {
layoutParams.gravity = Gravity.START
itemView.message_root_view.layoutParams = layoutParams
}
val payload = message.parts.first().payload
val messageText = when (payload) {
is Payload.Inline -> payload.content
else -> ""
}
itemView.message_text.text = messageText
}
companion object {
fun create(parent: ViewGroup): RoomViewHolder {
val rootView = LayoutInflater.from(parent.context)
.inflate(R.layout.chat_item, parent, false)
return RoomViewHolder(rootView)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment