Skip to content

AsyncListDifferDelegationAdapter DiffUtil get payloads inside bind #118

@james04gr

Description

@james04gr

In my project i have a chatbot recyclerView with some models represent each message. I want to continuously update an item's text and when i do i see the flickering effect. So i want to use the DiffUtils with the Payload list in onBindViewHolder. So what i did is the a created my DiffUtil.ItemCallback object and pass it to the AsyncListDifferDelegationAdapter as follow:

        object : AsyncListDifferDelegationAdapter<RowUiItem>(
            MESSAGE_DIFF_UTIL_CALLBACK,
            receiverMessageAdapterDelegate(),
            receiverNameAdapterDelegate(),
            ...other delegates...
        ) {}
    }```

val MESSAGE_DIFF_UTIL_CALLBACK = object : DiffUtil.ItemCallback<RowUiItem>() {
   //override methods and logic here

  override fun getChangePayload(
        oldItem: RowUiItem,
        newItem: RowUiItem
    ): Any? =
        if (oldItem is ServerMessageUiItem && newItem is ServerMessageUiItem) {
            if (oldItem.message.size != newItem.message.size) Bundle().apply {
                putString("key", "message_text")
            }
            else super.getChangePayload(oldItem, newItem)
        }
        else super.getChangePayload(oldItem, newItem)
}

Each delegate has the following form 
```fun receiverMessageAdapterDelegate() =
    adapterDelegateViewBinding<ReceiverMessageUiItem, RowUiItem, ItemReceiverMessageBinding>(
        { layoutInflater, parent ->
            ItemReceiverMessageBinding.inflate(layoutInflater, parent, false)
        }
    ) {
        bind { it: List<Any>
                 ....set up views here
                 // I want to take the Bundle payload here
        }

Since i want to update the View using the payload from the "getChangePayload" inside the bind block, i want to ask how i can have those payload inside the bind block. Using the debugging mode i see that the DiffUtil never gets called

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions