Java Code Examples for com.lzy.okgo.callback.Callback

The following examples show how to use com.lzy.okgo.callback.Callback. These examples are extracted from open source projects. 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 Project: okhttp-OkGo   Source File: DefaultCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example 2
Source Project: okhttp-OkGo   Source File: FirstCacheRequestPolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            if (cacheEntity != null) {
                Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                mCallback.onCacheSuccess(success);
            }
            requestNetworkAsync();
        }
    });
}
 
Example 3
Source Project: okhttp-OkGo   Source File: NoneCacheRequestPolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            if (cacheEntity != null) {
                Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                mCallback.onCacheSuccess(success);
                mCallback.onFinish();
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example 4
Source Project: okhttp-OkGo   Source File: NoCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example 5
Source Project: okhttp-OkGo   Source File: RequestFailedCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
    mCallback = callback;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mCallback.onStart(request);

            try {
                prepareRawCall();
            } catch (Throwable throwable) {
                Response<T> error = Response.error(false, rawCall, null, throwable);
                mCallback.onError(error);
                return;
            }
            requestNetworkAsync();
        }
    });
}
 
Example 6
Source Project: BaseProject   Source File: DefaultCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                mCallback.onStart(request);

                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                requestNetworkAsync();
            }
        });
    }
 
Example 7
Source Project: BaseProject   Source File: FirstCacheRequestPolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                mCallback.onStart(request);

                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                if (cacheEntity != null) {
                    Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                    callbackOnCacheSuccess(success);
//                    mCallback.onCacheSuccess(success);
                }
                requestNetworkAsync();
            }
        });
    }
 
Example 8
Source Project: BaseProject   Source File: NoCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                if (mCallback != null) {
//                    mCallback.onStart(request);
//                }
                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                requestNetworkAsync();
            }
        });
    }
 
Example 9
Source Project: BaseProject   Source File: RequestFailedCachePolicy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                mCallback.onStart(request);

                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                requestNetworkAsync();
            }
        });
    }
 
Example 10
Source Project: okhttp-OkGo   Source File: Request.java    License: Apache License 2.0 5 votes vote down vote up
/** 非阻塞方法,异步请求,但是回调在子线程中执行 */
public void execute(Callback<T> callback) {
    HttpUtils.checkNotNull(callback, "callback == null");

    this.callback = callback;
    Call<T> call = adapt();
    call.execute(callback);
}
 
Example 11
Source Project: okhttp-OkGo   Source File: CacheCall.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Callback<T> callback) {
    HttpUtils.checkNotNull(callback, "callback == null");

    CacheEntity<T> cacheEntity = policy.prepareCache();
    policy.requestAsync(cacheEntity, callback);
}
 
Example 12
Source Project: BaseProject   Source File: Request.java    License: Apache License 2.0 5 votes vote down vote up
/** 非阻塞方法,异步请求,但是回调在子线程中执行 */
    public void execute(Callback<T> callback) {
//        HttpUtils.checkNotNull(callback, "callback == null");//removed by fee : 允许callback为null

        this.callback = callback;
        Call<T> call = adapt();
        call.execute(callback);
    }
 
Example 13
Source Project: BaseProject   Source File: CacheCall.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void execute(Callback<T> callback) {
//        HttpUtils.checkNotNull(callback, "callback == null");//removed by fee: 允许callback为null

        CacheEntity<T> cacheEntity = policy.prepareCache();
        policy.requestAsync(cacheEntity, callback);
    }
 
Example 14
Source Project: BaseProject   Source File: NoneCacheRequestPolicy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    public void requestAsync(final CacheEntity<T> cacheEntity, Callback<T> callback) {
        mCallback = callback;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                callbackOnStart(request);
//                mCallback.onStart(request);

                try {
                    prepareRawCall();
                } catch (Throwable throwable) {
                    Response<T> error = Response.error(false, rawCall, null, throwable);
                    callbackOnError(error);
//                    mCallback.onError(error);
                    return;
                }
                if (cacheEntity != null) {
                    Response<T> success = Response.success(true, cacheEntity.getData(), rawCall, null);
                    callbackOnCacheSuccess(success);
                    callbackOnFinish();
//                    mCallback.onCacheSuccess(success);
//                    mCallback.onFinish();
                    return;
                }
                requestNetworkAsync();
            }
        });
    }
 
Example 15
Source Project: okhttp-OkGo   Source File: ProgressRequestBody.java    License: Apache License 2.0 4 votes vote down vote up
ProgressRequestBody(RequestBody requestBody, Callback<T> callback) {
    this.requestBody = requestBody;
    this.callback = callback;
}
 
Example 16
Source Project: okhttp-OkGo   Source File: Request.java    License: Apache License 2.0 4 votes vote down vote up
public void setCallback(Callback<T> callback) {
    this.callback = callback;
}
 
Example 17
Source Project: okhttp-OkGo   Source File: FileConvert.java    License: Apache License 2.0 4 votes vote down vote up
public void setCallback(Callback<File> callback) {
    this.callback = callback;
}
 
Example 18
Source Project: okhttp-OkGo   Source File: Call.java    License: Apache License 2.0 4 votes vote down vote up
/** 异步回调执行 */
void execute(Callback<T> callback);
 
Example 19
Source Project: BaseProject   Source File: ProgressRequestBody.java    License: Apache License 2.0 4 votes vote down vote up
ProgressRequestBody(RequestBody requestBody, Callback<T> callback) {
    this.requestBody = requestBody;
    this.callback = callback;
}
 
Example 20
Source Project: BaseProject   Source File: Request.java    License: Apache License 2.0 4 votes vote down vote up
public void setCallback(Callback<T> callback) {
    this.callback = callback;
}
 
Example 21
Source Project: BaseProject   Source File: FileConvert.java    License: Apache License 2.0 4 votes vote down vote up
public void setCallback(Callback<File> callback) {
    this.callback = callback;
}
 
Example 22
Source Project: BaseProject   Source File: Call.java    License: Apache License 2.0 4 votes vote down vote up
/** 异步回调执行 */
void execute(Callback<T> callback);
 
Example 23
Source Project: okhttp-OkGo   Source File: CachePolicy.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 异步请求获取数据
 *
 * @param cacheEntity 本地的缓存
 * @param callback    异步回调
 */
void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback);
 
Example 24
Source Project: BaseProject   Source File: CachePolicy.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 异步请求获取数据
 *
 * @param cacheEntity 本地的缓存
 * @param callback    异步回调
 */
void requestAsync(CacheEntity<T> cacheEntity, Callback<T> callback);