I can get a total number of records from the server, so I am using PositionalDataSource
for Network call. Everything works well but one problem: even if I don't scroll, the paging library continues fetching all the data from the server. How to solve this problem?
Using: androidx.paging:paging-runtime-ktx:2.1.1
Example:
override fun loadInitial(params: LoadInitialParams, callback: LoadInitialCallback<Doctor>) {
fetchDataFromApi(params.requestedStartPosition, params.pageSize) { list, totalCount ->
callback.onResult(list, 0, totalCount)
}
}
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<Doctor>) {
fetchDataFromApi(params.startPosition, params.loadSize) { list, totalCount ->
callback.onResult(list)
}
}
PagedList.Config.Builder()
.setPageSize(14)
.setPrefetchDistance(4)
.setInitialLoadSizeHint(14)
.setEnablePlaceholders(true)
.build()