├── RxHttp ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ └── values │ │ │ └── strings.xml │ │ └── java │ │ └── io │ │ └── github │ │ └── kongpf8848 │ │ └── rxhttp │ │ ├── callback │ │ ├── ProgressCallback.kt │ │ ├── DownloadCallback.kt │ │ └── HttpCallback.kt │ │ ├── typebuilder │ │ ├── exception │ │ │ └── TypeException.kt │ │ ├── TypeToken.kt │ │ ├── TypeBuilder.kt │ │ └── typeimpl │ │ │ └── ParameterizedTypeImpl.kt │ │ ├── converter │ │ ├── IConverter.kt │ │ ├── GsonConverter.kt │ │ └── DownloadConverter.kt │ │ ├── request │ │ ├── PutRequest.kt │ │ ├── DeleteRequest.kt │ │ ├── GetRequest.kt │ │ ├── PostFormRequest.kt │ │ ├── DownloadRequest.kt │ │ ├── PostRequest.kt │ │ ├── AbsRequest.kt │ │ └── UploadRequest.kt │ │ ├── bean │ │ └── DownloadInfo.kt │ │ ├── util │ │ ├── TypeUtil.kt │ │ ├── GsonUtil.kt │ │ ├── Md5Util.kt │ │ └── SSLUtil.kt │ │ ├── interceptors │ │ ├── CurlLoggingInterceptor.kt │ │ └── GzipRequestInterceptor.kt │ │ ├── HttpConstants.kt │ │ ├── ByteArrayRequestBody.kt │ │ ├── RetryWithDelay.kt │ │ ├── curl │ │ ├── CurlPrinter.kt │ │ └── CurlCommandParser.kt │ │ ├── utf8.kt │ │ ├── RxHttpTagManager.kt │ │ ├── Platform.kt │ │ ├── HttpObserver.kt │ │ ├── ProgressRequestBody.kt │ │ ├── ProgressResponseBody.kt │ │ ├── HttpService.kt │ │ ├── RxHttpConfig.kt │ │ └── RxHttp.kt ├── proguard-rules.pro └── build.gradle ├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── 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 │ │ │ ├── avatar_default.png │ │ │ ├── cover_default.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── xml │ │ │ ├── file_paths.xml │ │ │ └── network_security_config.xml │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── styles.xml │ │ │ └── strings.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ ├── activity_zhihu.xml │ │ │ ├── activity_glide.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_mvc.xml │ │ │ └── activity_mvvm.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── kongpf8848 │ │ │ └── rxhttp │ │ │ └── sample │ │ │ ├── http │ │ │ ├── TKEmpty.kt │ │ │ ├── exception │ │ │ │ ├── NullResponseException.kt │ │ │ │ └── ServerException.kt │ │ │ ├── TKResponse.kt │ │ │ ├── TKURL.kt │ │ │ ├── interceptor │ │ │ │ └── MockInterceptor.kt │ │ │ └── TKErrorCode.kt │ │ │ ├── bean │ │ │ ├── User.kt │ │ │ ├── Banner.kt │ │ │ └── Feed.kt │ │ │ ├── utils │ │ │ ├── GsonUtils.kt │ │ │ ├── MockUtils.kt │ │ │ ├── ApkUtils.kt │ │ │ ├── AssetUtils.kt │ │ │ └── LogUtils.kt │ │ │ ├── mvvm │ │ │ ├── BaseViewModel.kt │ │ │ ├── MvvmHttpCallback.kt │ │ │ ├── IBaseMvvm.kt │ │ │ ├── BaseMvvmActivity.kt │ │ │ ├── BaseMvvmFragment.kt │ │ │ ├── TKState.kt │ │ │ └── NetworkRepository.kt │ │ │ ├── extension │ │ │ ├── ActivityExtension.kt │ │ │ └── LiveDataExtension.kt │ │ │ ├── image │ │ │ ├── OkHttpGlideModule.kt │ │ │ └── transfrom │ │ │ │ └── RoundCornerTransform.java │ │ │ ├── activity │ │ │ ├── GlideActivity.kt │ │ │ ├── MainActivity.kt │ │ │ ├── ZhiHuActivity.kt │ │ │ ├── ZhiHuJavaActivity.java │ │ │ ├── MVVMActivity.kt │ │ │ └── MVCActivity.kt │ │ │ ├── mvc │ │ │ ├── MVCHttpCallback.kt │ │ │ └── MVCApi.kt │ │ │ ├── base │ │ │ ├── BaseActivity.kt │ │ │ └── BaseFragment.kt │ │ │ ├── MyApplication.kt │ │ │ ├── viewmodel │ │ │ └── MainViewModel.kt │ │ │ └── service │ │ │ └── DownloadService.kt │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── gradle-mvn-push.gradle ├── .idea ├── encodings.xml ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── vcs.xml ├── compiler.xml ├── kotlinc.xml ├── AndroidProjectSystem.xml ├── migrations.xml ├── deploymentTargetSelector.xml ├── misc.xml ├── runConfigurations.xml ├── gradle.xml ├── jarRepositories.xml ├── appInsightsSettings.xml ├── markdown-navigator-enh.xml └── markdown-navigator.xml ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /RxHttp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name="RxHttp" 2 | include ':app', ':RxHttp' 3 | -------------------------------------------------------------------------------- /RxHttp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /RxHttp/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RxHttp 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/http/TKEmpty.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.http 2 | 3 | class TKEmpty { 4 | } -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/avatar_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxhdpi/avatar_default.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/cover_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxhdpi/cover_default.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kongpf8848/RxHttp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/bean/User.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.bean 2 | 3 | data class User(var uuid: String, var name: String? = null,var address:String?=null) -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/xml/file_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/callback/ProgressCallback.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.callback 2 | 3 | interface ProgressCallback { 4 | fun onProgress(readBytes: Long, totalBytes: Long) 5 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/typebuilder/exception/TypeException.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.typebuilder.exception 2 | 3 | class TypeException(message: String?) : RuntimeException(message) -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/http/exception/NullResponseException.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.http.exception 2 | 3 | class NullResponseException(val code: Int, val msg: String?) : RuntimeException(msg) -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/http/exception/ServerException.kt: -------------------------------------------------------------------------------- 1 | package com.jsy.tk.library.http.exception 2 | 3 | /** 4 | * 服务器返回的异常 5 | */ 6 | class ServerException(val code: Int, val msg: String?) : RuntimeException(msg) -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/callback/DownloadCallback.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.callback 2 | 3 | import io.github.kongpf8848.rxhttp.bean.DownloadInfo 4 | 5 | abstract class DownloadCallback : HttpCallback() -------------------------------------------------------------------------------- /.idea/AndroidProjectSystem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | /buildSrc/build/ 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Jun 30 10:32:38 GMT+08:00 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-8.9-all.zip 7 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/converter/IConverter.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.converter 2 | 3 | import okhttp3.ResponseBody 4 | import java.lang.reflect.Type 5 | 6 | interface IConverter { 7 | @Throws(Exception::class) 8 | fun convert(body: ResponseBody, type: Type): T 9 | } -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/bean/Banner.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.bean 2 | 3 | import java.io.Serializable 4 | 5 | data class Banner( 6 | var id: Int, 7 | var pic: String, 8 | var url: String, 9 | var title: String? = null 10 | ) : Serializable 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/http/TKResponse.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.http 2 | 3 | import java.io.Serializable 4 | 5 | class TKResponse(val code:Int,val msg: String?, val data: T?) : Serializable { 6 | companion object{ 7 | const val STATUS_OK=200 8 | } 9 | fun isSuccess():Boolean{ 10 | return code== STATUS_OK 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/xml/network_security_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/request/PutRequest.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.request 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import androidx.fragment.app.Fragment 6 | 7 | class PutRequest : PostRequest { 8 | constructor(context: Context) : super(context) 9 | constructor(activity: Activity) : super(activity) 10 | constructor(fragment: Fragment) : super(fragment) 11 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/bean/DownloadInfo.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.bean 2 | 3 | import java.io.Serializable 4 | 5 | class DownloadInfo(var url: String, var dir: String, var fileName: String,var total: Long = 0, var progress: Long = 0):Serializable { 6 | 7 | override fun toString(): String { 8 | return "DownloadInfo(url='$url', dir='$dir', fileName='$fileName', total=$total, progress=$progress)" 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/utils/GsonUtils.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.utils 2 | 3 | import android.text.TextUtils 4 | import com.google.gson.Gson 5 | 6 | object GsonUtils { 7 | 8 | private val gson = Gson() 9 | 10 | fun toJson(obj: Any?): String { 11 | var gsonString = "" 12 | if (obj != null && !TextUtils.isEmpty(obj.toString())) { 13 | gsonString = gson.toJson(obj) 14 | } 15 | return gsonString 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/deploymentTargetSelector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/mvvm/BaseViewModel.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.mvvm 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import androidx.lifecycle.AndroidViewModel 6 | 7 | /** 8 | * MVVM架构ViewModel基类 9 | */ 10 | open class BaseViewModel(application: Application) : AndroidViewModel(application) { 11 | 12 | protected val networkbaseRepository: NetworkRepository = NetworkRepository.instance 13 | protected var context: Context = application.applicationContext 14 | 15 | 16 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/request/DeleteRequest.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.request 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import androidx.fragment.app.Fragment 6 | import okhttp3.RequestBody 7 | 8 | class DeleteRequest : AbsRequest { 9 | constructor(context: Context) : super(context) 10 | constructor(fragment: Fragment) : super(fragment) 11 | constructor(activity: Activity) : super(activity) 12 | 13 | override fun buildRequestBody(): RequestBody? { 14 | return null 15 | } 16 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/util/TypeUtil.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.util 2 | 3 | import java.lang.reflect.ParameterizedType 4 | import java.lang.reflect.Type 5 | 6 | object TypeUtil { 7 | 8 | fun getType(subclass: Class<*>): Type { 9 | val superclass = subclass.genericSuperclass 10 | return if (superclass is Class<*>) { 11 | subclass 12 | } else { 13 | val parameterized = superclass as ParameterizedType 14 | parameterized.actualTypeArguments[0] 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/interceptors/CurlLoggingInterceptor.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.interceptors 2 | 3 | import io.github.kongpf8848.rxhttp.curl.CurlCommandParser 4 | import okhttp3.Interceptor 5 | import okhttp3.Response 6 | 7 | class CurlLoggingInterceptor(var tag: String? = null) : Interceptor { 8 | 9 | override fun intercept(chain: Interceptor.Chain): Response { 10 | val request = chain.request() 11 | CurlCommandParser(tag).parse(request) 12 | return chain.proceed(request) 13 | } 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/request/GetRequest.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.request 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import androidx.fragment.app.Fragment 6 | import okhttp3.RequestBody 7 | 8 | class GetRequest : AbsRequest { 9 | constructor(context: Context) : super(context) 10 | constructor(activity: Activity) : super(activity) 11 | constructor(fragment: Fragment) : super(fragment) 12 | 13 | public override fun buildRequestBody(): RequestBody? { 14 | return null 15 | } 16 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/request/PostFormRequest.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.request 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import androidx.fragment.app.Fragment 6 | import okhttp3.RequestBody 7 | 8 | class PostFormRequest : AbsRequest { 9 | constructor(context: Context) : super(context) 10 | constructor(activity: Activity) : super(activity) 11 | constructor(fragment: Fragment) : super(fragment) 12 | 13 | public override fun buildRequestBody(): RequestBody? { 14 | return null 15 | } 16 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/util/GsonUtil.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.util 2 | 3 | import android.text.TextUtils 4 | import com.google.gson.Gson 5 | import java.lang.reflect.Type 6 | 7 | object GsonUtil { 8 | 9 | private val gson = Gson() 10 | 11 | fun toJson(obj: Any?): String { 12 | var gsonString = "" 13 | if (obj != null && !TextUtils.isEmpty(obj.toString())) { 14 | gsonString = gson.toJson(obj) 15 | } 16 | return gsonString 17 | } 18 | 19 | fun fromJson(str:String,type: Type):T=gson.fromJson(str,type) 20 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/typebuilder/TypeToken.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.typebuilder 2 | 3 | import io.github.kongpf8848.rxhttp.typebuilder.exception.TypeException 4 | import java.lang.reflect.ParameterizedType 5 | import java.lang.reflect.Type 6 | 7 | abstract class TypeToken { 8 | 9 | val type: Type 10 | 11 | init { 12 | val superclass = javaClass.genericSuperclass 13 | if (superclass is Class<*>) { 14 | throw TypeException("No generics found!") 15 | } 16 | val type = superclass as ParameterizedType 17 | this.type = type.actualTypeArguments[0] 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/extension/ActivityExtension.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.extension 2 | 3 | import android.net.Uri 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.result.ActivityResultCallback 6 | import androidx.activity.result.contract.ActivityResultContracts 7 | 8 | 9 | /** 10 | * 获取内容 11 | */ 12 | fun ComponentActivity.getContent(input: String, callback: ((uri: Uri) -> Unit)? = null) { 13 | registerForActivityResult(ActivityResultContracts.GetContent(), ActivityResultCallback { 14 | if (it != null && it.toString().isNotEmpty()) { 15 | callback?.invoke(it) 16 | } 17 | }).launch(input) 18 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/extension/LiveDataExtension.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.extension 2 | 3 | import androidx.lifecycle.LifecycleOwner 4 | import androidx.lifecycle.LiveData 5 | import androidx.lifecycle.Observer 6 | import io.github.kongpf8848.rxhttp.sample.mvvm.TKState 7 | 8 | fun LiveData>.observeState(lifecycleOwner: LifecycleOwner, callback: TKState.HandleCallback.() -> Unit) { 9 | this.observe(lifecycleOwner, Observer { 10 | it.handle(callback) 11 | }) 12 | } 13 | 14 | fun LiveData>.observeStateForever(callback: TKState.HandleCallback.() -> Unit) { 15 | this.observeForever { 16 | it.handle(callback) 17 | } 18 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/HttpConstants.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp 2 | 3 | object HttpConstants { 4 | const val TIME_OUT = 60L 5 | const val MIME_TYPE_BINARY = "application/octet-stream" 6 | const val MIME_TYPE_TEXT = "text/plain; charset=utf-8" 7 | const val MIME_TYPE_JSON = "application/json; charset=utf-8" 8 | const val MIME_TYPE_PROTOBUF = "application/x-protobuf" 9 | const val MIME_TYPE_APK = "application/vnd.android.package-archive" 10 | const val MIME_TYPE_JPG = "image/jpeg" 11 | const val MIME_TYPE_PNG = "image/png" 12 | const val TEXT_PLAIN="text/plain" 13 | const val APPLICATION_JSON="application/json" 14 | const val APPLICATION_XML="application/xml" 15 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/mvvm/MvvmHttpCallback.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.mvvm 2 | 3 | import io.github.kongpf8848.rxhttp.sample.http.TKResponse 4 | import io.github.kongpf8848.rxhttp.typebuilder.TypeBuilder 5 | import io.github.kongpf8848.rxhttp.util.TypeUtil 6 | import java.lang.reflect.Type 7 | 8 | abstract class MvvmHttpCallback() { 9 | 10 | private val type: Type 11 | init { 12 | val arg = TypeUtil.getType(javaClass) 13 | type = TypeBuilder 14 | .newInstance(TKResponse::class.java) 15 | .addTypeParam(arg) 16 | .build() 17 | } 18 | 19 | fun getType(): Type { 20 | return this.type 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/ByteArrayRequestBody.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp 2 | 3 | import okhttp3.MediaType 4 | import okhttp3.RequestBody 5 | import okio.BufferedSink 6 | import java.io.IOException 7 | 8 | class ByteArrayRequestBody(private val contentType: MediaType?, private val byteArray: ByteArray) : RequestBody() { 9 | override fun contentType(): MediaType? { 10 | return contentType 11 | } 12 | 13 | @Throws(IOException::class) 14 | override fun contentLength(): Long { 15 | return byteArray.size.toLong() 16 | } 17 | 18 | @Throws(IOException::class) 19 | override fun writeTo(sink: BufferedSink) { 20 | sink.write(byteArray, 0, byteArray.size) 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/converter/GsonConverter.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.converter 2 | 3 | import com.google.gson.JsonSyntaxException 4 | import io.github.kongpf8848.rxhttp.util.GsonUtil 5 | import okhttp3.ResponseBody 6 | import java.lang.reflect.Type 7 | 8 | class GsonConverter : IConverter { 9 | 10 | @Throws(Exception::class) 11 | override fun convert(body: ResponseBody, type: Type): T { 12 | var response: T? = null 13 | val result = body.string() 14 | body.close() 15 | try { 16 | response = GsonUtil.fromJson(result,type) as T 17 | } catch (e: JsonSyntaxException) { 18 | e.printStackTrace() 19 | throw e 20 | } 21 | 22 | return response 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/http/TKURL.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.http 2 | 3 | object TKURL { 4 | 5 | const val BASE_URL_LOCAL = "http://192.168.12.155:8080/webtest/" 6 | const val URL_GET = BASE_URL_LOCAL + "testGet" 7 | const val URL_POST = BASE_URL_LOCAL + "testPost" 8 | const val URL_POST_FORM = BASE_URL_LOCAL + "testPostForm" 9 | const val URL_PUT = BASE_URL_LOCAL + "testPut" 10 | const val URL_DELETE = BASE_URL_LOCAL + "testDelete" 11 | const val URL_UPLOAD = BASE_URL_LOCAL + "testUpload" 12 | const val URL_DOWNLOAD = "http://hbfile.huabanimg.com/android/huaban-android.apk" 13 | const val URL_DOWNLOAD_2 = "http://image.vcapp.cn/image/apk/JuziBrowser_release_1.6.9.1009_100.apk" 14 | const val URL_ZHIHU = "https://news-at.zhihu.com/api/4/stories/latest" 15 | } -------------------------------------------------------------------------------- /RxHttp/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 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/RetryWithDelay.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp 2 | 3 | import io.reactivex.Observable 4 | import io.reactivex.ObservableSource 5 | import io.reactivex.functions.Function 6 | import java.util.concurrent.TimeUnit 7 | 8 | class RetryWithDelay(private val maxRetries: Int, private val retryDelayMillis: Long) : Function, ObservableSource<*>> { 9 | private var retryCount = 0 10 | 11 | @Throws(Exception::class) 12 | override fun apply(throwableObservable: Observable): ObservableSource<*> { 13 | return throwableObservable.flatMap { throwable -> 14 | if (++retryCount <= maxRetries) { 15 | Observable.timer(retryDelayMillis, TimeUnit.MILLISECONDS) 16 | } else Observable.error(throwable) 17 | } 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/curl/CurlPrinter.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.curl 2 | 3 | import android.util.Log 4 | 5 | object CurlPrinter { 6 | 7 | private const val SINGLE_DIVIDER = "────────────────────────────────────────────" 8 | 9 | private const val DEFAULT_TAG = "CURL" 10 | 11 | fun print(tag: String?, url: String, msg: String?) { 12 | val printTag = tag ?: DEFAULT_TAG 13 | val logMsg = StringBuilder("\n") 14 | logMsg.append("\n") 15 | logMsg.append("URL: $url") 16 | logMsg.append("\n") 17 | logMsg.append(SINGLE_DIVIDER) 18 | logMsg.append("\n") 19 | logMsg.append(msg) 20 | logMsg.append("\n") 21 | logMsg.append(SINGLE_DIVIDER) 22 | logMsg.append("\n") 23 | Log.d(printTag, logMsg.toString()) 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /gradle/gradle-mvn-push.gradle: -------------------------------------------------------------------------------- 1 | mavenPublishing { 2 | publishToMavenCentral(true) 3 | 4 | signAllPublications() 5 | 6 | coordinates(GROUP, ARTIFACT_ID, VERSION_NAME) 7 | 8 | pom { 9 | name = POM_NAME 10 | description = POM_DESCRIPTION 11 | inceptionYear = POM_INCEPTION_YEAR 12 | url = POM_URL 13 | licenses { 14 | license { 15 | name = POM_LICENCE_NAME 16 | url = POM_LICENCE_URL 17 | distribution = POM_LICENCE_URL 18 | } 19 | } 20 | developers { 21 | developer { 22 | id = POM_DEVELOPER_ID 23 | name = POM_DEVELOPER_NAME 24 | url = POM_DEVELOPER_URL 25 | } 26 | } 27 | scm { 28 | url = POM_SCM_URL 29 | connection = POM_SCM_CONNECTION 30 | developerConnection = POM_SCM_DEVELOPER_CONNECTION 31 | } 32 | } 33 | } 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/image/OkHttpGlideModule.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.image 2 | 3 | import android.content.Context 4 | import com.bumptech.glide.Glide 5 | import com.bumptech.glide.Registry 6 | import com.bumptech.glide.annotation.GlideModule 7 | import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader 8 | import com.bumptech.glide.load.model.GlideUrl 9 | import com.bumptech.glide.module.AppGlideModule 10 | import io.github.kongpf8848.rxhttp.RxHttp 11 | import java.io.InputStream 12 | 13 | @GlideModule 14 | class OkHttpGlideModule : AppGlideModule() { 15 | override fun registerComponents( 16 | context: Context, 17 | glide: Glide, 18 | registry: Registry 19 | ) { 20 | registry.replace( 21 | GlideUrl::class.java, 22 | InputStream::class.java, 23 | OkHttpUrlLoader.Factory(RxHttp.getInstance().getOkHttpClient()) 24 | ) 25 | } 26 | } -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/callback/HttpCallback.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.callback 2 | 3 | import io.github.kongpf8848.rxhttp.util.TypeUtil 4 | import java.lang.reflect.Type 5 | 6 | abstract class HttpCallback { 7 | 8 | var type: Type 9 | 10 | constructor() { 11 | type = TypeUtil.getType(javaClass) 12 | } 13 | 14 | constructor(type: Type) { 15 | this.type = type 16 | } 17 | 18 | /** 19 | * http请求开始时回调 20 | */ 21 | open fun onStart(){} 22 | 23 | /** 24 | * http请求成功时回调 25 | */ 26 | abstract fun onNext(response: T?) 27 | 28 | /** 29 | * http请求失败时回调 30 | */ 31 | abstract fun onError(e: Throwable?) 32 | 33 | /** 34 | * http请求完成时回调 35 | */ 36 | open fun onComplete(){} 37 | 38 | /** 39 | * 上传下载进度回调 40 | * @param readBytes 41 | * @param totalBytes 42 | */ 43 | open fun onProgress(readBytes: Long, totalBytes: Long){} 44 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/bean/Feed.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.bean 2 | 3 | import java.io.Serializable 4 | 5 | data class Feed( 6 | var date: String, 7 | var stories: List? = null, 8 | var top_stories: List? = null 9 | ) : Serializable 10 | 11 | data class Story( 12 | var id: Long = 0L, 13 | var type: Int = 0, 14 | var title: String? = null, 15 | var url: String? = null, 16 | var images: List? = null, 17 | var hint: String? = null, 18 | var ga_prefix: String? = null, 19 | var image_hue: String? = null 20 | ) : Serializable 21 | 22 | data class TopStory( 23 | var id: Long = 0L, 24 | var type: Int = 0, 25 | var title: String? = null, 26 | var url: String? = null, 27 | var image: String? = null, 28 | var hint: String? = null, 29 | var ga_prefix: String? = null, 30 | var image_hue: String? = null 31 | ) : Serializable -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/utf8.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp 2 | 3 | import okio.Buffer 4 | import java.io.EOFException 5 | 6 | /** 7 | * Returns true if the body in question probably contains human readable text. Uses a small 8 | * sample of code points to detect unicode control characters commonly used in binary file 9 | * signatures. 10 | */ 11 | fun Buffer.isProbablyUtf8(): Boolean { 12 | try { 13 | val prefix = Buffer() 14 | val byteCount = size.coerceAtMost(64) 15 | copyTo(prefix, 0, byteCount) 16 | for (i in 0 until 16) { 17 | if (prefix.exhausted()) { 18 | break 19 | } 20 | val codePoint = prefix.readUtf8CodePoint() 21 | if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { 22 | return false 23 | } 24 | } 25 | return true 26 | } catch (_: EOFException) { 27 | return false // Truncated UTF-8 sequence. 28 | } 29 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /RxHttp/src/main/java/io/github/kongpf8848/rxhttp/util/Md5Util.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.util 2 | 3 | import okio.ByteString.Companion.encodeUtf8 4 | import okio.ByteString.Companion.toByteString 5 | import okio.buffer 6 | import okio.source 7 | import java.io.File 8 | import java.security.MessageDigest 9 | 10 | object Md5Util { 11 | 12 | fun getMD5(str: String) = str.encodeUtf8().md5().hex() 13 | 14 | fun getMD5(file: File?): String? { 15 | var hash: String? = null 16 | if (file == null || !file.exists()) { 17 | return hash 18 | } 19 | val messageDigest = MessageDigest.getInstance("MD5") 20 | file.source().buffer().use { 21 | val buffer = ByteArray(1024) 22 | var len = -1 23 | while (it.read(buffer, 0, buffer.size).also { len = it } != -1) { 24 | messageDigest.update(buffer, 0, len) 25 | } 26 | } 27 | hash = messageDigest.digest().toByteString().hex() 28 | return hash 29 | } 30 | 31 | 32 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/utils/MockUtils.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.utils 2 | 3 | import io.github.kongpf8848.rxhttp.sample.bean.Banner 4 | import io.github.kongpf8848.rxhttp.sample.bean.User 5 | import io.github.kongpf8848.rxhttp.sample.http.TKResponse 6 | import java.util.* 7 | 8 | object MockUtils { 9 | 10 | /** 11 | * 获取轮播图数据 12 | */ 13 | fun getBannerData():String { 14 | val list= listOf( 15 | Banner(1, "http://t8.baidu.com/it/u=198337120,441348595&fm=79&app=86&f=JPEG?w=1280&h=732", "https://www.baidu.com", "我是轮播图_1"), 16 | Banner(2, "http://t8.baidu.com/it/u=1484500186,1503043093&fm=79&app=86&f=JPEG?w=1280&h=853", "https://www.qq.com", "我是轮播图_2") 17 | ) 18 | val response= TKResponse(200,"",list) 19 | return GsonUtils.toJson(response) 20 | } 21 | 22 | /** 23 | * 获取用户信息 24 | */ 25 | fun getUserData():String { 26 | val user= User(UUID.randomUUID().toString(),"feifei","beijing") 27 | val response= TKResponse(200,"",user) 28 | return GsonUtils.toJson(response) 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/kongpf8848/rxhttp/sample/mvvm/IBaseMvvm.kt: -------------------------------------------------------------------------------- 1 | package io.github.kongpf8848.rxhttp.sample.mvvm 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import java.lang.reflect.ParameterizedType 6 | import java.lang.reflect.Type 7 | 8 | interface IBaseMvvm { 9 | 10 | fun findType(type: Type): Type? { 11 | return when (type) { 12 | is ParameterizedType -> type 13 | is Class<*> -> { 14 | findType(type.genericSuperclass) 15 | } 16 | 17 | else -> { 18 | null 19 | } 20 | } 21 | } 22 | 23 | fun getLayoutId(context: Context, type: Type): Int { 24 | val name = type.toString() 25 | .substringAfterLast('.') // 提取类名(如 "MainActivityBinding") 26 | .removeSuffix("Binding") // 移除结尾的 Binding 27 | .replace(Regex("(?<=.)([A-Z])"), "_$1")// 驼峰转下划线(如 "Main_Activity") 28 | .lowercase() 29 | Log.d("JACK88", "name:${name},type:$type") 30 | return context.resources.getIdentifier(name, "layout", context.packageName) 31 | 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_zhihu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 12 | 13 | 14 | 21 | 22 |