kozmi55 / Flexible-RecyclerView-with-Databinding

A RecyclerView Adapter that can handle multiple item types without much boilerplate and can be reused on any screen with list content.
Apache License 2.0
28 stars 15 forks source link

How I can implement DiffCallback in recyclerViewAdapter in this project? #3

Closed FitApps7 closed 2 years ago

FitApps7 commented 2 years ago

I am using your approach in my project, I am using live data having two types of views, when I make changes in data, whole recyclerView invalidate to overcome this issue I want to implement DiffCallback, please guide me How I can?

https://user-images.githubusercontent.com/35890924/157379068-afd7e4ac-c8f8-4d31-9cbc-33963df46a6b.mp4

kozmi55 commented 2 years ago

Hi, I think DiffUtil is not what you need to fix this issue. In your case you should only update the one item that you interact with. This can be done by making the items itself Observable so their views react to changes. This is covered in the linked article under the Making an ItemViewModel observable section.

If you still want to implement DiffUtil in your app to make animations more smoother when something changes in a list I added sample code for that in my latest commit: 69ef882747c597d327561cea6d358d3cfa400317

The code is pretty simple I think, you just basically have to delegate the comparing functions to the ItemViewModel classes. I plan to write a follow up article about it when I get the time.

FitApps7 commented 2 years ago

Hi, I think DiffUtil is not what you need to fix this issue. In your case you should only update the one item that you interact with. This can be done by making the items itself Observable so their views react to changes. This is covered in the linked article under the Making an ItemViewModel observable section.

If you still want to implement DiffUtil in your app to make animations more smoother when something changes in a list I added sample code for that in my latest commit: 69ef882747c597d327561cea6d358d3cfa400317

The code is pretty simple I think, you just basically have to delegate the comparing functions to the ItemViewModel classes. I plan to write a follow up article about it when I get the time.

thanks, @kozmi55