com.lzy.okgo.request.base.Request Java Examples

The following examples show how to use com.lzy.okgo.request.base.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Progress.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
public static Progress parseCursorToBean(Cursor cursor) {
    Progress progress = new Progress();
    progress.tag = cursor.getString(cursor.getColumnIndex(Progress.TAG));
    progress.url = cursor.getString(cursor.getColumnIndex(Progress.URL));
    progress.folder = cursor.getString(cursor.getColumnIndex(Progress.FOLDER));
    progress.filePath = cursor.getString(cursor.getColumnIndex(Progress.FILE_PATH));
    progress.fileName = cursor.getString(cursor.getColumnIndex(Progress.FILE_NAME));
    progress.fraction = cursor.getFloat(cursor.getColumnIndex(Progress.FRACTION));
    progress.totalSize = cursor.getLong(cursor.getColumnIndex(Progress.TOTAL_SIZE));
    progress.currentSize = cursor.getLong(cursor.getColumnIndex(Progress.CURRENT_SIZE));
    progress.status = cursor.getInt(cursor.getColumnIndex(Progress.STATUS));
    progress.priority = cursor.getInt(cursor.getColumnIndex(Progress.PRIORITY));
    progress.date = cursor.getLong(cursor.getColumnIndex(Progress.DATE));
    progress.request = (Request<?, ? extends Request>) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.REQUEST)));
    progress.extra1 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA1)));
    progress.extra2 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA2)));
    progress.extra3 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA3)));
    return progress;
}
 
Example #2
Source File: BaseOkgoApi.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
/**
 * 注:如果APP项目有对参数进行整体加密的需求,则本类不统一处理
 * 而采取把本类直接复制到APP项目下,并且其他的xxApi继承之,来作统一处理
 * @param request
 * @param appendKeys keys
 * @param values values 要一一对应到key的值
 * @return request请求自身
 */
public static Request buildCommonRequestParams(Request request, String[] appendKeys, String... values) {
    if (appendKeys != null && values != null) {//如果有外部传入的参数
        int keysLen = appendKeys.length;
        int valuesLen = values.length;
        int minLen = keysLen;
        if (valuesLen < keysLen) {
            minLen = valuesLen;
        }
        if (minLen > 0) {
            for (int keyIndex = 0; keyIndex < minLen; keyIndex++) {
                String curKey = appendKeys[keyIndex];
                String curValue = values[keyIndex];
                request.params(curKey, curValue);
            }
        }
    }
    return request;
}
 
Example #3
Source File: UploadAdapter.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
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());

    //由于Converter是无法保存下来的,所以这里恢复任务的时候,需要额外传入Converter,否则就没法解析数据
    //至于数据类型,统一就行,不一定非要是String
    for (UploadTask<?> task : values) {
        //noinspection unchecked
        Request<String, ? extends Request> request = (Request<String, ? extends Request>) task.progress.request;
        request.converter(new StringConvert());
    }

    notifyDataSetChanged();
}
 
Example #4
Source File: Progress.java    From okhttp-OkGo with Apache License 2.0 6 votes vote down vote up
public static Progress parseCursorToBean(Cursor cursor) {
    Progress progress = new Progress();
    progress.tag = cursor.getString(cursor.getColumnIndex(Progress.TAG));
    progress.url = cursor.getString(cursor.getColumnIndex(Progress.URL));
    progress.folder = cursor.getString(cursor.getColumnIndex(Progress.FOLDER));
    progress.filePath = cursor.getString(cursor.getColumnIndex(Progress.FILE_PATH));
    progress.fileName = cursor.getString(cursor.getColumnIndex(Progress.FILE_NAME));
    progress.fraction = cursor.getFloat(cursor.getColumnIndex(Progress.FRACTION));
    progress.totalSize = cursor.getLong(cursor.getColumnIndex(Progress.TOTAL_SIZE));
    progress.currentSize = cursor.getLong(cursor.getColumnIndex(Progress.CURRENT_SIZE));
    progress.status = cursor.getInt(cursor.getColumnIndex(Progress.STATUS));
    progress.priority = cursor.getInt(cursor.getColumnIndex(Progress.PRIORITY));
    progress.date = cursor.getLong(cursor.getColumnIndex(Progress.DATE));
    progress.request = (Request<?, ? extends Request>) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.REQUEST)));
    progress.extra1 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA1)));
    progress.extra2 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA2)));
    progress.extra3 = (Serializable) IOUtils.toObject(cursor.getBlob(cursor.getColumnIndex(Progress.EXTRA3)));
    return progress;
}
 
Example #5
Source File: BaseOkgoApi.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static void excute(Request request, AbsCallback callback) {
    Object cancelFlagInCallback = null;
    if (callback != null) {
        cancelFlagInCallback = callback.getObj4CancelTag();
    }
    request.tag(cancelFlagInCallback == null ? request.getUrl() : cancelFlagInCallback).execute(callback);
}
 
Example #6
Source File: OkGoCallback.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
     * 请求网络开始前, UI 线程
     */
    @Override
    public void onStart(Request<String, ? extends Request> request) {
        super.onStart(request);

        url = request.getUrl();

//        StringBuilder builder = new StringBuilder();
//        builder.append("请求网络开始前");
//        builder.append("请求链接" + request.getUrl());
//        builder.append("请求参数" + request.getParams().toString());

        DevLogger.dTag(TAG, "请求网络开始前: " + url);
    }
 
Example #7
Source File: DownloadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public DownloadTask(String tag, Request<File, ? extends Request> request) {
    HttpUtils.checkNotNull(tag, "tag == null");
    progress = new Progress();
    progress.tag = tag;
    progress.folder = OkDownload.getInstance().getFolder();
    progress.url = request.getBaseUrl();
    progress.status = Progress.NONE;
    progress.totalSize = -1;
    progress.request = request;

    executor = OkDownload.getInstance().getThreadPool().getExecutor();
    listeners = new HashMap<>();
}
 
Example #8
Source File: UploadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #9
Source File: UploadTask.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
public UploadTask(String tag, Request<T, ? extends Request> request) {
    HttpUtils.checkNotNull(tag, "tag == null");
    progress = new Progress();
    progress.tag = tag;
    progress.url = request.getBaseUrl();
    progress.status = Progress.NONE;
    progress.totalSize = -1;
    progress.request = request;

    executor = OkUpload.getInstance().getThreadPool().getExecutor();
    listeners = new HashMap<>();
}
 
Example #10
Source File: JsonCallback.java    From okhttp-OkGo with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart(Request<T, ? extends Request> request) {
    super.onStart(request);
    // 主要用于在所有请求之前添加公共的请求头或请求参数
    // 例如登录授权的 token
    // 使用的设备信息
    // 可以随意添加,也可以什么都不传
    // 还可以在这里对所有的参数进行加密,均在这里实现
    request.headers("header1", "HeaderValue1")//
            .params("params1", "ParamsValue1")//
            .params("token", "3215sdf13ad1f65asd4f3ads1f");
}
 
Example #11
Source File: BaseOkgoApi.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
protected static Request createRequest(String wholeUrl, byte requestMethod) {
    switch (requestMethod) {
        case GET:
            return OkGo.get(wholeUrl);
        case POST:
            return OkGo.post(wholeUrl);
        case PUT:
            return OkGo.put(wholeUrl);
    }
    return null;
}
 
Example #12
Source File: BaseCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public BaseCachePolicy(Request<T, ? extends Request> request) {
    this.request = request;
}
 
Example #13
Source File: BaseCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
protected void callbackOnStart(Request<T, ? extends Request> request){
    if (mCallback != null) {
        mCallback.onStart(request);
    }
}
 
Example #14
Source File: NoCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public NoCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #15
Source File: CommonCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public CommonCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #16
Source File: RequestFailedCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public RequestFailedCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #17
Source File: NoneCacheRequestPolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public NoneCacheRequestPolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #18
Source File: FirstCacheRequestPolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public FirstCacheRequestPolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #19
Source File: DefaultCachePolicy.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public DefaultCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #20
Source File: AbsCallback.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart(Request<T, ? extends Request> request) {
}
 
Example #21
Source File: Callback.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
/** 请求网络开始前,UI线程 */
void onStart(Request<T, ? extends Request> request);
 
Example #22
Source File: CacheCall.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public Request getRequest() {
    return request;
}
 
Example #23
Source File: CacheCall.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public CacheCall(Request<T, ? extends Request> request) {
    this.request = request;
    this.policy = preparePolicy();
}
 
Example #24
Source File: NoneCacheRequestPolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public NoneCacheRequestPolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #25
Source File: RequestFailedCachePolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public RequestFailedCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #26
Source File: NoCachePolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public NoCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #27
Source File: BaseCachePolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public BaseCachePolicy(Request<T, ? extends Request> request) {
    this.request = request;
}
 
Example #28
Source File: FirstCacheRequestPolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public FirstCacheRequestPolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #29
Source File: DefaultCachePolicy.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
public DefaultCachePolicy(Request<T, ? extends Request> request) {
    super(request);
}
 
Example #30
Source File: AbsCallback.java    From okhttp-OkGo with Apache License 2.0 4 votes vote down vote up
@Override
public void onStart(Request<T, ? extends Request> request) {
}