Skip to content

Commit 87bd11b

Browse files
committed
移除 IRequestPath 接口
优化和补充框架的使用文档 优化 Json 格式化的方式 优化框架中部分类命名和变量命名 优化框架日志打印的 TAG 和 LOG 优化 BodyRequest 类中的代码逻辑 优化 IRequestHandler 方法参数结构 优化 IRequestInterceptor 方法参数结构 修正使用 JSONObject 带来的斜杠转义问题 修复异常对象被修改之后没有打印原有异常的问题 修复下载时使用分区存储时出现文件读取失败的问题 修复使用空元素的 List 集合导致没有数据返回后台的问题 修复使用缓存策略 USE_CACHE_FIRST 出现泛型为空的问题 修复使用 SSL 来创建证书时可能导致出现的框架未初始化异常
1 parent 4db8dec commit 87bd11b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1355
-1160
lines changed

EasyHttp.apk

-5.03 MB
Binary file not shown.

HelpDoc.md

Lines changed: 195 additions & 145 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
* 博客地址:[网络请求,如斯优雅](https://www.jianshu.com/p/93cd59dec002)
66

7-
* [点击此处下载Demo](EasyHttp.apk)
7+
* [点击此处下载Demo](https://github.com/getActivity/EasyHttp/releases/download/10.5/EasyHttp.apk)
88

9-
![](EasyHttp.jpg)
9+
![](picture/demo_code.png)
1010

1111
* 另外对 OkHttp 原理感兴趣的同学推荐你看以下源码分析文章
1212

@@ -22,6 +22,8 @@
2222

2323
* [OkHttp 精讲:CallServerInterceptor](https://www.jianshu.com/p/aa77af6251ff)
2424

25+
![](picture/demo_preview.jpg)
26+
2527
#### 集成步骤
2628

2729
* 在项目根目录下的 `build.gradle` 文件中加入
@@ -52,7 +54,7 @@ android {
5254
5355
dependencies {
5456
// 网络请求框架:https://github.com/getActivity/EasyHttp
55-
implementation 'com.github.getActivity:EasyHttp:10.2'
57+
implementation 'com.github.getActivity:EasyHttp:10.5'
5658
// OkHttp 框架:https://github.com/square/okhttp
5759
// noinspection GradleDependency
5860
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
@@ -65,9 +67,9 @@ dependencies {
6567

6668
| 功能或细节 | [EasyHttp](https://github.com/getActivity/EasyHttp) | [Retrofit](https://github.com/square/retrofit) | [OkGo](https://github.com/jeasonlzy/okhttp-OkGo) |
6769
| :----: | :------: | :-----: | :-----: |
68-
| 对应版本 | 10.2 | 2.9.0 | 3.0.4 |
70+
| 对应版本 | 10.5 | 2.9.0 | 3.0.4 |
6971
| issues 数 | [![](https://img.shields.io/github/issues/getActivity/EasyHttp.svg)](https://github.com/getActivity/EasyHttp/issues) | [![](https://img.shields.io/github/issues/square/retrofit.svg)](https://github.com/square/retrofit/issues) | [![](https://img.shields.io/github/issues/jeasonlzy/okhttp-OkGo.svg)](https://github.com/jeasonlzy/okhttp-OkGo/issues) |
70-
| **aar 包大小** | 76 KB | 123 KB | 131 KB |
72+
| **aar 包大小** | 78 KB | 123 KB | 131 KB |
7173
| minSdk 要求 | API 14+ | API 21+ | API 14+ |
7274
| 配置多域名 ||||
7375
| **动态 Host** ||||
@@ -77,13 +79,14 @@ dependencies {
7779
| **请求缓存** ||||
7880
| **下载校验** ||||
7981
| **极速下载** ||||
80-
| 批量上传文件 ||||
8182
| 上传进度监听 ||||
8283
| Json 参数提交 ||||
84+
| Json 日志打印格式化 ||||
8385
| **请求代码定位** ||||
8486
| **延迟发起请求** ||||
8587
| **分区存储适配** ||||
8688
| 上传文件类型 | File / FileContentResolver <br> InputStream / RequestBody | RequestBody | File |
89+
| 批量上传文件 ||||
8790
| **请求生命周期** | 自动管控 | 需要封装 | 需要封装 |
8891
| 参数传值方式 | 字段名 + 字段值 | 参数名 + 参数值 | 定义 Key + Value |
8992
| 框架灵活性 ||||
@@ -180,9 +183,9 @@ public final class HttpLifecycleManager implements LifecycleEventObserver {
180183

181184
#### 代码定位功能介绍
182185

183-
* 框架会在日志打印中输出在网络请求的代码位置,这样开发者可以直接通过点击 Log 来定位代码是在哪个类哪行代码,这样可以极大提升我们排查问题的效率,特别是在请求一多且业务复杂的情况下,我相信没有一个人会拒绝这样的功能。
186+
* 框架会在日志打印中输出在网络请求的代码位置,这样开发者可以直接通过点击 Log 来定位是在哪个类哪行代码,这样可以极大提升我们排查问题的效率,特别是在请求一多且业务复杂的情况下,我相信没有一个人会拒绝这样的功能。
184187

185-
![](RequestCode.png)
188+
![](picture/request_code.png)
186189

187190
#### 延迟发起请求功能介绍
188191

app/build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
24

35
android {
4-
compileSdkVersion 30
6+
compileSdkVersion 31
57

68
lintOptions {
79
abortOnError false
@@ -10,9 +12,9 @@ android {
1012
defaultConfig {
1113
applicationId 'com.hjq.easy.demo'
1214
minSdkVersion 16
13-
targetSdkVersion 30
14-
versionCode 1020
15-
versionName '10.2'
15+
targetSdkVersion 31
16+
versionCode 1050
17+
versionName '10.5'
1618
}
1719

1820
// 支持 JDK 1.8
@@ -69,24 +71,24 @@ dependencies {
6971
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
7072

7173
// 吐司框架:https://github.com/getActivity/ToastUtils
72-
implementation 'com.github.getActivity:ToastUtils:9.5'
74+
implementation 'com.github.getActivity:ToastUtils:9.6'
7375

7476
// 权限请求框架:https://github.com/getActivity/XXPermissions
75-
implementation 'com.github.getActivity:XXPermissions:12.3'
77+
implementation 'com.github.getActivity:XXPermissions:12.8'
7678

7779
// 标题栏框架:https://github.com/getActivity/TitleBar
7880
implementation 'com.github.getActivity:TitleBar:9.2'
7981

8082
// Json 解析框架:https://github.com/google/gson
81-
implementation 'com.google.code.gson:gson:2.8.8'
83+
implementation 'com.google.code.gson:gson:2.8.9'
8284
// Gson 解析容错:https://github.com/getActivity/GsonFactory
8385
implementation 'com.github.getActivity:GsonFactory:5.2'
8486

8587
// 日志调试框架:https://github.com/getActivity/Logcat
8688
debugImplementation 'com.github.getActivity:Logcat:9.9'
8789

8890
// 腾讯 MMKV:https://github.com/Tencent/MMKV
89-
implementation 'com.tencent:mmkv-static:1.2.10'
91+
implementation 'com.tencent:mmkv-static:1.2.11'
9092

9193
// 内存泄漏监测框架:https://github.com/square/leakcanary
9294
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

app/src/main/AndroidManifest.xml

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.hjq.easy.demo">
5-
6-
<!-- 联网权限 -->
7-
<uses-permission android:name="android.permission.INTERNET" />
8-
<!-- 访问网络状态 -->
9-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
11-
12-
<!-- 外部存储读写权限 -->
13-
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
14-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
15-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
16-
17-
<!-- 安装包的权限 -->
18-
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
19-
20-
<application
21-
android:name=".AppApplication"
22-
android:icon="@mipmap/ic_launcher"
23-
android:label="@string/app_name"
24-
android:networkSecurityConfig="@xml/network_security_config"
25-
android:roundIcon="@mipmap/ic_launcher_round"
26-
android:requestLegacyExternalStorage="true"
27-
android:theme="@style/AppTheme"
28-
tools:ignore="LockedOrientationActivity,UnusedAttribute"
29-
tools:targetApi="n">
30-
31-
<!-- 适配 Android 7.0 文件意图 -->
32-
<provider
33-
android:name="androidx.core.content.FileProvider"
34-
android:authorities="${applicationId}.provider"
35-
android:exported="false"
36-
android:grantUriPermissions="true">
37-
<meta-data
38-
android:name="android.support.FILE_PROVIDER_PATHS"
39-
android:resource="@xml/file_paths" />
40-
</provider>
41-
42-
<activity
43-
android:name=".MainActivity"
44-
android:configChanges="orientation|screenSize|keyboardHidden"
45-
android:launchMode="singleTop"
46-
android:screenOrientation="portrait">
47-
<intent-filter>
48-
<action android:name="android.intent.action.MAIN" />
49-
<action android:name="android.intent.action.VIEW" />
50-
51-
<category android:name="android.intent.category.LAUNCHER" />
52-
</intent-filter>
53-
</activity>
54-
55-
</application>
56-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.hjq.easy.demo">
5+
6+
<!-- 联网权限 -->
7+
<uses-permission android:name="android.permission.INTERNET" />
8+
<!-- 访问网络状态 -->
9+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
10+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
11+
12+
<!-- 外部存储读写权限 -->
13+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
14+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
15+
16+
<!-- 安装包的权限 -->
17+
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
18+
19+
<application
20+
android:name=".AppApplication"
21+
android:icon="@mipmap/ic_launcher"
22+
android:label="@string/app_name"
23+
android:networkSecurityConfig="@xml/network_security_config"
24+
android:requestLegacyExternalStorage="true"
25+
android:roundIcon="@mipmap/ic_launcher_round"
26+
android:theme="@style/AppTheme"
27+
tools:ignore="LockedOrientationActivity,UnusedAttribute"
28+
tools:targetApi="n">
29+
30+
<!-- 表示当前已经适配了分区存储 -->
31+
<meta-data
32+
android:name="ScopedStorage"
33+
android:value="true" />
34+
35+
<!-- 适配 Android 7.0 文件意图 -->
36+
<provider
37+
android:name="androidx.core.content.FileProvider"
38+
android:authorities="${applicationId}.provider"
39+
android:exported="false"
40+
android:grantUriPermissions="true">
41+
<meta-data
42+
android:name="android.support.FILE_PROVIDER_PATHS"
43+
android:resource="@xml/file_paths" />
44+
</provider>
45+
46+
<activity
47+
android:name=".MainActivity"
48+
android:configChanges="orientation|screenSize|keyboardHidden"
49+
android:exported="true"
50+
android:launchMode="singleTop"
51+
android:screenOrientation="portrait">
52+
<intent-filter>
53+
<action android:name="android.intent.action.MAIN" />
54+
<action android:name="android.intent.action.VIEW" />
55+
56+
<category android:name="android.intent.category.LAUNCHER" />
57+
</intent-filter>
58+
</activity>
59+
60+
</application>
61+
5762
</manifest>

app/src/main/java/com/hjq/easy/demo/AppApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import com.hjq.easy.demo.http.server.ReleaseServer;
77
import com.hjq.easy.demo.http.server.TestServer;
88
import com.hjq.http.EasyConfig;
9-
import com.hjq.http.config.IRequestApi;
109
import com.hjq.http.config.IRequestInterceptor;
1110
import com.hjq.http.config.IRequestServer;
1211
import com.hjq.http.model.HttpHeaders;
1312
import com.hjq.http.model.HttpParams;
13+
import com.hjq.http.request.HttpRequest;
1414
import com.hjq.toast.ToastUtils;
1515
import com.tencent.mmkv.MMKV;
1616

@@ -51,7 +51,7 @@ public void onCreate() {
5151
// 设置请求参数拦截器
5252
.setInterceptor(new IRequestInterceptor() {
5353
@Override
54-
public void interceptArguments(IRequestApi api, HttpParams params, HttpHeaders headers) {
54+
public void interceptArguments(HttpRequest<?> httpRequest, HttpParams params, HttpHeaders headers) {
5555
headers.put("timestamp", String.valueOf(System.currentTimeMillis()));
5656
}
5757
})

0 commit comments

Comments
 (0)