Skip to content

Commit

Permalink
feat(chuck): 改成chucker
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Jul 11, 2022
1 parent cfbf03e commit fa6a96e
Show file tree
Hide file tree
Showing 11 changed files with 1,348 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/hss01248/flipperdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public void onSuccess(Object result) {
public void downloadLargeFile(View view) {
String url = "https://media.w3.org/2010/05/sintel/trailer.mp4";
HttpUtil.download(url)
/*.setFileDownlodConfig(FileDownlodConfig.newBuilder()
.setFileDownlodConfig(FileDownlodConfig.newBuilder()
.fileDir(getExternalFilesDir("down").getAbsolutePath())
.build())*/
.build())
.callback(new MyNetCallback<ResponseBean<FileDownlodConfig>>() {
@Override
public void onSuccess(ResponseBean<FileDownlodConfig> response) {
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildscript {
//apply from:'remote_booster.gradle'
apply from: 'deps/depsLastestChecker.gradle'
apply from: 'deps/uploadAllTask.gradle'
apply from: 'z_config/git_branch_info.gradle'

ext {
// 快照版需要在版本号后面加-SNAPSHOT
Expand Down
9 changes: 4 additions & 5 deletions network-hooks-chucker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ dependencies {
api project(path: ':network-hook')
api project(path: ':network-body-meta-interceptor')
//implementation("com.github.chuckerteam.chucker:library:3.4.0")
api 'org.aspectj:aspectjrt:1.9.5'

api project(path: ':chuck')
/*implementation("com.github.skyNet2017.chucker:library:3.4.0.00"){
//api 'org.aspectj:aspectjrt:1.9.5'
//api project(path: ':chuck')
api("com.github.skyNet2017.chucker:library:6.0.5-from340"){
exclude group :'com.github.hss01248.flipperUtil', module:'network-body-meta-interceptor'
}*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.hss01248.network.chucker;


import android.content.Context;
import android.util.Log;

import androidx.startup.Initializer;

import com.hss01248.aop.network.hook.OkhttpAspect;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;

/**
* @Despciption todo
* @Author hss
* @Date 21/02/2022 11:46
* @Version 1.0
*/
public class OkhttpHookForChuck implements OkhttpAspect.OkhttpHook, Initializer<String> {
@Override
public void beforeBuild(OkHttpClient.Builder builder) {
List<Interceptor> interceptors1 = builder.interceptors();
boolean hasChucker = false;
for (Interceptor interceptor : interceptors1) {
/*if(interceptor instanceof ChuckInterceptor){
hasChucker = true;
break;
} else if(interceptor.getClass().getSimpleName().contains("Chuck")){
hasChucker = true;
break;
}*/
}

if(!hasChucker){
// builder.addInterceptor(new ChuckInterceptor(Utils.getApp()));
// builder.addInterceptor(new PrintCookieNetworkInterceptor());
}
}

@Override
public String create(Context context) {
Log.d("init","OkhttpHookForChucker.init start");
OkhttpAspect.addHook(new OkhttpHookForChuck());
return "OkhttpHookForChucker";
}

@Override
public List<Class<? extends Initializer<?>>> dependencies() {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import androidx.startup.Initializer;

import com.blankj.utilcode.util.Utils;
import com.chuckerteam.chucker.api.ChuckerInterceptor;
import com.hss01248.aop.network.hook.OkhttpAspect;
import com.readystatesoftware.chuck.ChuckInterceptor;
import com.readystatesoftware.chuck.PrintCookieNetworkInterceptor;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -29,7 +28,7 @@ public void beforeBuild(OkHttpClient.Builder builder) {
List<Interceptor> interceptors1 = builder.interceptors();
boolean hasChucker = false;
for (Interceptor interceptor : interceptors1) {
if(interceptor instanceof ChuckInterceptor){
if(interceptor instanceof ChuckerInterceptor){
hasChucker = true;
break;
} else if(interceptor.getClass().getSimpleName().contains("Chuck")){
Expand All @@ -39,8 +38,7 @@ public void beforeBuild(OkHttpClient.Builder builder) {
}

if(!hasChucker){
builder.addInterceptor(new ChuckInterceptor(Utils.getApp()));
builder.addInterceptor(new PrintCookieNetworkInterceptor());
builder.addInterceptor(new ChuckerInterceptor(Utils.getApp()));
}
}

Expand Down
Loading

0 comments on commit fa6a96e

Please sign in to comment.