android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.37k stars 8.28k forks source link

Load a list at specified item position with Paging + Room #924

Open ParticleCore opened 3 years ago

ParticleCore commented 3 years ago

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:

I looked for something like this and I did not find anything.

Thanks for making these great components!

dlam commented 3 years ago

A bit more context here: https://issuetracker.google.com/176503896

In general there are basically two ways to do this:

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.

ParticleCore commented 2 years ago

Has there been any improvement done around this issue, or is the same dilemma present in the current versions of the Paging library?

dlam commented 2 years ago

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 :)

ParticleCore commented 1 year ago

Any update on this?