xuexiangjys / XHttp2

💪A powerful network request library, encapsulated using the RxJava2 + Retrofit2 + OKHttp combination.(一个功能强悍的网络请求库,使用RxJava2 + Retrofit2 + OKHttp组合进行封装)
https://github.com/xuexiangjys/XHttp2/wiki
Apache License 2.0
405 stars 84 forks source link

你好,请问我上传图片如何使用生命周期绑定? #30

Closed querli closed 2 years ago

querli commented 2 years ago
   XHttp.get("/face/statistics")
            .syncRequest(false) //异步请求
            .onMainThread(true)
            //回到主线程
            .execute(object : CallBackProxy<CustomApiResult<FaceInfoBean>, FaceInfoBean>(object :TipRequestCallBack<FaceInfoBean>() {
                override fun onSuccess(response: FaceInfoBean?) {
                     Log.i("TAG", "请求成功:" + response)

                }

            }) {})

目前我使用这种方式上传图片是没有问题的,请问如何使用 .compose(RxLifecycle.with(this).bindToLifecycle())方式上传图片,请解答下,谢谢

querli commented 2 years ago

就是给上传图片的接口绑定生命周期

querli commented 2 years ago

还有我如何去自定义Result中的值? image

querli commented 2 years ago
 XHttp.post("/book/uploadBookPicture")
        .uploadFile(
            "file", File(path)
        ) { bytesWritten, contentLength, done -> }.execute(CallClazzProxy(CustomApiResult<SportDataBean>()))
        .compose(RxLifecycle.with(this).bindToLifecycle())
        .subscribeWith(object : ProgressLoadingSubscriber<Boolean?>(mLoadingLoader) {
            fun onSuccess(aBoolean: Boolean) {
                ToastUtils.toast("图片上传" + (if (aBoolean) "成功" else "失败") + "!")
            }

            override fun onSuccess(t: Boolean?) {
            }
        })

请问使用绑定生命周期后如何设置execute()执行的自定义ApiResult

querli commented 2 years ago

还有我看到你讲2.0.1版本已经解决了返回data为null的问题,现在我使用的是2.0.4,返回null,就报api on SubscriberError,我也设置了StrictMode为FALSE,请问这个是怎么解决?

xuexiangjys commented 2 years ago

你这种写法暂时不能支持,建议手动处理请求取消