-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
How create my own DiffUtils? #893
Comments
So the sample showcases the default implementation which uses the This basically uses the identifier to see if a item is the same, and the quals method to see if the content of the items are the same If your items have a proper identifier defined and implement the correct equals method then this will already cover 95% of all usecases. As there are still 5% of the cases left then you can implement your own If in the end neither matches your requirements. The FastAdapter is a regular RecyclerView.Adapter implementation so yo can go barebones and simply use the original API for the diffUtil. |
@mikepenz thank U for your response, And I forced to split this logic. |
In this case you most likely will be best off doing it manually. Have a look at the impl of the calculate diff to get a better understanding what it does for you: |
@mikepenz And I've a question, I've created my own
I've tried like this:
If I write only set(), without clear(), then I see a blink effect after update the data even it hasn't changed! Or perhaps, did I do anything wrong? P.S.
It'll be cool if the next version of lib could be do it how the auto as the manually. |
It's kind of like we do internally here: https://github.com/mikepenz/FastAdapter/blob/develop/library-extensions-diff/src/main/java/com/mikepenz/fastadapter/diff/FastAdapterDiffUtil.kt#L56-L65 we update the list of items from the adapter (without letting it know about the changes yet) One thing you do different though is that you do not update the list, but the adapter directly. so it will already call the respective notify methods. so if you do it like above there is no need to use a diff util anymore. what you want to do instead is, is to replace and update the list of items only (not the adapter which will result in the notifies) and after that set the result of the diff util. which will result in the diff util calling the notify methods based on the changes. this will allow the diff util to tell the adapter if things were moved, removed, or added. |
@mikepenz
And then I can get diff result into my presenter(on the background) and set an items and diff's result into my Fragment. Perhaps it'll be helpful and this opportunity will be available into new version's this lib :) Thx for your responses! |
If I am not mistaken there may be issues if you do
before the diff got calculated. at least that's what I remember |
@Z-13 perhaps you could have a look at the PR and see if it would serve your requirements too |
Wow, it looks nice) Why? Since as my case I count a diffResult into the Presenter and it doesn't know about the adapter from my View(Fragment). My Presenter loads items and on background thread get a diffResult. Then it sends it to my Fragment, like this: Presenter:
Fragment:
I understand that perhaps it looks like too splittable and needs keep track of items, diffResult and types of items. |
Sadly this won't be possible to include int he library directly, as we require the adapter for those methods to apply order (if provided) to apply identifiers (via the id distributor) also we need the list which is inside the adapter. so we can keep a copy to ensure the diffing does not get affected by anything else possibly changing the list in the adapter while diffing. I still hope though that something may be of help for you from the PR :) Glad you could resolve your requirement though. Keep in mind. the FastAdapter is trying to provide simple APIs for the 99% of the usecases, but stay super flexible and as close to standard behavior as possible to allow embracing the functionality from the RV itself |
I would like to create my own
DiffUtil.Callback
and use it for myFastAdapter
.How can I do it?
I've watched this example:
https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/DiffUtilActivity.kt
var identifier: Long
)@mikepenz
May be do U have a little example on this?
Thank U!
The text was updated successfully, but these errors were encountered: