问题描述
实际上,我正在尝试从页面2迁移到页面3。我已经在我的代码库中成功地使用RxpagingSource实现了页面2的PageKeyedDataSource。但是,当我尝试将Paging 2的ItemKeyedDataSource实现到Paging库3时,我很困惑地实现了这一点。我也尝试编码。但被卡住了。这是我的代码。
JobSliderRestApi.kt
@GET("job/list/slides")
fun getDetailOfSelectedJob(
@Query("current_job") currentJodId: Int?,@Query("limit") jobLimit: Int?,@Query("search_in") fetchType: String?
): Single<Response<JobViewResponse>>
JobViewResponse.kt
data class JobViewResponse(
@SerializedName("data") val data: ArrayList<JobDetail>?
) : BaseResponse()
JodSliderDataSource.kt
class JodSliderDataSource @Inject constructor(
private val jobSliderRestApi: JobSliderRestApi,private val currentJobId: Int
): RxPagingSource<Int,JobDetail>() {
override fun loadSingle(params: LoadParams<Int>): Single<LoadResult<Int,JobDetail>> {
return jobSliderRestApi.getDetailOfSelectedJob(currentJobId,20,"next").toSingle()
.subscribeOn(Schedulers.io())
.map { jobResponse -> jobResponse.data }
.map { jobData -> toLoadResult(jobData,position) } // Don't know what to do
.onErrorReturn { LoadResult.Error(it) }
}
//Don't know what to do
private fun toLoadResult(data: JobDetail,position: Int): LoadResult<Int,JobDetail> {
/**val prevKey = if (position == 1) null else position-1
val nextKey = if (data.hasMore) position+1 else null
return LoadResult.Page(data.jobs,prevKey,nextKey)*/
}
@ExperimentalPagingApi
override fun getRefreshKey(state: PagingState<Int,JobDetail>): Int? {
return super.getRefreshKey(state)
}
}
事实上,以前我使用'currentJodId'来区分Paging 2中的列表,但是在第3页中,我没有任何线索可以解决这些问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)