问题描述
我从分页2迁移到分页3。我尝试将分页2的ItemKeyedDataSource实现到分页库3。但是我面临的问题是,在加载的两个连续页面中,传递了与nextkey相同的值(currentJodId)。然后该应用程序崩溃。但是,如果我在DataSource中添加“ keyReuseSupported = true”,则应用不会崩溃。但是它开始调用与nextkey相同的项目ID。
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()
JobDetail.kt
data class JobDetail(
@SerializedName("job_id") val jobId: Int,@SerializedName("tuition_type") val jobType: String?,@SerializedName("class_image") val jobImage: String,@SerializedName("salary") val salary: String,@SerializedName("no_of_student") val noOfStudent: Int,@SerializedName("student_gender") val studentGender: String,@SerializedName("tutor_gender") val preferredTutor: String,@SerializedName("days_per_week") val daysPerWeek: String?,@SerializedName("other_req") val otherReq: String?,@SerializedName("latitude") val latitude: Double?,@SerializedName("longitude") val longitude: Double?,@SerializedName("area") val area: String,@SerializedName("tutoring_time") val tutoringTime: String?,@SerializedName("posted_date") val postedDate: String?,@SerializedName("subjects") val subjects: String,@SerializedName("title") val title: String
)
JodSliderDataSource.kt
class JodSliderDataSource @Inject constructor(
private val jobSliderRestApi: JobSliderRestApi
): RxPagingSource<Int,JobDetail>() {
// override val keyReuseSupported = true
@ExperimentalPagingApi
override fun getRefreshKey(state: PagingState<Int,JobDetail>): Int? {
return state.anchorPosition?.let {
state.closestItemToPosition(it)?.jobId
}
}
override fun loadSingle(params: LoadParams<Int>): Single<LoadResult<Int,JobDetail>> {
return jobSliderRestApi.getDetailOfSelectedJob(42673,2,"next").toSingle()
.subscribeOn(Schedulers.io())
.map { jobResponse -> toLoadResult(jobResponse.data) }
.onErrorReturn { LoadResult.Error(it) }
}
private fun toLoadResult(data: ArrayList<JobDetail>): LoadResult<Int,JobDetail> {
return LoadResult.Page(data = data,prevKey = null,nextKey = data.lastOrNull()?.jobId)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)