I am using paging library to handle the pagination.
Here is my DataSource
class where requests are sent to server.
class HistoryDataSource() : PageKeyedDataSource<Int, DummyObject>() {
override fun loadInitial(
params: LoadInitialParams<Int>,
callback: LoadInitialCallback<Int, DummyObject>) {
//First load
}
override fun loadAfter(
params: LoadParams<Int>,
callback: LoadCallback<Int, DummyObject>) {
authApi.loadHistoryForCard(params.key.toInt(), params.requestedLoadSize, cardToken)
.subscribe({ response ->
//HERE I DELETE THE FIRST N ITEMS ACCORDING TO SOME CONDITION.
//THEN PASS LIST TO CALLBACK
callback.onResult(
response.list,
params.key + 1
)
},{
//handle error here
}).also {}
}
override fun loadBefore(
params: LoadParams<Int>,
callback: LoadCallback<Int, DummyObject>) {
}
}
BUT: when I am deleting certain items in the list, I might end up with a with a situation where all items are deleted and list might be empty. Then, I need to pass this empty list to callback.
The issue is that if I pass empty list to callback, paging library thinks that this is the end of the list. But actually it is not. There are still more items in the server.
How can I continue sending requests to load next bunk of items even though I pass empty list to callback?
Or (paraphrasing the question) How can I let paging library know that it is not the end of the list (even though i passing empty list to callback)?