Skip to content

Commit

Permalink
增加demo中IUpdateHttpService实现的asyncPost方法的说明
Browse files Browse the repository at this point in the history
  • Loading branch information
xuexiangjys committed Jun 11, 2019
1 parent 9220513 commit f1a76e7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dependencies {
implementation 'com.github.xuexiangjys.XAOP:xaop-runtime:1.0.3' //添加依赖

//XPage
implementation 'com.github.xuexiangjys.XPage:xpage-lib:2.2.5'
implementation 'com.github.xuexiangjys.XPage:xpage-lib:2.2.6'
annotationProcessor 'com.github.xuexiangjys.XPage:xpage-compiler:2.2.5'
//butterknife的sdk
implementation 'com.jakewharton:butterknife:8.8.1'
Expand All @@ -76,10 +76,10 @@ dependencies {
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

//网络请求的实现一
implementation 'com.qianwen:okhttp-utils:3.8.0'
implementation 'com.zhy:okhttputils:2.6.2'

//网络请求的实现二
implementation 'com.github.xuexiangjys:XHttp2:1.0.1'
implementation 'com.github.xuexiangjys:XHttp2:1.0.2'
implementation deps.gson
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/xuexiang/xupdatedemo/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
import com.xuexiang.xutil.XUtil;
import com.xuexiang.xutil.common.StringUtils;
import com.xuexiang.xutil.tip.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_NO_NEW_VERSION;

Expand Down Expand Up @@ -73,10 +77,11 @@ public void onDenied(List<String> permissionsDenied) {

initXHttp();

initOKHttpUtils();

initUpdate();
}


private void initUpdate() {
XUpdate.get()
.debug(true)
Expand Down Expand Up @@ -104,4 +109,12 @@ private void initXHttp() {
XHttpSDK.debug("XHttp"); //需要调试的时候执行
XHttp.getInstance().setTimeout(20000);
}

private void initOKHttpUtils() {
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(20000L, TimeUnit.MILLISECONDS)
.readTimeout(20000L, TimeUnit.MILLISECONDS)
.build();
OkHttpUtils.initClient(okHttpClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class OKHttpUpdateHttpService implements IUpdateHttpService {

public OKHttpUpdateHttpService() {
OkHttpUtils.getInstance().timeout(20000);

}

@Override
Expand All @@ -52,7 +52,7 @@ public void asyncGet(@NonNull String url, @NonNull Map<String, Object> params, f
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Response response, Exception e, int id) {
public void onError(Call call, Exception e, int id) {
callBack.onError(e);
}

Expand All @@ -65,13 +65,14 @@ public void onResponse(String response, int id) {

@Override
public void asyncPost(@NonNull String url, @NonNull Map<String, Object> params, final @NonNull Callback callBack) {
//这里默认post的是Form格式,使用json格式的请修改 post -> postString
OkHttpUtils.post()
.url(url)
.params(transform(params))
.build()
.execute(new StringCallback() {
@Override
public void onError(Call call, Response response, Exception e, int id) {
public void onError(Call call, Exception e, int id) {
callBack.onError(e);
}

Expand All @@ -94,7 +95,7 @@ public void inProgress(float progress, long total, int id) {
}

@Override
public void onError(Call call, Response response, Exception e, int id) {
public void onError(Call call, Exception e, int id) {
callback.onError(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onError(ApiException e) {

@Override
public void asyncPost(@NonNull String url, @NonNull Map<String, Object> params, @NonNull final Callback callBack) {
//这里默认post的是Form格式,使用json格式的请修改为 params -> upJson
XHttp.post(url)
.baseUrl(mBaseUrl)
.params(params)
Expand Down

0 comments on commit f1a76e7

Please sign in to comment.