Search in sources :

Example 1 with Request

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();
}
Also used : StringConvert(com.lzy.okgo.convert.StringConvert) Request(com.lzy.okgo.request.base.Request) PostRequest(com.lzy.okgo.request.PostRequest)

Example 2 with Request

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());
    }
}
Also used : Call(okhttp3.Call) Progress(com.lzy.okgo.model.Progress) Request(com.lzy.okgo.request.base.Request) ProgressRequestBody(com.lzy.okgo.request.base.ProgressRequestBody)

Aggregations

Request (com.lzy.okgo.request.base.Request)2 StringConvert (com.lzy.okgo.convert.StringConvert)1 Progress (com.lzy.okgo.model.Progress)1 PostRequest (com.lzy.okgo.request.PostRequest)1 ProgressRequestBody (com.lzy.okgo.request.base.ProgressRequestBody)1 Call (okhttp3.Call)1