├── XRetrofit ├── Could ├── annotations │ ├── .gitignore │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── yanxuwen │ │ │ └── xretrofit_annotations │ │ │ └── annotation │ │ │ ├── service │ │ │ └── NetServiceClass.java │ │ │ ├── param │ │ │ ├── Body.java │ │ │ ├── Param.java │ │ │ ├── Query.java │ │ │ ├── FilePath.java │ │ │ ├── Header.java │ │ │ └── Path.java │ │ │ └── method │ │ │ ├── GET.java │ │ │ ├── PUT.java │ │ │ ├── DELETE.java │ │ │ ├── FORM.java │ │ │ ├── UPLOAD.java │ │ │ ├── DOWNLOAD.java │ │ │ ├── POST.java │ │ │ └── Headers.java │ └── build.gradle ├── app │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── xml │ │ │ │ └── network_security_config.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── yanxuwen │ │ │ │ └── xretrofit │ │ │ │ ├── bean │ │ │ │ ├── HomeInfoV5.java │ │ │ │ └── LoginBuild.java │ │ │ │ ├── converter │ │ │ │ ├── GsonRequestConverter.java │ │ │ │ ├── GsonResponseConverter.java │ │ │ │ ├── Rxjava2CallAdapterFactories.java │ │ │ │ ├── GsonConverterFactories.java │ │ │ │ └── Rxjava2CallAdapter.java │ │ │ │ ├── http │ │ │ │ ├── HttpRequest.java │ │ │ │ └── NetService.java │ │ │ │ ├── callback │ │ │ │ ├── MyProgressCallBack.java │ │ │ │ ├── ServerException.java │ │ │ │ └── MyCallBack.java │ │ │ │ ├── RxSchedulers.java │ │ │ │ ├── MyApplication.java │ │ │ │ └── MainActivity.java │ │ │ └── AndroidManifest.xml │ ├── proguard-rules.pro │ └── build.gradle ├── compiler │ ├── .gitignore │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── xretrofit │ │ │ └── compiler │ │ │ ├── ElementUtils.java │ │ │ ├── HttpServiceProcessor2.java │ │ │ └── create │ │ │ └── CreateClassUtils.java │ └── build.gradle ├── xretrofit │ ├── .gitignore │ ├── src │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ └── com │ │ │ └── xretrofit │ │ │ ├── callback │ │ │ ├── ProgressCallBack.java │ │ │ └── CallBack.java │ │ │ ├── converter │ │ │ ├── UploadRequestConverter.java │ │ │ ├── StringResponseConverter.java │ │ │ ├── UploadConverterFactories.java │ │ │ ├── StringConverterFactories.java │ │ │ ├── DownloadConverterFactories.java │ │ │ ├── Converter.java │ │ │ └── DownloadResponseConverter.java │ │ │ ├── Interceptor │ │ │ ├── ProgressListener.java │ │ │ ├── UploadRequestBodyBody.java │ │ │ └── DownloadResponseBody.java │ │ │ ├── CallAdapter │ │ │ ├── MCallAdapter.java │ │ │ ├── ObjectCallAdapter.java │ │ │ ├── CallAdapter.java │ │ │ ├── ProgressCallAdapter.java │ │ │ └── ObjectCallAdapterFactory.java │ │ │ ├── call │ │ │ ├── Call.java │ │ │ ├── ProgressCall.java │ │ │ └── OkHttpCall.java │ │ │ ├── method │ │ │ ├── MethodAnnotation.java │ │ │ ├── ParamAnnotation.java │ │ │ └── ServiceMethod.java │ │ │ ├── utils │ │ │ ├── UrlUtils.java │ │ │ └── Utils.java │ │ │ ├── bean │ │ │ └── RequestParams.java │ │ │ ├── HttpException.java │ │ │ ├── Response.java │ │ │ ├── HttpManager.java │ │ │ └── okhttp │ │ │ └── SslUtils.java │ ├── proguard-rules.pro │ └── build.gradle ├── settings.gradle ├── jitpack.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── .gitignore ├── build.gradle ├── gradle.properties ├── versions.gradle ├── install.gradle ├── bintray.gradle ├── gradlew.bat └── gradlew └── README.md /XRetrofit/Could: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /XRetrofit/annotations/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /XRetrofit/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /XRetrofit/compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /XRetrofit/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':annotations' 2 | include ':app', ':xretrofit', ':compiler' 3 | -------------------------------------------------------------------------------- /XRetrofit/jitpack.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = 'com.github.yanxuwen' 4 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | XRetrofit 3 | 4 | -------------------------------------------------------------------------------- /XRetrofit/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yanxuwen/XRetrofit/HEAD/XRetrofit/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /XRetrofit/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 16 17:53:26 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/callback/ProgressCallBack.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.callback; 2 | 3 | public abstract class ProgressCallBack implements CallBack { 4 | 5 | /** 6 | * 进度 7 | */ 8 | public abstract void onProgress(float progress); 9 | } 10 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/xml/network_security_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/callback/CallBack.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.callback; 2 | 3 | import com.xretrofit.call.Call; 4 | import com.xretrofit.Response; 5 | 6 | 7 | public interface CallBack { 8 | 9 | void onStart(Call call); 10 | 11 | void onSuccess(Call call, Response response); 12 | 13 | void onFail(Call call, final Throwable e); 14 | } -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/bean/HomeInfoV5.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.bean; 2 | 3 | /** 4 | * @author bsnl_yanxuwen 5 | * @date 2021/2/19 9:21 6 | * Description : 7 | */ 8 | public class HomeInfoV5 { 9 | 10 | private String msg; 11 | 12 | public String getMsg() { 13 | return msg; 14 | } 15 | 16 | public void setMsg(String msg) { 17 | this.msg = msg; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/compiler/src/main/java/com/xretrofit/compiler/ElementUtils.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.compiler; 2 | 3 | /** 4 | * 这个类改版的话,HttpManager里面的getImplName 也需要改变 5 | */ 6 | @SuppressWarnings("unchecked") 7 | public class ElementUtils { 8 | public static String packageName = "com.http"; 9 | 10 | public static String getImplName(Class clazz) { 11 | return packageName + "." + clazz.getSimpleName() + "$Impl"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/UploadRequestConverter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import okhttp3.RequestBody; 4 | 5 | /** 6 | * @author bsnl_yanxuwen 7 | * @date 2021/2/8 9:25 8 | * Description : 9 | * * 接口数据转换 10 | * * 返回接口的 上次操作 11 | */ 12 | public class UploadRequestConverter implements Converter { 13 | 14 | @Override 15 | public RequestBody convert(T value) throws Exception { 16 | return null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/service/NetServiceClass.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit_annotations.annotation.service; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE}) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface NetServiceClass { 11 | String value() default ""; 12 | } 13 | -------------------------------------------------------------------------------- /XRetrofit/annotations/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | ext { 4 | bintrayName = 'annotations' 5 | artifact = bintrayName 6 | libraryName = 'xretrofit-annotations' 7 | libraryDescription = 'this is a xretrofit-annotations' 8 | libraryVersion = main_version 9 | } 10 | compileJava { 11 | sourceCompatibility = '1.8' 12 | targetCompatibility = '1.8' 13 | } 14 | 15 | dependencies { 16 | } 17 | 18 | //apply from: '../install.gradle' 19 | //apply from: '../bintray.gradle' 20 | apply from: '../jitpack.gradle' 21 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/StringResponseConverter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import okhttp3.ResponseBody; 4 | 5 | /** 6 | * @author bsnl_yanxuwen 7 | * @date 2021/2/4 17:09 8 | * Description : 9 | * 接口数据转换 10 | * 返回接口的 字符串操作 11 | */ 12 | public class StringResponseConverter implements Converter { 13 | 14 | 15 | @Override 16 | public T convert(ResponseBody value) throws Exception { 17 | String responseStr = value.string(); 18 | return (T) responseStr; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/Body.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.PARAMETER}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface Body { 18 | } 19 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/bean/LoginBuild.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.bean; 2 | 3 | public class LoginBuild { 4 | 5 | /** 6 | * password : “123456” 7 | * mobile : “15060568265” 8 | */ 9 | 10 | private String userId; 11 | private String msg; 12 | 13 | public String getUserId() { 14 | return userId; 15 | } 16 | 17 | public void setUserId(String userId) { 18 | this.userId = userId; 19 | } 20 | 21 | public String getMsg() { 22 | return msg; 23 | } 24 | 25 | public void setMsg(String msg) { 26 | this.msg = msg; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/Param.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.PARAMETER}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface Param { 18 | String value(); 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/Query.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.PARAMETER}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface Query { 18 | String value(); 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/GET.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface GET { 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/PUT.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface PUT { 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/DELETE.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface DELETE { 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/FORM.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | * 标记是否是表单提交 16 | */ 17 | @Documented 18 | @Target({ElementType.METHOD}) 19 | @Retention(RetentionPolicy.CLASS) 20 | public @interface FORM { 21 | } 22 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/UPLOAD.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface UPLOAD { 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/Interceptor/ProgressListener.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.Interceptor; 2 | 3 | /** 4 | * @author bsnl_yanxuwen 5 | * @date 2021/2/8 9:45 6 | * Description : 7 | */ 8 | public class ProgressListener { 9 | public void setProgress(float progress) { 10 | if (listener != null) { 11 | listener.progress(progress); 12 | } 13 | } 14 | 15 | public interface Listener { 16 | public void progress(float progress); 17 | } 18 | 19 | private Listener listener; 20 | 21 | public void setProgressListener(Listener listener) { 22 | this.listener = listener; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/DOWNLOAD.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface DOWNLOAD { 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/POST.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface POST { 18 | String value() default ""; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/method/Headers.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.method; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Target({ElementType.METHOD}) 16 | @Retention(RetentionPolicy.CLASS) 17 | public @interface Headers { 18 | String[] value(); 19 | boolean encoded() default false; 20 | } 21 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/FilePath.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | //用于文件上传用的路径 15 | //支持 File String List List 16 | @Documented 17 | @Target({ElementType.PARAMETER}) 18 | @Retention(RetentionPolicy.CLASS) 19 | public @interface FilePath { 20 | } 21 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/Header.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.CLASS) 16 | @Target({ElementType.PARAMETER}) 17 | public @interface Header { 18 | String value(); 19 | boolean encoded() default false; 20 | } 21 | -------------------------------------------------------------------------------- /XRetrofit/annotations/src/main/java/com/yanxuwen/xretrofit_annotations/annotation/param/Path.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by Fernflower decompiler) 4 | // 5 | 6 | package com.yanxuwen.xretrofit_annotations.annotation.param; 7 | 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | @Documented 15 | @Retention(RetentionPolicy.CLASS) 16 | @Target({ElementType.PARAMETER}) 17 | public @interface Path { 18 | String value(); 19 | 20 | boolean encoded() default false; 21 | } 22 | -------------------------------------------------------------------------------- /XRetrofit/.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | 39 | # Keystore files 40 | *.jks 41 | 42 | # External native build folder generated in Android Studio 2.2 and later 43 | .externalNativeBuild -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/CallAdapter/MCallAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.CallAdapter; 2 | 3 | import com.xretrofit.call.Call; 4 | 5 | import java.lang.reflect.Type; 6 | 7 | /** 8 | * @author bsnl_yanxuwen 9 | * @date 2021/2/4 17:49 10 | * Description : 11 | * 返回类型为Call<> 的适配器 12 | */ 13 | public class MCallAdapter implements CallAdapter { 14 | 15 | private Type responseType; 16 | 17 | protected MCallAdapter(Type responseType){ 18 | this.responseType = responseType; 19 | } 20 | 21 | 22 | @Override 23 | public Type responseType() { 24 | return responseType; 25 | } 26 | 27 | 28 | @Override 29 | public Call adapt(Call call) { 30 | return call; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /XRetrofit/compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | ext { 3 | bintrayName = 'compiler' 4 | artifact = bintrayName 5 | libraryName = 'xretrofit compiler' 6 | libraryDescription = 'this is a xretrofit-compiler' 7 | libraryVersion = main_version 8 | } 9 | compileJava { 10 | sourceCompatibility = '1.8' 11 | targetCompatibility = '1.8' 12 | } 13 | 14 | dependencies { 15 | implementation 'com.google.auto.service:auto-service:1.0-rc6' 16 | annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6' 17 | 18 | implementation 'com.squareup:javapoet:1.10.0' 19 | 20 | implementation project(path: ':annotations') 21 | } 22 | 23 | //apply from: '../install.gradle' 24 | //apply from: '../bintray.gradle' 25 | apply from: '../jitpack.gradle' 26 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/converter/GsonRequestConverter.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.converter; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.xretrofit.converter.Converter; 5 | 6 | import okhttp3.MediaType; 7 | import okhttp3.RequestBody; 8 | 9 | /** 10 | * @author bsnl_yanxuwen 11 | * @date 2021/2/5 16:00 12 | * Description : 13 | * 请求参数数据转换 14 | */ 15 | class GsonRequestConverter implements Converter { 16 | private static final MediaType JSON = MediaType.parse("application/json;charset=utf-8"); 17 | 18 | 19 | @Override 20 | public RequestBody convert(T value) throws Exception { 21 | RequestBody requestBody = RequestBody.create(JSON, JSONObject.toJSONString(value)); 22 | return requestBody; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/call/Call.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.call; 2 | 3 | import com.xretrofit.Response; 4 | import com.xretrofit.callback.CallBack; 5 | import com.xretrofit.converter.Converter; 6 | 7 | import okhttp3.ResponseBody; 8 | 9 | 10 | /** 11 | * @author bsnl_yanxuwen 12 | * @date 2021/2/4 11:02 13 | * Description : 14 | * 15 | */ 16 | public interface Call { 17 | 18 | /** 19 | * 初始化接口返回类型 20 | */ 21 | void init(Converter responseConverter); 22 | 23 | /** 24 | * 执行请求,异步 25 | */ 26 | void enqueue(CallBack callback); 27 | 28 | 29 | /** 30 | * 执行请求同步 31 | */ 32 | Response execute() throws Exception; 33 | 34 | 35 | void cancel(); 36 | 37 | boolean isCanceled(); 38 | 39 | Call clone(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/http/HttpRequest.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.http; 2 | 3 | import com.xretrofit.HttpManager; 4 | 5 | public class HttpRequest { 6 | 7 | private static NetService netService; 8 | 9 | public static NetService getNetService() { 10 | try { 11 | if (netService == null) { 12 | synchronized (HttpRequest.class) { 13 | if (netService == null) { 14 | netService = (NetService) Class.forName(HttpManager.getImplName(NetService.class)) 15 | .getConstructor().newInstance(); 16 | } 17 | } 18 | } 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | return netService; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /XRetrofit/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/CallAdapter/ObjectCallAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.CallAdapter; 2 | 3 | import com.xretrofit.call.Call; 4 | 5 | import java.lang.reflect.Type; 6 | 7 | /** 8 | * @author bsnl_yanxuwen 9 | * @date 2021/2/4 17:49 10 | * Description : 11 | * 同步 12 | * Object 适配器, 13 | */ 14 | public class ObjectCallAdapter implements CallAdapter { 15 | 16 | private Type responseType; 17 | 18 | protected ObjectCallAdapter(Type responseType){ 19 | this.responseType = responseType; 20 | } 21 | 22 | @Override 23 | public Type responseType() { 24 | return responseType; 25 | } 26 | 27 | @Override 28 | public Object adapt(Call call) { 29 | try { 30 | return call.execute().body(); 31 | } catch (Exception e) { 32 | return null; 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /XRetrofit/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | apply from: 'versions.gradle' 5 | repositories { 6 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 7 | jcenter() 8 | google() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.6.0' 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 14 | } 15 | 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 21 | maven { url 'https://jitpack.io' } 22 | jcenter() 23 | google() 24 | } 25 | } 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/converter/GsonResponseConverter.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.converter; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.xretrofit.converter.Converter; 5 | 6 | import java.lang.reflect.Type; 7 | 8 | import okhttp3.ResponseBody; 9 | 10 | /** 11 | * @author bsnl_yanxuwen 12 | * @date 2021/2/4 17:09 13 | * Description : 14 | * 请求结果数据转换 15 | * Gson操作 16 | */ 17 | public class GsonResponseConverter implements Converter { 18 | 19 | private Type responseType; 20 | 21 | protected GsonResponseConverter(Type responseType){ 22 | this.responseType = responseType; 23 | } 24 | 25 | 26 | @Override 27 | public T convert(ResponseBody value) throws Exception { 28 | String responseStr = value.string(); 29 | return (T) JSONObject.parseObject(responseStr,responseType); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/CallAdapter/CallAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.CallAdapter; 2 | 3 | import com.xretrofit.call.Call; 4 | import com.xretrofit.utils.Utils; 5 | 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | /** 11 | * @author bsnl_yanxuwen 12 | * @date 2021/2/4 16:02 13 | * Description : 14 | * 适配器 15 | * 16 | * R 为 封装后的类型。 17 | * T 为接口返回类型 18 | */ 19 | public interface CallAdapter{ 20 | R adapt(Call call); 21 | 22 | /** 23 | * 接口数据 类型 24 | */ 25 | Type responseType(); 26 | 27 | abstract class Factory { 28 | /** 29 | * 封装转换器,如封装Observable 30 | */ 31 | public abstract @Nullable CallAdapter get(Type returnType); 32 | 33 | protected static Class getRawType(Type type) { 34 | return Utils.getRawType(type); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/UploadConverterFactories.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import com.yanxuwen.xretrofit_annotations.annotation.method.UPLOAD; 4 | 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.lang.reflect.Type; 8 | 9 | import okhttp3.RequestBody; 10 | 11 | /** 12 | * @author bsnl_yanxuwen 13 | * @date 2021/2/7 16:32 14 | * 接口数据转换器 15 | * 转换器 16 | */ 17 | public class UploadConverterFactories extends Converter.Factory { 18 | 19 | public static UploadConverterFactories create() { 20 | return new UploadConverterFactories(); 21 | } 22 | 23 | @Nullable 24 | @Override 25 | public Converter requestBodyConverter(Type request, Type requestParamType) { 26 | if (request == UPLOAD.class) { 27 | return new UploadRequestConverter<>(); 28 | } 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/StringConverterFactories.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | import java.lang.reflect.Type; 6 | 7 | import okhttp3.ResponseBody; 8 | 9 | /** 10 | * @author bsnl_yanxuwen 11 | * @date 2021/2/4 15:46 12 | * Description : 13 | * 接口数据转换器 14 | * 字符串转换器 15 | */ 16 | public class StringConverterFactories extends Converter.Factory { 17 | 18 | public static StringConverterFactories create() { 19 | return new StringConverterFactories(); 20 | } 21 | 22 | 23 | @Nullable 24 | @Override 25 | public Converter responseBodyConverter(Type request,Type responseType) { 26 | Class rawType = getRawType(responseType); 27 | if (rawType == String.class) { 28 | return new StringResponseConverter(); 29 | } 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/DownloadConverterFactories.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import com.yanxuwen.xretrofit_annotations.annotation.method.DOWNLOAD; 4 | 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.lang.reflect.Type; 8 | 9 | import okhttp3.ResponseBody; 10 | 11 | /** 12 | * @author bsnl_yanxuwen 13 | * @date 2021/2/7 16:32 14 | * 接口数据转换器 15 | * 下载转换器 16 | */ 17 | public class DownloadConverterFactories extends Converter.Factory { 18 | 19 | public static DownloadConverterFactories create() { 20 | return new DownloadConverterFactories(); 21 | } 22 | 23 | 24 | @Nullable 25 | @Override 26 | public Converter responseBodyConverter(Type request, Type responseType) { 27 | if (request == DOWNLOAD.class) { 28 | return new DownloadResponseConverter(); 29 | } 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/callback/MyProgressCallBack.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.callback; 2 | 3 | import com.xretrofit.Response; 4 | import com.xretrofit.call.Call; 5 | import com.xretrofit.callback.ProgressCallBack; 6 | 7 | public abstract class MyProgressCallBack extends ProgressCallBack { 8 | 9 | @Override 10 | public void onStart(Call call) { 11 | 12 | } 13 | 14 | @Override 15 | public final void onSuccess(Call call, Response response) { 16 | if (response.errorBody() != null) { 17 | fail("网络异常"); 18 | return; 19 | } 20 | success(response.body()); 21 | 22 | } 23 | 24 | @Override 25 | public final void onFail(Call call, Throwable e) { 26 | fail(ServerException.handleException(e)); 27 | } 28 | 29 | 30 | public abstract void success(T t); 31 | 32 | public abstract void fail(String msg); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/CallAdapter/ProgressCallAdapter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.CallAdapter; 2 | 3 | import com.xretrofit.call.Call; 4 | import com.xretrofit.call.ProgressCall; 5 | 6 | import java.lang.reflect.Type; 7 | 8 | /** 9 | * @author bsnl_yanxuwen 10 | * @date 2021/2/4 17:49 11 | * Description : 12 | * 返回类型为{@link ProgressCall<> 的适配器 带进度的 13 | */ 14 | public class ProgressCallAdapter implements CallAdapter { 15 | 16 | private Type responseType; 17 | 18 | protected ProgressCallAdapter(Type responseType){ 19 | this.responseType = responseType; 20 | } 21 | 22 | @Override 23 | public ProgressCall adapt(Call call) { 24 | if (call != null){ 25 | return (ProgressCall) call; 26 | } 27 | return null; 28 | } 29 | 30 | @Override 31 | public Type responseType() { 32 | return responseType; 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/converter/Rxjava2CallAdapterFactories.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.converter; 2 | 3 | import com.xretrofit.CallAdapter.CallAdapter; 4 | import com.xretrofit.utils.Utils; 5 | 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | import io.reactivex.Observable; 11 | 12 | /** 13 | * @author bsnl_yanxuwen 14 | * @date 2021/2/4 15:46 15 | * Description : 16 | * rxjava2 适配器 17 | */ 18 | public class Rxjava2CallAdapterFactories extends CallAdapter.Factory { 19 | 20 | public static Rxjava2CallAdapterFactories create() { 21 | return new Rxjava2CallAdapterFactories(); 22 | } 23 | 24 | 25 | @Nullable 26 | @Override 27 | public CallAdapter get(Type returnType) { 28 | Class rawType = getRawType(returnType); 29 | final Type responseType = Utils.getCallResponseType(returnType); 30 | if (rawType == Observable.class) { 31 | return new Rxjava2CallAdapter(responseType); 32 | } 33 | return null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/method/MethodAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.method; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author bsnl_yanxuwen 7 | * @date 2021/2/4 14:00 8 | * Description : 9 | * 方法注解,就是那些get post 10 | */ 11 | public class MethodAnnotation { 12 | private Class annotation;//注解类型 13 | private List key;//注解key 14 | 15 | public MethodAnnotation(Class annotation , List key){ 16 | this.annotation = annotation; 17 | this.key = key; 18 | 19 | } 20 | 21 | public Class getAnnotation() { 22 | return annotation; 23 | } 24 | 25 | /** 26 | * key虽然可以多个,但是这个基本都显示1个,并且为String 27 | */ 28 | public String getKey() { 29 | if (key == null || key.isEmpty()){ 30 | return null; 31 | } 32 | if (key.get(0) instanceof String){ 33 | return (String) key.get(0); 34 | } 35 | return null; 36 | } 37 | 38 | /** 39 | * @Headers 使用 40 | */ 41 | public List getKeys() { 42 | return key; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/CallAdapter/ObjectCallAdapterFactory.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.CallAdapter; 2 | 3 | import com.xretrofit.call.Call; 4 | import com.xretrofit.call.ProgressCall; 5 | import com.xretrofit.utils.Utils; 6 | 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.lang.reflect.Type; 10 | 11 | /** 12 | * @author bsnl_yanxuwen 13 | * @date 2021/2/4 17:47 14 | * Description : 15 | * 适配器Factory 16 | */ 17 | public class ObjectCallAdapterFactory extends CallAdapter.Factory { 18 | 19 | public static ObjectCallAdapterFactory create() { 20 | return new ObjectCallAdapterFactory(); 21 | } 22 | 23 | 24 | @Nullable 25 | @Override 26 | public CallAdapter get(Type returnType) { 27 | Class rawType = getRawType(returnType); 28 | final Type responseType = Utils.getCallResponseType(returnType); 29 | if (rawType == ProgressCall.class) { 30 | return new ProgressCallAdapter(responseType); 31 | } else if (rawType == Call.class) { 32 | return new MCallAdapter<>(responseType); 33 | } 34 | return new ObjectCallAdapter(responseType); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/method/ParamAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.method; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author bsnl_yanxuwen 7 | * @date 2021/2/4 14:00 8 | * Description : 9 | * 参数注解, Queue,Path 10 | */ 11 | public class ParamAnnotation { 12 | private Class annotation;//注解类型 13 | private List key;//注解key ,会存在第一个key 14 | private Object value;//注解字段,会存在为空问题 15 | 16 | public ParamAnnotation(Class annotation, List key, Object value) { 17 | this.annotation = annotation; 18 | this.key = key; 19 | this.value = value; 20 | } 21 | 22 | public Class getAnnotation() { 23 | return annotation; 24 | } 25 | 26 | /** 27 | * key虽然可以多个,但是这个基本都显示1个,并且为String 28 | */ 29 | public String getKey() { 30 | if (key == null || key.isEmpty()){ 31 | return null; 32 | } 33 | if (key.get(0) instanceof String){ 34 | return (String) key.get(0); 35 | } 36 | return null; 37 | } 38 | 39 | public Object getValue() { 40 | return value; 41 | } 42 | 43 | public void setValue(Object value) { 44 | this.value = value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | ext { 3 | bintrayName = 'xretrofit' 4 | artifact = bintrayName 5 | libraryName = 'xretrofit api' 6 | libraryDescription = 'xretrofit' 7 | libraryVersion = main_version 8 | } 9 | 10 | android { 11 | compileSdkVersion 28 12 | buildToolsVersion "28.0.3" 13 | defaultConfig { 14 | minSdkVersion 15 15 | targetSdkVersion 28 16 | versionCode 1 17 | versionName "1.0" 18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 19 | javaCompileOptions { 20 | annotationProcessorOptions { 21 | includeCompileClasspath true 22 | } 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 28 | } 29 | } 30 | } 31 | } 32 | dependencies { 33 | implementation fileTree(dir: 'libs', include: ['*.jar']) 34 | api other.okhttp 35 | api other.guava 36 | api project(path: ':annotations') 37 | } 38 | 39 | //apply from: '../install.gradle' 40 | //apply from: '../bintray.gradle' 41 | apply from: '../jitpack.gradle' 42 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/converter/GsonConverterFactories.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.converter; 2 | 3 | import com.xretrofit.converter.Converter; 4 | 5 | import org.jetbrains.annotations.Nullable; 6 | 7 | import java.lang.reflect.Type; 8 | 9 | import okhttp3.RequestBody; 10 | import okhttp3.ResponseBody; 11 | 12 | /** 13 | * @author bsnl_yanxuwen 14 | * @date 2021/2/4 15:46 15 | * Description : 16 | * 接口数据转换器 17 | * fastjson转换器 18 | */ 19 | public class GsonConverterFactories extends Converter.Factory { 20 | 21 | public static GsonConverterFactories create() { 22 | return new GsonConverterFactories(); 23 | } 24 | 25 | @Nullable 26 | @Override 27 | public Converter requestBodyConverter(Type request, Type requestParamType) { 28 | if (requestParamType instanceof Object) { 29 | return new GsonRequestConverter(); 30 | } 31 | return null; 32 | } 33 | 34 | @Nullable 35 | @Override 36 | public Converter responseBodyConverter(Type request, Type responseType) { 37 | Class rawType = getRawType(responseType); 38 | if (rawType instanceof Object) { 39 | return new GsonResponseConverter(responseType); 40 | } 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /XRetrofit/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | # When configured, Gradle will run in incubating parallel mode. 10 | # This option should only be used with decoupled projects. More details, visit 11 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 12 | # org.gradle.parallel=true 13 | org.gradle.daemon=true 14 | 15 | bintrayRepo=maven 16 | main_version=0.0.8 17 | publishedGroupId=com.github.yanxuwen 18 | siteUrl=https://github.com/yanxuwen/xretrofit 19 | gitUrl=https://github.com/yanxuwen/xretrofit.git 20 | developerId=yxe 21 | developerName=yanxuwen 22 | developerEmail=420255048@qq.com 23 | android.useAndroidX=true 24 | android.enableJetifier=true 25 | 26 | 27 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 28 | 29 | #org.gradle.jvmargs= -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005, 30 | #Dorg.gradle.debug=true 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /XRetrofit/versions.gradle: -------------------------------------------------------------------------------- 1 | /** 2 | * Shared file between builds so that they can all use the same dependencies and 3 | * maven repositories. 4 | **/ 5 | ext.deps = [:] 6 | ext.support_version = '23.1.1' 7 | ext.kotlin_version = '1.3.0' 8 | ext.anko_version = '0.8.2' 9 | ext.butterknife_version = '8.8.1' 10 | 11 | def build_versions = [:] 12 | build_versions.min_sdk = 16 13 | build_versions.target_sdk = 28 14 | build_versions.build_tools = "28.0.3" 15 | ext.build_versions = build_versions 16 | 17 | def versions = [:] 18 | versions.support = "28.0.0" 19 | 20 | def support = [:] 21 | support.app_compat = "androidx.appcompat:appcompat:1.0.0" 22 | support.design = "com.google.android.material:material:1.0.0" 23 | support.recyclerview = "androidx.recyclerview:recyclerview:1.0.0" 24 | support.constraintlayout = 'androidx.constraintlayout:constraintlayout:1.1.3' 25 | ext.support = support 26 | 27 | def other = [:] 28 | other.okhttp = 'com.squareup.okhttp3:okhttp:4.1.0' 29 | other.fastjson = 'com.alibaba:fastjson:1.2.57' 30 | other.rxpermissions = 'com.github.tbruyelle:rxpermissions:0.10.2' 31 | other.rxandroid = 'io.reactivex.rxjava2:rxandroid:2.1.1' 32 | other.rxjava = 'io.reactivex.rxjava2:rxjava:2.2.19' 33 | other.autoDispose = 'com.uber.autodispose:autodispose-android-archcomponents:1.0.0-RC2' 34 | other.guava = 'com.google.guava:guava:27.0.1-jre' 35 | 36 | ext.other = other 37 | 38 | 39 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/utils/UrlUtils.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | public class UrlUtils { 8 | /** 9 | * @param url 实际URL的path 10 | * @param params 11 | * @return 12 | */ 13 | public static String urlJoint(String url, Map params) { 14 | StringBuilder realURL = new StringBuilder(); 15 | realURL = realURL.append(url); 16 | boolean isFirst = true; 17 | if (params == null) { 18 | params = new HashMap<>(); 19 | } else { 20 | Set> entrySet = params.entrySet(); 21 | for (Map.Entry entry : entrySet) { 22 | if (isFirst && !url.contains("?")) { 23 | isFirst = false; 24 | realURL.append("?"); 25 | } else { 26 | realURL.append("&"); 27 | } 28 | realURL.append(entry.getKey()); 29 | realURL.append("="); 30 | if (entry.getValue() == null) { 31 | realURL.append(" "); 32 | } else { 33 | realURL.append(entry.getValue()); 34 | } 35 | 36 | } 37 | } 38 | 39 | return realURL.toString(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/RxSchedulers.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit; 2 | 3 | import androidx.lifecycle.Lifecycle; 4 | import androidx.lifecycle.LifecycleOwner; 5 | 6 | import com.uber.autodispose.AutoDispose; 7 | import com.uber.autodispose.ObservableSubscribeProxy; 8 | import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider; 9 | 10 | import io.reactivex.Observable; 11 | import io.reactivex.ObservableConverter; 12 | import io.reactivex.android.schedulers.AndroidSchedulers; 13 | import io.reactivex.annotations.NonNull; 14 | import io.reactivex.schedulers.Schedulers; 15 | 16 | /** 17 | * @author bsnl_yanxuwen 18 | * @date 2021/3/19 10:52 19 | * Description : 20 | */ 21 | public class RxSchedulers { 22 | public static ObservableConverter applySchedulers(LifecycleOwner owner) { 23 | return new ObservableConverter() { 24 | @NonNull 25 | @Override 26 | public ObservableSubscribeProxy apply(@NonNull Observable upstream) { 27 | return upstream 28 | .subscribeOn(Schedulers.io()) 29 | .observeOn(AndroidSchedulers.mainThread()) 30 | .as(AutoDispose.autoDisposable( 31 | AndroidLifecycleScopeProvider.from(owner, Lifecycle.Event.ON_DESTROY))); 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /XRetrofit/install.gradle: -------------------------------------------------------------------------------- 1 | // backup of [https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle] 2 | 3 | apply plugin: 'com.github.dcendents.android-maven' 4 | 5 | group = publishedGroupId // Maven Group ID for the artifact 6 | 7 | install { 8 | repositories.mavenInstaller { 9 | // This generates POM.xml with proper parameters 10 | pom { 11 | project { 12 | packaging 'aar' 13 | groupId publishedGroupId 14 | artifactId artifact 15 | 16 | // Add your description here 17 | name libraryName 18 | description libraryDescription 19 | url siteUrl 20 | 21 | // Set your license 22 | licenses { 23 | license { 24 | name 'The Apache Software License, Version 2.0' 25 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 26 | } 27 | } 28 | developers { 29 | developer { 30 | id developerId 31 | name developerName 32 | email developerEmail 33 | } 34 | } 35 | scm { 36 | connection gitUrl 37 | developerConnection gitUrl 38 | url siteUrl 39 | 40 | } 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/bean/RequestParams.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.bean; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * 自动生成用的请求参数 8 | */ 9 | public class RequestParams { 10 | private String url; 11 | private boolean isForm;//是否是表单提交 12 | private Map params; 13 | private Map headers; 14 | 15 | public String getUrl() { 16 | return url; 17 | } 18 | 19 | public void setUrl(String url) { 20 | this.url = url; 21 | } 22 | 23 | 24 | public Map getParams() { 25 | if (params == null){ 26 | return new HashMap<>(); 27 | } 28 | return params; 29 | } 30 | 31 | public void setParams(Map params) { 32 | this.params = params; 33 | } 34 | 35 | 36 | public Map getHeaders() { 37 | if (headers == null){ 38 | return new HashMap<>(); 39 | } 40 | return headers; 41 | } 42 | 43 | 44 | public void setHeaders(Map headers) { 45 | this.headers = headers; 46 | } 47 | 48 | public void addParams(String key, String value) { 49 | getParams().put(key, value); 50 | } 51 | 52 | public void addHeader(String key, String value) { 53 | getHeaders().put(key, value); 54 | } 55 | 56 | public boolean isForm() { 57 | return isForm; 58 | } 59 | 60 | public void setForm(boolean form) { 61 | isForm = form; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/callback/ServerException.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.callback; 2 | 3 | import org.apache.http.conn.ConnectTimeoutException; 4 | import org.json.JSONException; 5 | 6 | import java.io.NotSerializableException; 7 | import java.net.ConnectException; 8 | import java.net.SocketTimeoutException; 9 | import java.net.UnknownHostException; 10 | import java.text.ParseException; 11 | 12 | public class ServerException { 13 | 14 | public static String handleException(Throwable e) { 15 | String msg = e.getMessage(); 16 | if (e instanceof SocketTimeoutException) { 17 | msg = "网络连接超时,请检查网络"; 18 | } else if (e instanceof ConnectException) { 19 | msg = "网络异常,请检查网络"; 20 | } else if (e instanceof ConnectTimeoutException) { 21 | msg = "网络连接超时,请检查网络"; 22 | } else if (e instanceof UnknownHostException) { 23 | msg = "网络异常,请检查网络"; 24 | } else if (e instanceof NullPointerException) { 25 | msg = "空指针异常"; 26 | } else if (e instanceof javax.net.ssl.SSLHandshakeException) { 27 | msg = "证书验证失败"; 28 | } else if (e instanceof ClassCastException) { 29 | msg = "类型转换错误"; 30 | } else if (/*e instanceof JsonParseException ||*/ 31 | e instanceof JSONException || 32 | e instanceof com.alibaba.fastjson.JSONException || 33 | /*e instanceof JsonSerializer ||*/ 34 | e instanceof NotSerializableException || 35 | e instanceof ParseException) { 36 | msg = "解析错误"; 37 | } 38 | return msg; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /XRetrofit/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion build_versions.target_sdk 5 | buildToolsVersion build_versions.build_tools 6 | defaultConfig { 7 | applicationId "com.yanxuwen.myhttpservice" 8 | minSdkVersion build_versions.min_sdk 9 | targetSdkVersion build_versions.target_sdk 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | multiDexEnabled true 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | repositories { 22 | flatDir { dirs 'libs' } 23 | } 24 | 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | 30 | } 31 | //自动导入libs目录下的aar文件 32 | fileTree(dir: 'libs', include: '**/*.aar').each { File file -> 33 | dependencies.add("implementation", [name: file.name.lastIndexOf('.').with { 34 | it != -1 ? file.name[0.. response) { 24 | checkNotNull(response, "response == null"); 25 | return "HTTP " + response.code() + " " + response.message(); 26 | } 27 | 28 | private final int code; 29 | private final String message; 30 | private final transient Response response; 31 | 32 | public HttpException(Response response) { 33 | super(getMessage(response)); 34 | this.code = response.code(); 35 | this.message = response.message(); 36 | this.response = response; 37 | } 38 | 39 | /** HTTP status code. */ 40 | public int code() { 41 | return code; 42 | } 43 | 44 | /** HTTP status message. */ 45 | public String message() { 46 | return message; 47 | } 48 | 49 | /** 50 | * The full HTTP response. This may be null if the exception was serialized. 51 | */ 52 | public Response response() { 53 | return response; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/callback/MyCallBack.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit.callback; 2 | 3 | import android.util.Log; 4 | 5 | import androidx.fragment.app.FragmentActivity; 6 | import androidx.lifecycle.Lifecycle; 7 | import androidx.lifecycle.LifecycleObserver; 8 | import androidx.lifecycle.OnLifecycleEvent; 9 | 10 | import com.xretrofit.Response; 11 | import com.xretrofit.call.Call; 12 | import com.xretrofit.callback.CallBack; 13 | 14 | /** 15 | * @author bsnl_yanxuwen 16 | * @date 2021/2/5 11:19 17 | * Description : 18 | */ 19 | public abstract class MyCallBack implements CallBack { 20 | 21 | private FragmentActivity activity; 22 | 23 | public MyCallBack() { 24 | } 25 | 26 | public MyCallBack(FragmentActivity activity) { 27 | this.activity = activity; 28 | } 29 | 30 | @Override 31 | public void onStart(Call call) { 32 | if (activity != null) { 33 | activity.getLifecycle().addObserver(new LifecycleObserver() { 34 | @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 35 | public void onDestroy() { 36 | Log.e("yxw", "????取消请求"); 37 | call.cancel(); 38 | } 39 | 40 | }); 41 | } 42 | } 43 | 44 | @Override 45 | public final void onSuccess(Call call, Response response) { 46 | if (response.errorBody() != null) { 47 | fail("网络异常"); 48 | return; 49 | } 50 | success(response.body()); 51 | 52 | } 53 | 54 | @Override 55 | public final void onFail(Call call, Throwable e) { 56 | if (call.isCanceled()){ 57 | cancel(); 58 | } else { 59 | fail(ServerException.handleException(e)); 60 | } 61 | } 62 | 63 | 64 | public abstract void success(T t); 65 | 66 | public abstract void fail(String msg); 67 | 68 | public void cancel(){ 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/java/com/yanxuwen/xretrofit/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.yanxuwen.xretrofit; 2 | 3 | import android.app.Application; 4 | 5 | import com.xretrofit.HttpManager; 6 | import com.xretrofit.okhttp.SslUtils; 7 | import com.yanxuwen.xretrofit.converter.GsonConverterFactories; 8 | import com.yanxuwen.xretrofit.converter.Rxjava2CallAdapterFactories; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | import javax.net.ssl.HostnameVerifier; 13 | import javax.net.ssl.SSLSession; 14 | 15 | import okhttp3.OkHttpClient; 16 | 17 | public class MyApplication extends Application { 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | init(); 22 | } 23 | 24 | public void init() { 25 | 26 | OkHttpClient client = new OkHttpClient 27 | .Builder() 28 | .connectTimeout(15, TimeUnit.SECONDS)//连接超时时间 29 | .readTimeout(15, TimeUnit.SECONDS)//读取超时时间 30 | .writeTimeout(15, TimeUnit.SECONDS)//写入超时时间 31 | .retryOnConnectionFailure(false)//连接不上是否重连,false不重连 32 | .hostnameVerifier(new TrustAllHostnameVerifier())//校验名称,这个对象就是信任所有的主机,也就是信任所有https的请求 33 | .sslSocketFactory(SslUtils.getSslSocketFactory().sSLSocketFactory, SslUtils.getSslSocketFactory().trustManager) 34 | .build(); 35 | HttpManager.Builder() 36 | .baseUrl("https://bxapi.bisinuolan.cn/") 37 | .addConverterFactory(GsonConverterFactories.create())//FastJson转换器、可以替换成Gson 38 | .addCallAdapterFactory(Rxjava2CallAdapterFactories.create())//Rxjava2适配器,不配置有自带Call适配器 39 | .client(client) 40 | .build(); 41 | } 42 | 43 | /** 44 | * 信任所有的服务器,返回true 45 | */ 46 | private static class TrustAllHostnameVerifier implements HostnameVerifier { 47 | @Override 48 | public boolean verify(String hostname, SSLSession session) { 49 | return true; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/call/ProgressCall.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.call; 2 | 3 | import com.xretrofit.Interceptor.ProgressListener; 4 | import com.xretrofit.callback.CallBack; 5 | import com.xretrofit.callback.ProgressCallBack; 6 | 7 | import java.text.DecimalFormat; 8 | 9 | import okhttp3.Call; 10 | 11 | /** 12 | * @author bsnl_yanxuwen 13 | * @date 2021/2/7 17:05 14 | * Description : 15 | * 下载 16 | */ 17 | public class ProgressCall extends OkHttpCall { 18 | 19 | final DecimalFormat df = new DecimalFormat("#.00"); 20 | 21 | private ProgressListener[] listeners; 22 | 23 | /** 24 | * @param listeners 用于监听上传跟下载的时候用的 25 | */ 26 | public ProgressCall(Call call, ProgressListener... listeners) { 27 | super(call); 28 | this.listeners = listeners; 29 | } 30 | 31 | @Override 32 | public void enqueue(final CallBack callback) { 33 | super.enqueue(callback); 34 | if (callback instanceof ProgressCallBack) { 35 | final ProgressCallBack progressCallBack = (ProgressCallBack) callback; 36 | if (listeners != null) { 37 | final float[] totalProgress = new float[listeners.length]; 38 | for (int i = 0; i < listeners.length; i++) { 39 | final int finalI = i; 40 | listeners[i].setProgressListener(new ProgressListener.Listener() { 41 | @Override 42 | public void progress(float progress) { 43 | totalProgress[finalI] = progress; 44 | double total = 0; 45 | for (double mProcess : totalProgress) { 46 | total += mProcess; 47 | } 48 | progressCallBack.onProgress(Float.valueOf(df.format(total / listeners.length))); 49 | } 50 | }); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /XRetrofit/bintray.gradle: -------------------------------------------------------------------------------- 1 | // backup of [https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle] 2 | 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | version = libraryVersion 6 | 7 | if (project.hasProperty("android")) { // Android libraries 8 | task sourcesJar(type: Jar) { 9 | classifier = 'sources' 10 | from android.sourceSets.main.java.srcDirs 11 | } 12 | 13 | task javadoc(type: Javadoc) { 14 | source = android.sourceSets.main.java.srcDirs 15 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 16 | } 17 | } else { // Java libraries 18 | task sourcesJar(type: Jar, dependsOn: classes) { 19 | classifier = 'sources' 20 | from sourceSets.main.allSource 21 | } 22 | } 23 | 24 | task javadocJar(type: Jar, dependsOn: javadoc) { 25 | classifier = 'javadoc' 26 | from javadoc.destinationDir 27 | } 28 | 29 | artifacts { 30 | archives javadocJar 31 | archives sourcesJar 32 | } 33 | 34 | javadoc { 35 | failOnError false 36 | options { 37 | encoding "UTF-8" 38 | charSet 'UTF-8' 39 | author true 40 | version true 41 | links "http://docs.oracle.com/javase/7/docs/api" 42 | } 43 | } 44 | 45 | // Bintray 46 | Properties properties = new Properties() 47 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 48 | 49 | bintray { 50 | user = properties.getProperty("bintray.user") 51 | key = properties.getProperty("bintray.apikey") 52 | 53 | configurations = ['archives'] 54 | pkg { 55 | repo = "maven" 56 | name = bintrayName 57 | desc = libraryDescription 58 | websiteUrl = siteUrl 59 | vcsUrl = gitUrl 60 | licenses = ["Apache-2.0"] 61 | publish = true 62 | publicDownloadNumbers = true 63 | version { 64 | desc = libraryDescription 65 | gpg { 66 | sign = true //Determines whether to GPG sign the files. The default is false 67 | passphrase = properties.getProperty("bintray.gpg.password") 68 | //Optional. The passphrase for GPG signing' 69 | } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/Converter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import com.xretrofit.utils.Utils; 4 | import com.yanxuwen.xretrofit_annotations.annotation.param.Body; 5 | import com.yanxuwen.xretrofit_annotations.annotation.param.FilePath; 6 | import com.yanxuwen.xretrofit_annotations.annotation.param.Header; 7 | import com.yanxuwen.xretrofit_annotations.annotation.param.Param; 8 | import com.yanxuwen.xretrofit_annotations.annotation.param.Path; 9 | import com.yanxuwen.xretrofit_annotations.annotation.param.Query; 10 | 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | import java.lang.reflect.Type; 14 | 15 | import okhttp3.RequestBody; 16 | import okhttp3.ResponseBody; 17 | 18 | /** 19 | * @author bsnl_yanxuwen 20 | * @date 2021/2/4 14:07 21 | * Description : 22 | * 如果是请求 23 | */ 24 | public interface Converter { 25 | T convert(F value) throws Exception; 26 | 27 | abstract class Factory { 28 | 29 | /** 30 | * 请求转换器,目前只支持{@link Body @Body} 注解 31 | * @param request get post 32 | * @param requestParamType 请求的参数类型 33 | * @return 34 | */ 35 | public @Nullable Converter requestBodyConverter(Type request, Type requestParamType) { 36 | return null; 37 | } 38 | 39 | /** 40 | * 请求转换器 ,支持 41 | * {@link Header @Header} 42 | * {@link Query @Query} 43 | * {@link Path @Path} 44 | * {@link FilePath @FilePath} 45 | * {@link Param @FilePath} 46 | * @param request get post 47 | * @param requestParamType 请求的参数类型 48 | * @return 49 | */ 50 | public @Nullable Converter stringConverter(Type request,Type requestParamType) { 51 | return null; 52 | } 53 | 54 | /** 55 | * 结果转换器 56 | * @param request get post 57 | * @param responseType 结果返回的参数类型 58 | * @return 59 | */ 60 | public @Nullable Converter responseBodyConverter(Type request,Type responseType) { 61 | return null; 62 | } 63 | 64 | protected static Class getRawType(Type type) { 65 | return Utils.getRawType(type); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/Interceptor/UploadRequestBodyBody.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.Interceptor; 2 | 3 | import java.io.IOException; 4 | import java.text.DecimalFormat; 5 | 6 | import okhttp3.MediaType; 7 | import okhttp3.RequestBody; 8 | import okio.Buffer; 9 | import okio.BufferedSink; 10 | import okio.ForwardingSink; 11 | import okio.Okio; 12 | import okio.Sink; 13 | 14 | /** 15 | * 上传 16 | */ 17 | public class UploadRequestBodyBody extends RequestBody { 18 | private RequestBody mRequestBody; 19 | private long mContentLength; 20 | final DecimalFormat df = new DecimalFormat("#.00"); 21 | 22 | private ProgressListener progressListener; 23 | 24 | public void setProgressListener(ProgressListener progressListener) { 25 | this.progressListener = progressListener; 26 | } 27 | 28 | public UploadRequestBodyBody(RequestBody requestBody) { 29 | mRequestBody = requestBody; 30 | } 31 | 32 | //文件的总长度 33 | @Override 34 | public long contentLength() { 35 | try { 36 | if (mContentLength == 0) 37 | mContentLength = mRequestBody.contentLength(); 38 | return mContentLength; 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | return -1; 43 | } 44 | 45 | @Override 46 | public MediaType contentType() { 47 | return mRequestBody.contentType(); 48 | } 49 | 50 | @Override 51 | public void writeTo(BufferedSink sink) throws IOException { 52 | ByteSink byteSink = new ByteSink(sink); 53 | BufferedSink mBufferedSink = Okio.buffer(byteSink); 54 | mRequestBody.writeTo(mBufferedSink); 55 | mBufferedSink.flush(); 56 | } 57 | 58 | 59 | private final class ByteSink extends ForwardingSink { 60 | //已经上传的长度 61 | private long mByteLength = 0L; 62 | 63 | ByteSink(Sink delegate) { 64 | super(delegate); 65 | } 66 | 67 | @Override 68 | public void write(Buffer source, long byteCount) throws IOException { 69 | super.write(source, byteCount); 70 | mByteLength += byteCount; 71 | if (progressListener != null){ 72 | progressListener.setProgress(Float.valueOf(df.format((Float.valueOf(mByteLength) / contentLength()) * 100))); 73 | } 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /XRetrofit/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/Interceptor/DownloadResponseBody.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.Interceptor; 2 | 3 | 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.text.DecimalFormat; 7 | 8 | import okhttp3.MediaType; 9 | import okhttp3.Response; 10 | import okhttp3.ResponseBody; 11 | import okio.Buffer; 12 | import okio.BufferedSource; 13 | import okio.ForwardingSource; 14 | import okio.Okio; 15 | 16 | /** 17 | * 下载 18 | */ 19 | public class DownloadResponseBody extends ResponseBody { 20 | 21 | private Response originalResponse; 22 | private long startsPoint = 0; 23 | private long maxProgress = 0; 24 | private File file; 25 | DecimalFormat df = new DecimalFormat("#.00"); 26 | 27 | private ProgressListener progressListener; 28 | 29 | public void setProgressListener(ProgressListener progressListener) { 30 | this.progressListener = progressListener; 31 | } 32 | 33 | public DownloadResponseBody(Response originalResponse, long startsPoint, File file) { 34 | this.originalResponse = originalResponse; 35 | this.startsPoint = startsPoint; 36 | this.file = file; 37 | } 38 | 39 | @Override 40 | public MediaType contentType() { 41 | return originalResponse.body().contentType(); 42 | } 43 | 44 | @Override 45 | public long contentLength() { 46 | return originalResponse.body().contentLength(); 47 | } 48 | 49 | public void setMaxProgress(long maxProgress) { 50 | this.maxProgress = maxProgress; 51 | } 52 | 53 | @Override 54 | public BufferedSource source() { 55 | return Okio.buffer(new ForwardingSource(originalResponse.body().source()) { 56 | private long bytesReaded = 0; 57 | 58 | @Override 59 | public long read(Buffer sink, long byteCount) throws IOException { 60 | long bytesRead = super.read(sink, byteCount); 61 | bytesReaded += bytesRead == -1 ? 0 : bytesRead; 62 | if (progressListener != null) { 63 | progressListener.setProgress(Float.valueOf(df.format((Float.valueOf(bytesReaded+startsPoint) / maxProgress) * 100))); 64 | } 65 | return bytesRead; 66 | } 67 | }); 68 | } 69 | 70 | public File getFile() { 71 | return file; 72 | } 73 | 74 | public void setFile(File file) { 75 | this.file = file; 76 | } 77 | 78 | public long getStartsPoint() { 79 | return startsPoint; 80 | } 81 | } -------------------------------------------------------------------------------- /XRetrofit/xretrofit/src/main/java/com/xretrofit/converter/DownloadResponseConverter.java: -------------------------------------------------------------------------------- 1 | package com.xretrofit.converter; 2 | 3 | import com.xretrofit.Interceptor.DownloadResponseBody; 4 | 5 | import java.io.BufferedInputStream; 6 | import java.io.InputStream; 7 | import java.io.RandomAccessFile; 8 | 9 | import okhttp3.ResponseBody; 10 | 11 | /** 12 | * @author bsnl_yanxuwen 13 | * @date 2021/2/4 17:09 14 | * Description : 15 | * 接口数据转换 16 | * 返回接口的 下载操作 17 | */ 18 | public class DownloadResponseConverter implements Converter { 19 | 20 | @Override 21 | public T convert(ResponseBody value) throws Exception { 22 | 23 | DownloadResponseBody responseBody = null; 24 | if (value instanceof DownloadResponseBody) { 25 | responseBody = (DownloadResponseBody) value; 26 | } 27 | if (responseBody == null) { 28 | return null; 29 | } 30 | long length = responseBody.contentLength(); 31 | if (length == 0 || length == 1) { 32 | // 说明文件已经下载完,直接跳转安装就好 33 | return (T) String.valueOf(responseBody.getFile().getAbsoluteFile()); 34 | } 35 | if (responseBody instanceof DownloadResponseBody) { 36 | responseBody.setMaxProgress(length + responseBody.getStartsPoint()); 37 | } 38 | // 保存文件到本地 39 | InputStream is = null; 40 | RandomAccessFile randomAccessFile = null; 41 | BufferedInputStream bis = null; 42 | 43 | byte[] buff = new byte[2048]; 44 | int len = 0; 45 | try { 46 | is = responseBody.byteStream(); 47 | bis = new BufferedInputStream(is); 48 | 49 | // 随机访问文件,可以指定断点续传的起始位置 50 | randomAccessFile = new RandomAccessFile(responseBody.getFile(), "rwd"); 51 | randomAccessFile.seek( responseBody.getStartsPoint()); 52 | while ((len = bis.read(buff)) != -1) { 53 | randomAccessFile.write(buff, 0, len); 54 | } 55 | 56 | // 下载完成 57 | return (T) String.valueOf(responseBody.getFile().getAbsoluteFile()); 58 | } catch (Exception e) { 59 | // postUIFail(e, requestParams); 60 | } finally { 61 | try { 62 | if (is != null) { 63 | is.close(); 64 | } 65 | if (bis != null) { 66 | bis.close(); 67 | } 68 | if (randomAccessFile != null) { 69 | randomAccessFile.close(); 70 | } 71 | } catch (Exception e) { 72 | 73 | } 74 | } 75 | return null; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /XRetrofit/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 |