I have paged list to which there is a possibility to apply some filter. After user applies the filters, recyclerview should display 0 items with the loading footer until it loads the first items and fire a LoadResul.Error
in case there is nothing to show.
The footer works fine but you can still see data that was there before calling .invalidate()
and you'll see that data until it gets a new response from backend (which can take some time if you're having bad internet). And in case of error, the old items will still be there and the error footer will appear.
Any idea on how to achieve that ?
I am also using the library with RxJava so here is the DataSource code:
override fun getRefreshKey(state: PagingState<Int, Event>): Int = 1
override fun loadSingle(params: LoadParams<Int>): Single<LoadResult<Int, Event>> {
val key = params.key ?: 1
return repository.getCityEvents(
cityId = globalData.currentCityId,
start = selectedDates?.start?.toApiFormat(),
end = selectedDates?.end?.toApiFormat(),
pageNo = key,
categories = categoryFilters
)
.map { it.content }
.map { toLoadResult(it, params) }
.onErrorReturn { LoadResult.Error(it) }
}
private fun toLoadResult(data: List<Event>, params: LoadParams<Int>): LoadResult<Int, Event> {
val currentKey = params.key ?: 1
return if (data.isEmpty() && currentKey == 1)
LoadResult.Error(NoEventsException())
else
LoadResult.Page(
data = data,
prevKey = null,
nextKey = if (data.size < params.loadSize) null else currentKey + 1
)
}