Skip to content

Commit 3904080

Browse files
AriesHoo@126.comAriesHoo@126.com
authored andcommitted
1、升级部分三方库
2、修改已知bug
1 parent 9468ca4 commit 3904080

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

library/src/main/java/com/aries/library/fast/retrofit/FastRetrofit.java

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.aries.library.fast.retrofit;
22

33
import android.text.TextUtils;
4-
import android.util.Log;
4+
5+
import androidx.annotation.Nullable;
56

67
import com.aries.library.fast.manager.LoggerManager;
78
import com.aries.library.fast.util.SSLUtil;
@@ -15,9 +16,7 @@
1516
import javax.net.ssl.SSLSocketFactory;
1617
import javax.net.ssl.X509TrustManager;
1718

18-
import androidx.annotation.Nullable;
1919
import io.reactivex.Observable;
20-
import io.reactivex.functions.Consumer;
2120
import io.reactivex.schedulers.Schedulers;
2221
import okhttp3.Interceptor;
2322
import okhttp3.OkHttpClient;
@@ -78,6 +77,10 @@ public class FastRetrofit {
7877
* 证书配置
7978
*/
8079
private SSLUtil.SSLParams mSslParams = new SSLUtil.SSLParams();
80+
/**
81+
* 日志tag
82+
*/
83+
private String mLogTag = "FastRetrofit";
8184
/**
8285
* 日志拦截器
8386
*/
@@ -211,13 +214,10 @@ public Observable<ResponseBody> downloadFile(String fileUrl, Map<String, Object>
211214
FastRetrofit.getInstance().setLogEnable(false);
212215
return FastRetrofit.getRetrofit()
213216
.create(FastRetrofitService.class)
214-
.downloadFile(fileUrl, header == null ? new HashMap<String, Object>(0) : header)
215-
.doOnNext(new Consumer<ResponseBody>() {
216-
@Override
217-
public void accept(ResponseBody responseBody) {
218-
//onNext回调前还原log状态
219-
FastRetrofit.getInstance().setLogEnable(logEnable);
220-
}
217+
.downloadFile(fileUrl, header == null ? new HashMap<>(0) : header)
218+
.doOnNext(responseBody -> {
219+
//onNext回调前还原log状态
220+
FastRetrofit.getInstance().setLogEnable(logEnable);
221221
})
222222
.subscribeOn(Schedulers.io());
223223
}
@@ -244,7 +244,7 @@ public Observable<ResponseBody> uploadFile(String uploadUrl, @Nullable RequestBo
244244
public Observable<ResponseBody> uploadFile(String uploadUrl, @Nullable final RequestBody body, Map<String, Object> header) {
245245
return getRetrofit()
246246
.create(FastRetrofitService.class)
247-
.uploadFile(uploadUrl, body, header == null ? new HashMap<>() : header)
247+
.uploadFile(uploadUrl, body, header == null ? new HashMap<>(0) : header)
248248
.compose(FastTransformer.<ResponseBody>switchSchedulers());
249249
}
250250

@@ -406,11 +406,22 @@ public boolean isLogEnable() {
406406
/**
407407
* 设置日志打印
408408
*
409-
* @param enable
409+
* @param enable 是否打印日志
410410
* @return
411411
*/
412412
public FastRetrofit setLogEnable(boolean enable) {
413-
return setLogEnable(enable, this.getClass().getSimpleName(), HttpLoggingInterceptor.Level.BODY);
413+
return setLogEnable(enable, mLogTag);
414+
}
415+
416+
/**
417+
* 设置日志打印
418+
*
419+
* @param enable 是否打印日志
420+
* @param tag 日志标签
421+
* @return
422+
*/
423+
public FastRetrofit setLogEnable(boolean enable, String tag) {
424+
return setLogEnable(enable, tag, HttpLoggingInterceptor.Level.BODY);
414425
}
415426

416427
/**
@@ -421,27 +432,25 @@ public FastRetrofit setLogEnable(boolean enable) {
421432
* @return
422433
*/
423434
public FastRetrofit setLogEnable(boolean enable, String tag, HttpLoggingInterceptor.Level level) {
435+
tag = TextUtils.isEmpty(tag) ? mLogTag : tag;
424436
if (TextUtils.isEmpty(tag)) {
425-
tag = getClass().getSimpleName();
437+
tag = "FastRetrofit";
426438
}
439+
mLogTag = tag;
427440
if (enable) {
428441
if (mLoggingInterceptor == null) {
429-
final String finalTag = tag;
430-
mLoggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
431-
@Override
432-
public void log(String message) {
433-
if (TextUtils.isEmpty(message)) {
434-
return;
435-
}
436-
//json格式使用Logger.json打印
437-
boolean isJson = message.startsWith("[") || message.startsWith("{");
438-
isJson = isJson && mLogJsonEnable;
439-
if (isJson) {
440-
LoggerManager.json(finalTag, message);
441-
return;
442-
}
443-
Log.d(finalTag, message);
442+
mLoggingInterceptor = new HttpLoggingInterceptor(message -> {
443+
if (TextUtils.isEmpty(message)) {
444+
return;
445+
}
446+
//json格式使用Logger.json打印
447+
boolean isJson = message.startsWith("[") || message.startsWith("{");
448+
isJson = isJson && mLogJsonEnable;
449+
if (isJson) {
450+
LoggerManager.json(mLogTag, message);
451+
return;
444452
}
453+
LoggerManager.d(mLogTag, message);
445454
});
446455
}
447456
mLoggingInterceptor.setLevel(level);

0 commit comments

Comments
 (0)