package cn.flightfeather.thirdappmodule.repository
|
|
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
|
import cn.flightfeather.thirdappmodule.common.net.NetWorkProgressListener
|
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
|
import cn.flightfeather.thirdappmodule.common.net.ResultObserver
|
import cn.flightfeather.thirdappmodule.common.net.RetrofitFactory
|
import cn.flightfeather.thirdappmodule.httpservice.SearchService
|
import cn.flightfeather.thirdappmodule.model.bean.BaseResponse
|
import cn.flightfeather.thirdappmodule.model.bean.ExcelConfigVo
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.schedulers.Schedulers
|
import okhttp3.ResponseBody
|
import retrofit2.Response
|
|
/**
|
* @author riku
|
* Date: 2020/6/15
|
*/
|
class SearchRepository {
|
|
val retrofit = RetrofitFactory.instance.retrofit
|
|
fun getExcel(excelConfigVo: ExcelConfigVo, resultCallBack: ResultCallBack<Response<ResponseBody>>, listener: NetWorkProgressListener? = null) {
|
val service = RetrofitFactory.withProgressListeningRetrofit(listener).create(SearchService::class.java)
|
.getExcel(excelConfigVo)
|
.subscribeOn(Schedulers.io())
|
.observeOn(AndroidSchedulers.mainThread())
|
.subscribe({
|
resultCallBack.onSuccess(it)
|
},{
|
resultCallBack.onFailure()
|
})
|
}
|
|
fun searchSubtask(userId: String, keyword: String, page: Int, resultCallBack: ResultCallBack<List<Subtask>>) {
|
val service = retrofit.create(SearchService::class.java).searchSubtask(userId, keyword, page)
|
|
RetrofitFactory.executeResult(service, object : ResultObserver<BaseResponse<List<Subtask>>>() {
|
override fun onSuccess(result: BaseResponse<List<Subtask>>?) {
|
resultCallBack.onSuccess(result?.data)
|
}
|
|
override fun onPage(current: Int, total: Int) {
|
super.onPage(current, total)
|
resultCallBack.onPage(current, total)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
})
|
}
|
}
|