I am creating an app in which i am using RxJava and paging 3 library. I am using RxPagingSource and Retrofit to paginate response coming from Server but i have to fetch some data from Firestore and have to paginate
override fun loadSingle(params: LoadParams<QuerySnapshot>): Single<LoadResult<QuerySnapshot, Notification>> {
var currentPage : QuerySnapshot
if(params.key != null){
currentPage = params.key!!
}else{
reference
.limit(10)
.get()
.addOnCompleteListener(OnCompleteListener {
if(it.isSuccessful){
currentPage = it.result
val lastDocumentSnapshot = it.result.documents[it.result.size() - 1]
reference
.limit(10)
.startAfter(lastDocumentSnapshot)
.get()
.addOnCompleteListener(OnCompleteListener {
val nextPage: QuerySnapshot
if(it.isSuccessful){
nextPage = it.result
return Single.just(
LoadResult.Page(
data = currentPage.toObjects(Notification::class.java),
prevKey = null,
nextKey = nextPage
)
)
//return
}
})
}
})
}
This is code i tried but its not working for me, there is many mistake in this code
How can i paginate Firestore data using RxPagingSource provided by Paging 3 library