Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncListDifferDelegationAdapter DiffUtil get payloads inside bind #118

Open
james04gr opened this issue Apr 25, 2024 · 0 comments
Open

Comments

@james04gr
Copy link

james04gr commented Apr 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant