Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package io.getstream.livestreamclone
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
class MessagesListAdapter() : ListAdapter<Message, MessageViewHolder>(DiffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.item_message, parent, false)
return MessageViewHolder(itemView)
override fun onBindViewHolder(holder: MessageViewHolder, position: Int) {
companion object {
val DiffCallback = object : DiffUtil.ItemCallback<Message>() {
override fun areItemsTheSame(oldItem: Message, newItem: Message): Boolean {
return ==
override fun areContentsTheSame(oldItem: Message, newItem: Message): Boolean {
return oldItem == newItem
class MessageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindMessage(message: Message) {
message.apply {
itemView.avatar.loadUrl(user.image, R.drawable.ic_person_white_24dp)
itemView.userName.text =
itemView.message.text = text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.