Suppose I have a flow of search results, where each emitted item is a single search result item (i.e. the flow needs to be collected into a list which forms the search results). Is there a recommended pattern for how to control the collection of this flow from an Android recyclerview adapter? For example, so that items are collected as the user scrolls down the recyclerview perhaps prefetching 5-10 items ahead of the last visible item.
I don’t think that fits my use case. The flow is rather complex in the way items are emitted, not some simple query. No way of knowing the size etc.
i
Ian Lake
08/07/2020, 4:47 PM
That isn't a requirement with Paging 3.0
Ian Lake
08/07/2020, 4:48 PM
The entire Data Source API is Flow based
m
Mark
08/08/2020, 3:40 AM
Isn’t that a flow of list of all items, rather than what I have - a flow of items that make up the list? The examples I see here https://developer.android.com/reference/kotlin/androidx/paging/PagingSource show a page number or key being passed in, but I don’t see how that can work with my use case since I would need to calculate all the preceding items first to know the page number and I cannot work out item N from item N-1
i
Ian Lake
08/08/2020, 5:46 AM
There's no requirement to use page numbers or anything of the sort if that's not what you need. You get to pick what LoadParams you want, what they they are, literally everything.
m
Mark
08/08/2020, 5:52 AM
Ok, so PagingSource has a key generic, so I guess you are saying that can be ignored (use a dummy value) since there is no such key I could use for my flow. But then wouldn’t that mean loading the entire list in one go? Do you have some kind of sample that describes this usage?
Mark
08/12/2020, 7:03 AM
Maybe there is a way to convert the flow of search result items into something which is keyed/paged. At the moment I collect the flow to build a flow of a list of search items (i.e. a list gradually gets bigger until the underlying flow completes). But maybe this collector could associate a key/page with each incremental change. How does that sound?