architecture-components-samples
architecture-components-samples copied to clipboard
Load a list at specified item position with Paging + Room
Are there any plans to provide a sample showing how to load a PagingSource from the Room's Dao at a certain item position?
Example:
- User sends me an image.
- I click on it and it opens in a fullscreen view
- In that same screen I also display all the images the user sent to me at the bottom in an horizontal list using Paging + Room
- That list is initially loaded with the clicked item visible in the view
- the item that is in fullscreen view is also in this bottom image list visible to the user to help him locate the image in between the other images in that list.
I looked for something like this and I did not find anything.
Thanks for making these great components!
A bit more context here: https://issuetracker.google.com/176503896
In general there are basically two ways to do this:
- Changing
initialKeypassed toPager - enablePlaceholders in PagingConfig, set jumpThreshold and implement jumpingSupport + getRefreshKey() in PagingSource to allow fast-scroll behavior that allows you to load from scratch from an arbitrary position, without appending / prepending until you get there.
However if you are using Room, in both cases you need a way to map the desired starting item to the position in Room which unfortunately is quite hard until we can figure out how to support item-keyed paging source in Room. The easiest way is probably to implement a custom item-keyed PagingSource that just queries from Room, but allows you to use the same key across your app + paging integration.
Has there been any improvement done around this issue, or is the same dilemma present in the current versions of the Paging library?
Room does not support item keyed paging yet - they've moved to paging3 but still have some ways to go to get to item keyed.
SQLDelight allows a key map argument for their paging integration which supports item keyed, but yigit will hunt me down for telling you this :)
Any update on this?