Obsolete
Status Update
Comments
ad...@google.com <ad...@google.com> #2
We have passed this to the development team and will update this issue with more information as it becomes available.
sa...@google.com <sa...@google.com> #3
We will be closing this bug as Obsolete. If you still think this issue is reproducible and relevant in the latest Android release (Android Q), please attach a new bug report along with reproduction details. If a reply is not received within the next 14 days, this issue will be closed. Thank you for your understanding.
da...@allaboutapps.at <da...@allaboutapps.at> #4
This is part of the RecyclerView API and the issue remains with the latest AndroidX version. The first line JavaDoc of DiffUtil states
> DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
but without addressing this issue (and including an additional parameter) it is _not_ possible to convert the first list into the second one.
> DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
but without addressing this issue (and including an additional parameter) it is _not_ possible to convert the first list into the second one.
sh...@google.com <sh...@google.com> #5
David,
I'm confused as to what you are trying to achieve. Let's zero in on some terminology:
List: A list of data where each data element is represented in the RV
RV: The UI representation of a list of data, including animations to display changes from one list to another.
DiffUtil is intended to be given 2 lists, and then produce the changes necessary for RV to run animations to show the changes between lists. The changes are controlled internally such that RV understands how to interpret them correctly.
So, given [a, y, z] and [b, y, z], RV should be told that the animations it should run are to
onRemoved at 0, count 1
onInserted at 0, count 1
RV internally is aware that there is a representation that it is showing in UI, and that the views that are generated from the adapter may now be different from what is represented. With the update commands, it will remove the item at 0 with an animation, and it will add an item at 0 (which it will pull from the same index from the adapter).
I'm confused as to what you are trying to achieve. Let's zero in on some terminology:
List: A list of data where each data element is represented in the RV
RV: The UI representation of a list of data, including animations to display changes from one list to another.
DiffUtil is intended to be given 2 lists, and then produce the changes necessary for RV to run animations to show the changes between lists. The changes are controlled internally such that RV understands how to interpret them correctly.
So, given [a, y, z] and [b, y, z], RV should be told that the animations it should run are to
onRemoved at 0, count 1
onInserted at 0, count 1
RV internally is aware that there is a representation that it is showing in UI, and that the views that are generated from the adapter may now be different from what is represented. With the update commands, it will remove the item at 0 with an animation, and it will add an item at 0 (which it will pull from the same index from the adapter).
da...@gmail.com <da...@gmail.com> #6
> DiffUtil is intended to be given 2 lists, and then produce the changes necessary for RV to run animations to show the changes between lists.
I'm not talking about the RV here. I'm talking about using DiffUtil to get the updates necessary to convert the first list into the second one. In my case I am using it for an adapter that manages markers on a map.
The javadoc hints that I can use the DiffUtil for exactly this use case (https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil )
> DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
The fact that RV uses the DiffUtil for its animation purposes gets mentioned as well, but it's not stated as the primary use case
> It can be used to calculate updates for a RecyclerView Adapter.
With the current API it is not possible to convert one list into the other as one crucial index is missing. This index is already used internally and it only needs to be added to the callback method
I'm not talking about the RV here. I'm talking about using DiffUtil to get the updates necessary to convert the first list into the second one. In my case I am using it for an adapter that manages markers on a map.
The javadoc hints that I can use the DiffUtil for exactly this use case (
> DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
The fact that RV uses the DiffUtil for its animation purposes gets mentioned as well, but it's not stated as the primary use case
> It can be used to calculate updates for a RecyclerView Adapter.
With the current API it is not possible to convert one list into the other as one crucial index is missing. This index is already used internally and it only needs to be added to the callback method
ae...@google.com <ae...@google.com>
ps...@gmail.com <ps...@gmail.com> #7
I’m also trying to, given the old list and the new list, calculate the DiffResult, dispatch the result to UpdateListCallback, and apply the resulting callback steps on the old list in such a way that I end up with the new list. That seems to be exactly the use case for UpdateListCallback but it’s just not trivial to do it without some hacks.
For example, suppose onInserted is called saying 3 items were inserted on position 4 of the old list. There’s no way to know, at the moment of the callback, *which* items from new list are being added at this position.
For example, suppose onInserted is called saying 3 items were inserted on position 4 of the old list. There’s no way to know, at the moment of the callback, *which* items from new list are being added at this position.
yb...@google.com <yb...@google.com> #8
We don't keep this information (as RV does not need it) so DiffResult does not have necessary information to apply changes 1 by 1 into the old list.
The only way to do it is to apply some metadata as you go through the updates and once updatese are done, pull them from the new list (that is the only time you can be sure of the position of items).
al...@google.com <al...@google.com> #9
This issue was filed against the top-level component, which is not monitored, and has exceeded the age limit for triage to the appropriate sub-component.
If this issue is still relevant, please re-file it against the appropriate sub-component.
If this issue is still relevant, please re-file it against the appropriate sub-component.
Description
Version used: 1.0.0-rc02
Theme used: -
Devices/Android versions reproduced on: - / all
When trying to update a List by applying the updates from DiffResult there is currently no way to get the correct index in the new list of the items that need to be inserted. Without this information I can't correctly apply all the updates to convert one list into another. move, deletion, and change can all be applied without further issues.
e.g. converting [1, 3] to [2, 3] would result in
onRemoved at 0, count 1
onInserted at 0, count 1 <- there is no way to get the new index of the item that needs to be inserted at `0`
When looking at the source code I discovered `globalIndex` which gets passed into `dispatchAdditions`. The field `globalIndex` marks the end of the current snake and the start index of the items that need to be inserted. This value holds the information that the current API lacks. I could use it to insert the items at [globalIndex .. globalIndex + count] from the new list at `position`.
Hence I would like to ask you to add the value of `globalIndex` to the api of `onInserted` so that we can use DiffUtil to manage updates to lists of items.
e.g. the new interface could look like this
public void onInserted(int position, int count, int insertedItemStartPosition)
Attached is my implementation that uses `globalIndex` with a test that shows that it will enable the correct modification of the original list.
Kind Regards
David