Skip to content

Commit 6b977ff

Browse files
committed
更新okhttp包
1 parent 8221822 commit 6b977ff

31 files changed

+860
-752
lines changed

app/app.iml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,32 +142,30 @@
142142
<orderEntry type="library" exported="" name="com.android.support:multidex-1.0.1" level="project" />
143143
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_search_v3_7_0.jar:unspecified@jar" level="project" />
144144
<orderEntry type="library" exported="" name="com.theartofdev.edmodo:android-image-cropper-2.3.1" level="project" />
145+
<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp:3.10.0@jar" level="project" />
146+
<orderEntry type="library" exported="" name="com.squareup.okio:okio:1.14.0@jar" level="project" />
145147
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/MobTools-2016.1201.1839.jar:unspecified@jar" level="project" />
146148
<orderEntry type="library" exported="" name="com.google.code.gson:gson:2.4@jar" level="project" />
147-
<orderEntry type="library" exported="" name="com.qiniu:qiniu-android-sdk:7.0.10@jar" level="project" />
148149
<orderEntry type="library" exported="" name="com.android.support:appcompat-v7-26.0.0-alpha1" level="project" />
149150
<orderEntry type="library" exported="" name="com.facebook.fresco:fresco-0.9.0" level="project" />
150151
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_radar_v3_7_0.jar:unspecified@jar" level="project" />
151152
<orderEntry type="library" exported="" name="com.android.support:support-media-compat-26.0.0-alpha1" level="project" />
153+
<orderEntry type="library" exported="" name="com.qiniu:qiniu-android-sdk:7.2.3@jar" level="project" />
152154
<orderEntry type="library" exported="" name="com.facebook.fresco:fbcore-0.9.0" level="project" />
153-
<orderEntry type="library" exported="" name="io.reactivex:rxandroid-1.2.1" level="project" />
154155
<orderEntry type="library" exported="" name="com.nineoldandroids:library:2.4.0@jar" level="project" />
155156
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_cloud_v3_7_0.jar:unspecified@jar" level="project" />
156-
<orderEntry type="library" exported="" name="io.reactivex:rxjava:1.2.0@jar" level="project" />
157157
<orderEntry type="library" exported="" name="com.android.support:support-compat-26.0.0-alpha1" level="project" />
158158
<orderEntry type="library" exported="" name="com.android.support:support-core-utils-26.0.0-alpha1" level="project" />
159159
<orderEntry type="library" exported="" name="de.greenrobot:greendao:1.3.7@jar" level="project" />
160160
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_base_v3_7_0.jar:unspecified@jar" level="project" />
161161
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/xUtils-2.6.7.jar:unspecified@jar" level="project" />
162162
<orderEntry type="library" exported="" name="top.zibin:Luban-1.0.9" level="project" />
163-
<orderEntry type="library" exported="" name="com.squareup.okhttp:okhttp-urlconnection:2.0.0@jar" level="project" />
164163
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/universal-image-loader-1.9.3.jar:unspecified@jar" level="project" />
165164
<orderEntry type="library" exported="" name="com.parse.bolts:bolts-android:1.1.4@jar" level="project" />
166165
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/MobCommons-2016.1201.1839.jar:unspecified@jar" level="project" />
167166
<orderEntry type="library" exported="" name="com.android.support:support-vector-drawable-26.0.0-alpha1" level="project" />
168167
<orderEntry type="library" exported="" name="com.android.support:animated-vector-drawable-26.0.0-alpha1" level="project" />
169168
<orderEntry type="library" exported="" name="com.android.support:support-annotations:26.0.0-alpha1@jar" level="project" />
170-
<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp:3.4.1@jar" level="project" />
171169
<orderEntry type="library" exported="" name="com.afollestad.material-dialogs:commons-0.9.1.0" level="project" />
172170
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/locSDK_6.13.jar:unspecified@jar" level="project" />
173171
<orderEntry type="library" exported="" name="com.android.support:transition-26.0.0-alpha1" level="project" />
@@ -179,38 +177,31 @@
179177
<orderEntry type="library" exported="" name="com.android.support:support-v13-25.0.0" level="project" />
180178
<orderEntry type="library" exported="" scope="TEST" name="com.android.support:multidex-instrumentation-1.0.1" level="project" />
181179
<orderEntry type="library" exported="" name="com.facebook.fresco:imagepipeline-0.9.0" level="project" />
182-
<orderEntry type="library" exported="" name="com.squareup.okhttp:okhttp:2.0.0@jar" level="project" />
183180
<orderEntry type="library" exported="" name="com.android.support:recyclerview-v7-26.0.0-alpha1" level="project" />
184181
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_map_v3_7_0.jar:unspecified@jar" level="project" />
185182
<orderEntry type="library" exported="" name="com.android.support:support-v4-26.0.0-alpha1" level="project" />
183+
<orderEntry type="library" exported="" name="com.qiniu:happy-dns:0.2.7@jar" level="project" />
186184
<orderEntry type="library" exported="" name="com.google.protobuf:protobuf-java:2.6.1@jar" level="project" />
187185
<orderEntry type="library" exported="" name="com.android.support:design-26.0.0-alpha1" level="project" />
188186
<orderEntry type="library" exported="" name="com.afollestad.material-dialogs:core-0.9.1.0" level="project" />
189-
<orderEntry type="library" exported="" name="cz.msebera.android:httpclient:4.3.6@jar" level="project" />
187+
<orderEntry type="library" exported="" name="com.lzy.net:okgo-3.0.4" level="project" />
190188
<orderEntry type="library" exported="" name="me.zhanghai.android.materialprogressbar:library-1.3.0" level="project" />
191-
<orderEntry type="library" exported="" name="com.lzy.net:okserver-1.1.3" level="project" />
192-
<orderEntry type="library" exported="" name="com.lzy.net:okrx-0.1.2" level="project" />
193189
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/netty-3.6.6.Final.jar:unspecified@jar" level="project" />
194190
<orderEntry type="library" exported="" name="com.facebook.fresco:drawee-0.9.0" level="project" />
195191
<orderEntry type="library" exported="" name="SMSSDK-2.1.3:@aar" level="project" />
196192
<orderEntry type="library" exported="" name="commons-io:commons-io:2.4@jar" level="project" />
197193
<orderEntry type="library" exported="" name="com.alibaba:fastjson:1.2.6@jar" level="project" />
198-
<orderEntry type="library" exported="" name="com.lzy.net:okgo-2.1.4" level="project" />
199194
<orderEntry type="library" exported="" name="com.bigkoo:svprogresshud-1.0.6" level="project" />
200195
<orderEntry type="library" exported="" name="com.android.support:support-core-ui-26.0.0-alpha1" level="project" />
201196
<orderEntry type="library" exported="" name="com.github.af913337456:WeChatVideoView-1.0" level="project" />
202197
<orderEntry type="library" exported="" name="de.greenrobot:eventbus:2.4.0@jar" level="project" />
203-
<orderEntry type="library" exported="" name="com.loopj.android:android-async-http:1.4.9@jar" level="project" />
204-
<orderEntry type="library" exported="" name="com.qiniu:happy-dns:0.2.5@jar" level="project" />
205198
<orderEntry type="library" exported="" name="com.android.support:support-fragment-26.0.0-alpha1" level="project" />
206199
<orderEntry type="library" exported="" name="__local_jars__:/Users/donal/develop/Tut-android/app/libs/baidumapapi_util_v3_7_0.jar:unspecified@jar" level="project" />
207200
<orderEntry type="library" exported="" name="cn.jiguang:jpush-2.1.8" level="project" />
208-
<orderEntry type="library" exported="" name="com.squareup.okio:okio:1.9.0@jar" level="project" />
209201
<orderEntry type="library" exported="" name="com.github.bumptech.glide:glide:3.7.0@jar" level="project" />
210202
<orderEntry type="module" module-name="emoj_library" exported="" />
211203
<orderEntry type="module" module-name="mgimlibs" exported="" />
212204
<orderEntry type="module" module-name="PhotoPicker" exported="" />
213205
<orderEntry type="library" exported="" name="android-android-26" level="project" />
214-
<orderEntry type="library" exported="" name="org.apache.http.legacy-android-26" level="project" />
215206
</component>
216207
</module>

app/build.gradle

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ repositories {
88
}
99

1010
android {
11-
useLibrary 'org.apache.http.legacy'
1211
compileSdkVersion rootProject.ext.compileSdkVersion
1312
buildToolsVersion rootProject.ext.buildToolsVersion
1413
signingConfigs {
@@ -74,8 +73,6 @@ dependencies {
7473
compile 'de.greenrobot:eventbus:2.4.0'
7574
compile 'de.greenrobot:greendao:1.3.7'
7675
compile 'com.google.code.gson:gson:2.4'
77-
compile 'com.squareup.okhttp:okhttp:2.0.0'
78-
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
7976
compile 'commons-io:commons-io:2.4'
8077
compile 'com.alibaba:fastjson:1.2.6'
8178
compile files('libs/baidumapapi_base_v3_7_0.jar')
@@ -84,11 +81,10 @@ dependencies {
8481
compile 'com.github.bumptech.glide:glide:3.7.0'
8582
compile 'in.srain.cube:ultra-ptr:1.0.11'
8683
compile 'com.bigkoo:svprogresshud:1.0.6'
87-
compile 'com.lzy.net:okgo:2.1.4'
88-
compile 'com.lzy.net:okrx:0.1.2'
89-
compile 'com.lzy.net:okserver:1.1.3'
84+
compile 'com.squareup.okhttp3:okhttp:3.10.0'
85+
compile 'com.lzy.net:okgo:3.0.4'
9086
compile 'top.zibin:Luban:1.0.9'
91-
compile 'com.qiniu:qiniu-android-sdk:7.0.+'
87+
compile 'com.qiniu:qiniu-android-sdk:7.2.+'
9288
compile 'cn.jiguang:jpush:2.1.8'
9389
compile 'com.github.razerdp:BasePopup:v1.4.0'
9490
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'

app/src/main/java/com/dtalk/dd/app/IMApplication.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,29 @@
55
import android.os.Environment;
66
import android.support.multidex.MultiDex;
77

8+
import com.dtalk.dd.BuildConfig;
89
import com.dtalk.dd.imservice.service.IMService;
910
import com.dtalk.dd.utils.ImageLoaderUtil;
1011
import com.dtalk.dd.utils.Logger;
1112
import com.dtalk.dd.utils.SandboxUtils;
12-
import com.dtalk.dd.utils.StringUtils;
1313
import com.facebook.cache.disk.DiskCacheConfig;
1414
import com.facebook.drawee.backends.pipeline.Fresco;
1515
import com.facebook.imagepipeline.core.ImagePipelineConfig;
1616
import com.lzy.okgo.OkGo;
1717
import com.lzy.okgo.cache.CacheEntity;
1818
import com.lzy.okgo.cache.CacheMode;
19-
import com.lzy.okgo.cookie.store.PersistentCookieStore;
19+
import com.lzy.okgo.cookie.CookieJarImpl;
20+
import com.lzy.okgo.cookie.store.MemoryCookieStore;
21+
import com.lzy.okgo.https.HttpsUtils;
22+
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
2023
import com.lzy.okgo.model.HttpHeaders;
2124

2225
import java.io.File;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.logging.Level;
2328

2429
import cn.jpush.android.api.JPushInterface;
30+
import okhttp3.OkHttpClient;
2531

2632

2733
public class IMApplication extends Application {
@@ -87,20 +93,31 @@ private ImagePipelineConfig createFrescoConfig() {
8793
private void initOK() {
8894
HttpHeaders headers = new HttpHeaders();
8995
headers.put("User-Agent", "Android-TT");
90-
OkGo.init(this);
9196
try {
97+
OkHttpClient.Builder builder = new OkHttpClient.Builder();
98+
builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
99+
builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
100+
builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
101+
builder.cookieJar(new CookieJarImpl(new MemoryCookieStore()));
102+
HttpsUtils.SSLParams sslParams1 = HttpsUtils.getSslSocketFactory();
103+
builder.sslSocketFactory(sslParams1.sSLSocketFactory, sslParams1.trustManager);
104+
if (BuildConfig.DEBUG) {
105+
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("tt");
106+
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
107+
loggingInterceptor.setColorLevel(Level.WARNING);
108+
builder.addInterceptor(loggingInterceptor);
109+
}
92110
OkGo.getInstance()
93-
.debug("OkGo")
94-
.setConnectTimeout(OkGo.DEFAULT_MILLISECONDS) //全局的连接超时时间
95-
.setReadTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局的读取超时时间
96-
.setWriteTimeOut(OkGo.DEFAULT_MILLISECONDS) //全局的写入超时时间
111+
.init(this)
112+
.setOkHttpClient(builder.build())
97113
.setCacheMode(CacheMode.NO_CACHE)
98114
.setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
99-
.setCookieStore(new PersistentCookieStore())
115+
.setRetryCount(0)
100116
.addCommonHeaders(headers);
101117
} catch (Exception e) {
102118
e.printStackTrace();
103119
}
120+
104121
}
105122

106123
private void startIMService() {

app/src/main/java/com/dtalk/dd/http/base/BaseClient.java

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import com.dtalk.dd.Security;
66
import com.dtalk.dd.config.UrlConstant;
7+
import com.lzy.okgo.OkGo;
8+
import com.lzy.okgo.callback.StringCallback;
9+
import com.lzy.okgo.model.HttpParams;
10+
import com.lzy.okgo.request.base.Request;
711

812
/**
913
* Created by Donal on 16/4/19.
@@ -13,46 +17,89 @@ public class BaseClient {
1317
public static String getAbsoluteUrl(String relativeUrl) {
1418
if (relativeUrl.contains("http")) {
1519
return relativeUrl;
16-
}
17-
else {
20+
} else {
1821
return UrlConstant.BASE_API + relativeUrl;
1922
}
2023
}
2124

22-
public interface ClientCallback
23-
{
24-
abstract void onPreConnection();
2525

26-
abstract void onCloseConnection();
26+
public static String encryptParam(String param) throws Exception {
27+
return new String(Security.getInstance().EncryptMsg(Base64.encodeToString(param.getBytes("utf-8"), Base64.DEFAULT)));
28+
}
29+
30+
public static String decryptResult(String result) throws Exception {
31+
return new String(Base64.decode(Security.getInstance().DecryptMsg(result), Base64.DEFAULT));
32+
}
33+
34+
public static void postRequest(String url, HttpParams params, final ClientCallback callback) {
35+
OkGo.<String>post(url)
36+
.params(params)
37+
.execute(new StringCallback() {
2738

28-
/**
29-
* 返回api有效数据
30-
*
31-
* @param data
32-
*/
33-
abstract void onSuccess(Object data);
39+
@Override
40+
public void onStart(Request<String, ? extends Request> request) {
41+
super.onStart(request);
42+
if (callback != null) {
43+
callback.onPreConnection();
44+
}
45+
}
3446

47+
@Override
48+
public void onFinish() {
49+
super.onFinish();
50+
if (callback != null) {
51+
callback.onCloseConnection();
52+
}
53+
}
3554

36-
/**
37-
* 连接api失败
38-
*
39-
* @param message
40-
*/
41-
abstract void onFailure(String message);
55+
@Override
56+
public void onSuccess(com.lzy.okgo.model.Response<String> response) {
57+
if (callback != null) {
58+
if (response.isSuccessful()) {
59+
callback.onSuccess(response.body());
60+
} else {
61+
callback.onFailure(response.message());
62+
}
63+
}
64+
}
4265

43-
/**
44-
* 返回解析json等异常
45-
*
46-
* @param e
47-
*/
48-
abstract void onException(Exception e);
66+
@Override
67+
public void onError(com.lzy.okgo.model.Response<String> response) {
68+
super.onError(response);
69+
if (callback != null) {
70+
callback.onFailure(response.getException().toString());
71+
}
72+
}
73+
});
4974
}
5075

51-
public static String encryptParam(String param) throws Exception{
52-
return new String(Security.getInstance().EncryptMsg(Base64.encodeToString(param.getBytes("utf-8"), Base64.DEFAULT)));
76+
public static void onStart(ClientCallback callback) {
77+
if (callback != null) {
78+
callback.onPreConnection();
79+
}
5380
}
5481

55-
public static String decryptResult(String result) throws Exception{
56-
return new String(Base64.decode(Security.getInstance().DecryptMsg(result), Base64.DEFAULT));
82+
public static void onFinish(ClientCallback callback) {
83+
if (callback != null) {
84+
callback.onCloseConnection();
85+
}
86+
}
87+
88+
public static void onRequestSuccess(ClientCallback callback, Object data) {
89+
if (callback != null) {
90+
callback.onSuccess(data);
91+
}
92+
}
93+
94+
public static void onRequestFailure(ClientCallback callback, String message) {
95+
if (callback != null) {
96+
callback.onFailure(message);
97+
}
98+
}
99+
100+
public static void onRequestException(ClientCallback callback, Exception e) {
101+
if (callback != null) {
102+
callback.onException(e);
103+
}
57104
}
58105
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.dtalk.dd.http.base;
2+
3+
/**
4+
* Created by donal on 2018/4/8.
5+
*/
6+
7+
public abstract class ClientCallback implements RequestListener {
8+
public void onPreConnection() {
9+
10+
}
11+
12+
public void onCloseConnection() {
13+
14+
}
15+
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.dtalk.dd.http.base;
2+
3+
/**
4+
* Created by donal on 2018/4/8.
5+
*/
6+
7+
public interface RequestListener {
8+
void onSuccess(Object data);
9+
10+
void onFailure(String message);
11+
12+
void onException(Exception e);
13+
}

0 commit comments

Comments
 (0)