Clear `PagingDataAdapter` between refresh calls
Asked Answered
C

1

16

I am using the Paging 3 PagingDataAdapter to search the database based on the given query. Every time a new query is submitted, i call the refresh() method on the adapter. The problem is that until the new data is loaded, the old one is still present.

Is there a way to remove all items from the list so that no items are present when loading is in progress? Also, I use the ConcatAdapter to attach a header and a footer to indicate loading, so my goal is to have only the progress indicator showing when the data is being loaded/new query is submitted.

Update:

The only way i managed to make it work was to call adapter.submitData(PagingData.empty()) followed by pagingSource.invalidate(). I don't like this solution because it is not easy to gain access to invalidate() method which is available in repository layer and I had to use it in the ViewModel. Is there a more elegant way to achieve this? I don't think that is a way to do so, because the use case of refreshing a list and removing items during the load is quite common and I thought it was taken into account during Paging 3 library development.

Corium answered 25/7, 2021 at 18:57 Comment(0)
M
0

actually, I was forced to clear the cache and reload the data once again from the room side not Paging side I know there is a better solution but this a temp solution

Manama answered 10/2, 2023 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.