Skip to content

Commit

Permalink
增加实时网速浮动窗口
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZhousf committed Oct 19, 2017
1 parent 72d77ff commit 9356455
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@
<dependency>
<groupId>com.zhousf.lib</groupId>
<artifactId>okhttp3</artifactId>
<version>2.9.1.4</version>
<version>2.9.1.5</version>
<type>pom</type>
</dependency>
```
### Gradle
```
compile 'com.zhousf.lib:okhttp3:2.9.1.4'
compile 'com.zhousf.lib:okhttp3:2.9.1.5'
```
若项目已包含support-annotations或出现support-annotations版本冲突请采用下面方式进行依赖:
```
compile ('com.zhousf.lib:okhttp3:2.9.1.4'){
compile ('com.zhousf.lib:okhttp3:2.9.1.5'){
exclude(module: 'support-annotations')
}
```
若项目已包含Gson或出现Gson版本冲突请采用下面方式进行依赖:
```
compile ('com.zhousf.lib:okhttp3:2.9.1.4'){
compile ('com.zhousf.lib:okhttp3:2.9.1.5'){
exclude(module:'gson')
}
```
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {

dependencies {
// compile project(':okhttp3')
compile ('com.zhousf.lib:okhttp3:2.9.1.4'){
compile ('com.zhousf.lib:okhttp3:2.9.1.5'){
exclude(module:'gson')
}
compile fileTree(include: ['*.jar'], dir: 'libs')
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/okhttp3/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class MainActivity extends BaseActivity {
/**
* 注意:测试时请更换该地址
*/
private String url = "http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
// private String url = "http://192.168.120.206:8080/office/api/time?key=zhousf_key";
// private String url = "http://api.k780.com:88/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
private String url = "http://192.168.120.206:8088/office/api/time?key=zhousf_key";

private boolean isNeedDeleteCache = true;

Expand Down
2 changes: 1 addition & 1 deletion okhttp3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
targetSdkVersion rootProject.sdkVersion
minSdkVersion rootProject.minSdkVersion
versionCode 1
versionName "2.9.1.4"
versionName "2.9.1.5"
}

buildTypes {
Expand Down
15 changes: 10 additions & 5 deletions okhttp3/src/main/java/com/okhttplib/helper/BaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
Response originalResponse;
Response originalResponse = null;
switch (cacheType){
case CacheType.FORCE_CACHE:
originalRequest = originalRequest.newBuilder().cacheControl(CacheControl.FORCE_CACHE).build();
Expand All @@ -164,11 +164,16 @@ public Response intercept(Chain chain) throws IOException {
.build();
originalResponse = chain.proceed(originalRequest);
}else {
originalRequest = originalRequest.newBuilder()
.cacheControl(CacheControl.FORCE_NETWORK)
// originalRequest = originalRequest.newBuilder()
// .cacheControl(CacheControl.FORCE_NETWORK)
// .build();
// //网络请求失败后自动读取缓存并响应
// originalResponse = aopChain(chain,originalRequest,CacheControl.FORCE_CACHE,true);
originalResponse = chain.proceed(originalRequest);
originalResponse.newBuilder()
.removeHeader("Pragma")
.header("Cache-Control", "public, only-if-cached, max-stale=" + 60*60*24*365)
.build();
//网络请求失败后自动读取缓存并响应
originalResponse = aopChain(chain,originalRequest,CacheControl.FORCE_CACHE,true);
}
break;
case CacheType.CACHE_THEN_NETWORK:
Expand Down

0 comments on commit 9356455

Please sign in to comment.