Skip to content

Commit df189b5

Browse files
committed
优化日志打印逻辑
优化 md5 校验逻辑 新增支持自定义日志 TAG 新增支持打印请求耗时 删除一些已经标记过时方法 纠正某个英文单词书写错误 修复参数解析逻辑上的 Bug
1 parent 12fd135 commit df189b5

23 files changed

+455
-432
lines changed

EasyHttp.apk

210 KB
Binary file not shown.

README.md

Lines changed: 265 additions & 257 deletions
Large diffs are not rendered by default.

app/build.gradle

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
apply plugin: 'com.android.application'
2-
3-
android {
4-
compileSdkVersion 28
5-
6-
// 支持 JDK 1.8
7-
compileOptions {
8-
targetCompatibility JavaVersion.VERSION_1_8
9-
sourceCompatibility JavaVersion.VERSION_1_8
10-
}
11-
12-
defaultConfig {
13-
applicationId "com.hjq.http.demo"
14-
minSdkVersion 14
15-
targetSdkVersion 28
16-
versionCode 50
17-
versionName "5.0"
18-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
19-
}
20-
buildTypes {
21-
release {
22-
minifyEnabled false
23-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24-
}
25-
debug {
26-
minifyEnabled false
27-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28-
}
29-
}
30-
}
31-
32-
dependencies {
33-
implementation fileTree(include: ['*.jar'], dir: 'libs')
34-
implementation project(':library')
35-
36-
implementation 'com.android.support:appcompat-v7:28.0.0'
37-
implementation 'com.android.support:design:28.0.0'
38-
39-
// 标题栏:https://github.com/getActivity/TitleBar
40-
implementation 'com.hjq:titlebar:6.0'
41-
// 吐司工具类:https://github.com/getActivity/ToastUtils
42-
implementation 'com.hjq:toast:8.0'
43-
// 权限请求框架:https://github.com/getActivity/XXPermissions
44-
implementation 'com.hjq:xxpermissions:6.0'
45-
46-
// Json 解析框架:https://github.com/google/gson
47-
implementation 'com.google.code.gson:gson:2.8.5'
48-
// OkHttp 网络框架:https://github.com/square/okhttp
49-
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 28
5+
6+
// 支持 JDK 1.8
7+
compileOptions {
8+
targetCompatibility JavaVersion.VERSION_1_8
9+
sourceCompatibility JavaVersion.VERSION_1_8
10+
}
11+
12+
defaultConfig {
13+
applicationId "com.hjq.http.demo"
14+
minSdkVersion 14
15+
targetSdkVersion 28
16+
versionCode 60
17+
versionName "6.0"
18+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
19+
}
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24+
}
25+
debug {
26+
minifyEnabled false
27+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28+
}
29+
}
30+
}
31+
32+
dependencies {
33+
implementation fileTree(include: ['*.jar'], dir: 'libs')
34+
implementation project(':library')
35+
36+
implementation 'com.android.support:appcompat-v7:28.0.0'
37+
implementation 'com.android.support:design:28.0.0'
38+
39+
// 标题栏:https://github.com/getActivity/TitleBar
40+
implementation 'com.hjq:titlebar:6.0'
41+
// 吐司工具类:https://github.com/getActivity/ToastUtils
42+
implementation 'com.hjq:toast:8.0'
43+
// 权限请求框架:https://github.com/getActivity/XXPermissions
44+
implementation 'com.hjq:xxpermissions:6.2'
45+
// Json 解析框架:https://github.com/google/gson
46+
implementation 'com.google.code.gson:gson:2.8.5'
47+
// OkHttp 框架:https://github.com/square/okhttp
48+
// 升级注意事项:https://www.jianshu.com/p/d12d0f536f55
49+
implementation 'com.squareup.okhttp3:okhttp:3.12.10'
50+
// 日志调试:https://github.com/getActivity/Logcat
51+
debugImplementation 'com.hjq:logcat:6.0'
5052
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
android:resource="@xml/file_paths" />
3737
</provider>
3838

39-
<activity android:name=".MainActivity">
39+
<activity
40+
android:name=".MainActivity"
41+
android:configChanges="orientation|screenSize|keyboardHidden"
42+
android:launchMode="singleTop"
43+
android:screenOrientation="portrait">
4044
<intent-filter>
4145
<action android:name="android.intent.action.MAIN" />
4246
<action android:name="android.intent.action.VIEW" />

app/src/main/java/com/hjq/http/demo/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void onClick(View v) {
103103
case R.id.btn_main_get:
104104
EasyHttp.get(this)
105105
.api(new SearchAuthorApi()
106-
.setAuthor("鸿洋"))
106+
.setAuthor("鸿洋"))
107107
.request(new HttpCallback<HttpData<SearchBean>>(this) {
108108

109109
@Override
@@ -115,12 +115,12 @@ public void onSucceed(HttpData<SearchBean> result) {
115115
case R.id.btn_main_post:
116116
EasyHttp.post(this)
117117
.api(new SearchBlogsApi()
118-
.setKeyword("搬砖不再有"))
118+
.setKeyword("搬砖不再有"))
119119
.request(new HttpCallback<HttpData<SearchBean>>(this) {
120120

121121
@Override
122122
public void onSucceed(HttpData<SearchBean> result) {
123-
ToastUtils.show("请求成功" + result.getData().getSize());
123+
ToastUtils.show("请求成功");
124124
}
125125
});
126126
break;

app/src/main/java/com/hjq/http/demo/http/model/RequestHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ public Exception requestFail(Context context, Exception e) {
147147
e = new HttpException(e.getMessage(), e);
148148
}
149149
}
150-
151-
// 打印错误信息
152-
EasyLog.print(e);
153150
return e;
154151
}
155152
}

app/src/main/java/com/hjq/http/demo/http/request/SearchBlogsApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public SearchBlogsApi setKeyword(String keyword) {
2424
this.keyword = keyword;
2525
return this;
2626
}
27-
}
27+
}

library/build.gradle

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// 文件开头配置
21
apply plugin: 'com.android.library'
32
apply plugin: 'com.novoda.bintray-release'
43

@@ -14,26 +13,26 @@ android {
1413
defaultConfig {
1514
minSdkVersion 14
1615
targetSdkVersion 26
17-
versionCode 50
18-
versionName "5.0"
16+
versionCode 60
17+
versionName "6.0"
1918
}
2019
}
2120

2221
dependencies {
23-
compileOnly 'com.squareup.okhttp3:okhttp:3.12.1'
24-
compileOnly 'com.android.support:support-fragment:26.0.0'
22+
implementation 'com.squareup.okhttp3:okhttp:3.12.10'
23+
implementation 'com.android.support:support-fragment:26.0.0'
2524
}
2625

2726
publish {
28-
userOrg = 'getactivity'//填写bintray用户名,注意大小写
29-
groupId = 'com.hjq'//定义的maven group id最终引用形式
30-
artifactId = 'http'//maven的artifact id
31-
version = '5.0'//maven 上发布版本号
32-
description = 'Easy-to-use network request framework'//描述,自己定义
33-
website = "https://github.com/getActivity/EasyHttp"//项目在github中的地址
27+
userOrg = 'getactivity'
28+
groupId = 'com.hjq'
29+
artifactId = 'http'
30+
version = '6.0'
31+
description = 'Easy-to-use network request framework'
32+
website = "https://github.com/getActivity/EasyHttp"
3433
}
3534

36-
tasks.withType(Javadoc) {//防止编码问题
35+
tasks.withType(Javadoc) {
3736
options.addStringOption('Xdoclint:none', '-quiet')
3837
options.addStringOption('encoding', 'UTF-8')
3938
options.addStringOption('charSet', 'UTF-8')

library/src/main/java/com/hjq/http/EasyConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public static EasyConfig with(OkHttpClient client) {
5151

5252
/** 日志开关 */
5353
private boolean mLogEnabled = true;
54+
/** 日志 TAG */
55+
private String mLogTag = "EasyHttp";
5456
/** 重试次数 */
5557
private int mRetryCount;
5658

@@ -104,6 +106,11 @@ public EasyConfig setLogEnabled(boolean enabled) {
104106
return this;
105107
}
106108

109+
public EasyConfig setLogTag(String tag) {
110+
mLogTag = tag;
111+
return this;
112+
}
113+
107114
public EasyConfig setRetryCount(int count) {
108115
if (count < 0) {
109116
throw new IllegalArgumentException("The number of retries must be greater than 0");
@@ -136,6 +143,10 @@ public boolean isLogEnabled() {
136143
return mLogEnabled;
137144
}
138145

146+
public String getLogTag() {
147+
return mLogTag;
148+
}
149+
139150
public int getRetryCount() {
140151
return mRetryCount;
141152
}

library/src/main/java/com/hjq/http/EasyLog.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.hjq.http;
22

3+
import android.text.TextUtils;
34
import android.util.Log;
45

56
/**
@@ -10,8 +11,6 @@
1011
*/
1112
public final class EasyLog {
1213

13-
private static final String TAG = "EasyHttp";
14-
1514
/**
1615
* 日志开关
1716
*/
@@ -24,7 +23,7 @@ public static boolean isEnable() {
2423
*/
2524
public static void print(String log) {
2625
if (isEnable()) {
27-
Log.d(TAG, log != null ? log : "null");
26+
Log.d(EasyConfig.getInstance().getLogTag(), log != null ? log : "null");
2827
}
2928
}
3029

@@ -33,7 +32,7 @@ public static void print(String log) {
3332
*/
3433
public static void print(Throwable throwable) {
3534
if (EasyConfig.getInstance().isLogEnabled()) {
36-
throwable.printStackTrace();
35+
Log.e(EasyConfig.getInstance().getLogTag(), throwable.getMessage(), throwable);
3736
}
3837
}
3938

@@ -57,7 +56,7 @@ public static void print() {
5756
public static void json(String json) {
5857
if (isEnable()) {
5958
String text = stringToJSON(json);
60-
if (text != null && !"".equals(text)) {
59+
if (!TextUtils.isEmpty(text)) {
6160
// 打印 Json 数据最好换一行再打印会好看一点
6261
text = " \n" + text;
6362

0 commit comments

Comments
 (0)