1

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)?

Azizjon Kholmatov
  • 1,136
  • 1
  • 13
  • 26
  • Why are you passing empty list ? You just have to check that Your ListView or RecyclerView is scrolled up to end or not and then call the service to fetch the data. – Jaimin Modi Sep 04 '19 at 13:21
  • @JaiminModi I am not passing empty list all the time. Please note that I pass only empty list if all the items in my list matches my conditions and gets deleted. – Azizjon Kholmatov Sep 04 '19 at 13:38
  • Please explain how your server gives you response according to page count or any other logic ? You can make your own paging implementation and use it according to your need. – Jaimin Modi Sep 04 '19 at 13:43
  • blablabla.com/history/pageNum/pageSiz/userId Here pageNum is number of the page. pageSize is the size of the page. userId is the id of the user. Yes, I know that I can implement my paging. But I need to use paging library. – Azizjon Kholmatov Sep 04 '19 at 13:45

0 Answers0