I have a list with pagination which I implemented using Paging library. Items on this list can be modified (changed/deleted).
According to official documentation, I'm first changing in-memory list cache from which my DataSource
gets pages and after that calling datasource.invalidate()
in order to create new pair PagedList/DataSource
:
If you have more granular update signals, such as a network API signaling an update to a single item in the list, it's recommended to load data from network into memory. Then present that data to the PagedList via a DataSource that wraps an in-memory snapshot. Each time the in-memory copy changes, invalidate the previous DataSource, and a new one wrapping the new state of the snapshot can be created.
It works and looks WELL if user modifies items on first page.
However, if user is on page two or further during datasource.invalidate()
he will be thrown at the end of the first page.
Debugging shows this happens because new PagedList
has only first page when it's submitted to PagedListAdapter.submitList
. Adapter compares old and new lists and removes all items not from first page. It happens always but not visible for user if he is on the first page.
So to me, it looks like new pair PagedList/DataSource
have no idea about number of pages which fetched previous pair and datasource.invalidate()
doesn't fit for the situation in docs. Behavior that I see acceptable for cases then user updates all list (like swipe-to-refresh) but not
an update to a single item in the list
Has anybody faced such issue or somehow archived things I want? Maybe I'm missing some trick which helps me to get new PagedList
already with all pages.
For clarification: library version 2.1.0
. Custom PageKeyedDataSource
based on in-memory cache and remote servise (No Room
)