use of com.lzy.okgo.request.base.Request in project okhttp-OkGo by jeasonlzy.
the class UploadAdapter method updateData.
public void updateData(int type) {
// 这里是将数据库的数据恢复
this.type = type;
if (type == TYPE_ALL)
values = OkUpload.restore(UploadManager.getInstance().getAll());
if (type == TYPE_FINISH)
values = OkUpload.restore(UploadManager.getInstance().getFinished());
if (type == TYPE_ING)
values = OkUpload.restore(UploadManager.getInstance().getUploading());
// 至于数据类型,统一就行,不一定非要是String
for (UploadTask<?> task : values) {
// noinspection unchecked
Request<String, ? extends Request> request = (Request<String, ? extends Request>) task.progress.request;
request.converter(new StringConvert());
}
notifyDataSetChanged();
}
use of com.lzy.okgo.request.base.Request in project okhttp-OkGo by jeasonlzy.
the class UploadTask method run.
@Override
public void run() {
progress.status = Progress.LOADING;
postLoading(progress);
final Response<T> response;
try {
// noinspection unchecked
Request<T, ? extends Request> request = (Request<T, ? extends Request>) progress.request;
final Call rawCall = request.getRawCall();
request.uploadInterceptor(new ProgressRequestBody.UploadInterceptor() {
@Override
public void uploadProgress(Progress innerProgress) {
if (rawCall.isCanceled())
return;
if (progress.status != Progress.LOADING) {
rawCall.cancel();
return;
}
progress.from(innerProgress);
postLoading(progress);
}
});
response = request.adapt().execute();
} catch (Exception e) {
postOnError(progress, e);
return;
}
if (response.isSuccessful()) {
postOnFinish(progress, response.body());
} else {
postOnError(progress, response.getException());
}
}
Aggregations