Paging library - Boundary callback for network + db with API taking page and size

后端 未结 4 1026
小蘑菇
小蘑菇 2021-02-03 16:35

Short question:

What is the correct way to handle database + network on the Paging library from Architecture components, using an API that uses page + s

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 17:33

    I have a similar API (pageNum + size), I have 2 extra fields in my data class, pageNum and pageSize with defaults 1 and PAGE_SIZE respectively.

    If you're using Network+DB then you'll have onZeroItemsLoaded and onItemAtEndLoaded, In onZeroItemsLoaded send pageNum and pageSize as it is, and in onItemAtEndLoaded increment pageSize by 1 and then send.

    Let's say you have a method fetchData(pageNum, pageSize) when you receive result in this just update the pageNum and pageSize accordingly in each item of this page.

提交回复
热议问题