diff --git a/app/build.gradle b/app/build.gradle index b38db56..53ae226 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,14 +76,14 @@ dependencies { api 'io.github.didi.dokit:dokitx-plugin:3.5.0.1' - implementation 'com.github.hss01248.HttpUtil2:http:3.0.5' + implementation 'com.github.hss01248.HttpUtil2:http:3.1.2' } //com.github.hss01248.flipperUtil configurations { - all*.exclude group: 'com.github.hss01248.flipperUtil' + //all*.exclude group: 'com.github.hss01248.flipperUtil' // all*.exclude group: 'me.weishu', module: 'free_reflection' } diff --git a/app/src/main/java/com/hss01248/flipperdemo/MainActivity.java b/app/src/main/java/com/hss01248/flipperdemo/MainActivity.java index 3f75ce9..76a0b9a 100644 --- a/app/src/main/java/com/hss01248/flipperdemo/MainActivity.java +++ b/app/src/main/java/com/hss01248/flipperdemo/MainActivity.java @@ -1,18 +1,22 @@ package com.hss01248.flipperdemo; +import android.app.ProgressDialog; import android.os.Bundle; import android.util.Log; import android.view.View; import androidx.appcompat.app.AppCompatActivity; -import com.blankj.utilcode.util.LogUtils; +import com.blankj.utilcode.util.ConvertUtils; import com.blankj.utilcode.util.ThreadUtils; import com.blankj.utilcode.util.ToastUtils; +import com.facebook.flipper.plugins.network.NetworkReporter; +import com.facebook.flipper.plugins.network.RequestBodyParser; import com.hjq.permissions.OnPermissionCallback; import com.hjq.permissions.Permission; import com.hjq.permissions.XXPermissions; import com.hss01248.flipper.DBAspect; +import com.hss01248.flipper.FlipperUtil; import com.hss01248.http.ConfigInfo; import com.hss01248.http.HttpUtil; import com.hss01248.http.callback.MyNetCallback; @@ -35,6 +39,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -46,6 +51,7 @@ import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.logging.HttpLoggingInterceptor; +import okio.Buffer; public class MainActivity extends AppCompatActivity { @@ -57,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) { //.addInterceptor(new MyAppHelperInterceptor()) .retryOnConnectionFailure(false).build(); + + XXPermissions.with(this).permission(Permission.MANAGE_EXTERNAL_STORAGE) .request(new OnPermissionCallback() { @Override @@ -253,7 +261,11 @@ public void onSuccess(Object result) { * @param view */ public void downloadLargeFile(View view) { - String url = "https://media.w3.org/2010/05/sintel/trailer.mp4"; + //String url = "https://media.w3.org/2010/05/sintel/trailer.mp4"; + String url = "https://services.gradle.org/distributions/gradle-6.5-rc-1-docs.zip"; + ProgressDialog dialog = new ProgressDialog(this); + dialog.setCanceledOnTouchOutside(false); + HttpUtil.download(url) .setFileDownlodConfig(FileDownlodConfig.newBuilder() .fileDir(getExternalFilesDir("down").getAbsolutePath()) @@ -261,17 +273,30 @@ public void downloadLargeFile(View view) { .callback(new MyNetCallback>() { @Override public void onSuccess(ResponseBean response) { + dialog.dismiss(); + ToastUtils.showShort("success"); } + @Override + protected void onStart() { + super.onStart(); + dialog.show(); + } + @Override public void onProgressChange(long transPortedBytes, long totalBytes, ConfigInfo info) { super.onProgressChange(transPortedBytes, totalBytes, info); - LogUtils.i("transPortedBytes:"+transPortedBytes+"--totalBytes:"+totalBytes); + //LogUtils.i("transPortedBytes:"+transPortedBytes+"--totalBytes:"+totalBytes); + String percent = transPortedBytes*100f/totalBytes+"%\n"+ + ConvertUtils.byte2FitMemorySize(transPortedBytes,1)+"/"+ConvertUtils.byte2FitMemorySize(totalBytes,1); + dialog.setMessage(percent); + } @Override public void onError(String msgCanShow) { + dialog.dismiss(); ToastUtils.showLong(msgCanShow); } diff --git a/build.gradle b/build.gradle index 54c355c..ec04928 100644 --- a/build.gradle +++ b/build.gradle @@ -46,17 +46,7 @@ buildscript { task clean(type: Delete) { delete rootProject.buildDir } -allprojects { - repositories { - /* maven { - url 'https://nexus.hss01248.tech/repository/jitpack_proxy' - credentials { - username "fetcher" - password "123456qt" - } - }*/ - } -} + //url 'https://jitpack.io' //动态修改/优化repo,会造成idea代码报错. 只能加,不能减? diff --git a/network-body-meta-interceptor/src/main/java/com/hss01248/network/body/meta/interceptor/MyAppHelperInterceptor.java b/network-body-meta-interceptor/src/main/java/com/hss01248/network/body/meta/interceptor/MyAppHelperInterceptor.java index b935526..67bf1c6 100644 --- a/network-body-meta-interceptor/src/main/java/com/hss01248/network/body/meta/interceptor/MyAppHelperInterceptor.java +++ b/network-body-meta-interceptor/src/main/java/com/hss01248/network/body/meta/interceptor/MyAppHelperInterceptor.java @@ -15,7 +15,9 @@ import okhttp3.Headers; import okhttp3.Interceptor; +import okhttp3.MediaType; import okhttp3.Request; +import okhttp3.RequestBody; import okhttp3.Response; public class MyAppHelperInterceptor implements Interceptor { @@ -74,8 +76,19 @@ public Response intercept(Chain chain) throws IOException { context = activity.getClass().getSimpleName(); } id = UUID.randomUUID().toString(); + + String bodyType = ""; + RequestBody requestBody = request.body(); + if(requestBody != null){ + MediaType mediaType = requestBody.contentType(); + if(mediaType!=null){ + bodyType = mediaType.toString(); + } + } + request = request.newBuilder() .header(KEY_REQUEST_ID, id) + .header(KEY_FLIPPER_PREFIX+"body-type", bodyType) .header(KEY_FLIPPER_PREFIX+"top-activity", context) .build(); requestBodyMap.put(id,bodyMetaData); diff --git a/network-hooks-logging/consumer-rules.pro b/network-hooks-logging/consumer-rules.pro index e69de29..d68188d 100644 --- a/network-hooks-logging/consumer-rules.pro +++ b/network-hooks-logging/consumer-rules.pro @@ -0,0 +1,2 @@ +-keep class okhttp3.** { *;} +-keep class com.hss01248.network.logging.** { *;} \ No newline at end of file diff --git a/network-hooks-logging/src/main/java/com/hss01248/network/logging/HttpLogggingAspect.java b/network-hooks-logging/src/main/java/com/hss01248/network/logging/HttpLogggingAspect.java new file mode 100644 index 0000000..2653f15 --- /dev/null +++ b/network-hooks-logging/src/main/java/com/hss01248/network/logging/HttpLogggingAspect.java @@ -0,0 +1,52 @@ +package com.hss01248.network.logging; + +import android.text.TextUtils; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +import okhttp3.Headers; + +/** + * @Despciption todo + * @Author hss + * @Date 25/10/2022 14:08 + * @Version 1.0 + */ +@Aspect +public class HttpLogggingAspect { + + /** + * 防止HttpLoggingInterceptor.Level.BODY时,retrofit的@Stream注解失效 + * @param joinPoint + * @return + * @throws Throwable + */ + @Around("execution(* okhttp3.logging.HttpLoggingInterceptor.bodyHasUnknownEncoding(..))") + public Object setWebViewClient(ProceedingJoinPoint joinPoint) throws Throwable{ + Headers headers = (Headers) joinPoint.getArgs()[0]; + //原始逻辑 + String contentEncoding = headers.get("Content-Encoding"); + if(contentEncoding != null + && (contentEncoding.equalsIgnoreCase("identity") || contentEncoding.equalsIgnoreCase("gzip"))){ + return false; + } + //新增逻辑 + String type = headers.get("Content-Type"); + if(!TextUtils.isEmpty(type)){ + if(type.contains("text") || type.contains("json") || type.contains("xml") || type.contains("x-www-form-urlencoded")){ + return false; + } + } + String type2 = headers.get("flipper-body-type"); + if(!TextUtils.isEmpty(type2)){ + if(type2.contains("text") || type2.contains("json") || type2.contains("xml") || type2.contains("x-www-form-urlencoded")){ + return false; + } + } + return true; + } + + +} diff --git a/network-hooks-logging/src/main/java/com/hss01248/network/logging/PrintReqeustBodyTypeToHeaderInterceptor.java b/network-hooks-logging/src/main/java/com/hss01248/network/logging/PrintReqeustBodyTypeToHeaderInterceptor.java new file mode 100644 index 0000000..051f0f5 --- /dev/null +++ b/network-hooks-logging/src/main/java/com/hss01248/network/logging/PrintReqeustBodyTypeToHeaderInterceptor.java @@ -0,0 +1,33 @@ +package com.hss01248.network.logging; + +import java.io.IOException; + +import okhttp3.Interceptor; +import okhttp3.MediaType; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +/** + * @Despciption todo + * @Author hss + * @Date 25/10/2022 15:16 + * @Version 1.0 + */ +@Deprecated +public class PrintReqeustBodyTypeToHeaderInterceptor implements Interceptor { + @Override + public Response intercept(Chain chain) throws IOException { + Request request = chain.request(); + RequestBody requestBody = request.body(); + if(requestBody != null){ + if (requestBody.contentType() != null) { + MediaType mediaType = requestBody.contentType(); + String type = mediaType.toString(); + Request build = request.newBuilder().addHeader("flipper-body-type", type).build(); + return chain.proceed(build); + } + } + return chain.proceed(request); + } +} diff --git a/remote3.gradle b/remote3.gradle index 5f1772f..be7a16b 100644 --- a/remote3.gradle +++ b/remote3.gradle @@ -78,6 +78,14 @@ static void assignRepos(Project project){ } mavenLocal() + /* maven { + //加到了group里,直接使用maven-public, 无需显式使用jitpack_proxy2 + url "https://nexus.hss01248.tech/repository/jitpack_proxy/" + *//*credentials{ + username "cccc" + password "ccccc" + }*//* + }*/ mavenCentral() google() jcenter()