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.