Skip to content

Commit

Permalink
更新了 retrofit 添加其他解析器 和适配器的逻辑
Browse files Browse the repository at this point in the history
取消了 混淆
  • Loading branch information
JiangHaiYang01 committed May 28, 2020
1 parent 9d42d16 commit 9342266
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

//编译配置
apply from: '../config_compile.gradle'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
Expand Down Expand Up @@ -33,23 +34,21 @@ android {
}



}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'



implementation project(":lib_http-coroutine")

// implementation(name: 'lib_http-coroutine-release', ext: 'aar')

//==========================================================================================
// 协程
Expand All @@ -67,4 +66,8 @@ dependencies {

//文件选择框架
implementation 'me.rosuh:AndroidFilePicker:0.6.1'


implementation 'com.squareup.retrofit2:converter-gson:2.8.2'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.8.2'
}
Binary file added app/libs/lib_http-coroutine-release.aar
Binary file not shown.
5 changes: 4 additions & 1 deletion app/src/main/java/com/allens/rxhttp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.allens.lib_http2.config.HttpLevel
import com.allens.lib_http2.impl.OnBuildClientListener
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {

Expand All @@ -29,7 +31,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
.readTimeout(10)
.connectTimeout(10)
.addBuilderClientListener(object : OnBuildClientListener {
override fun addBuildClient(client: retrofit2.Retrofit.Builder) {
override fun addBuildClient(): MutableSet<Any> {
return mutableSetOf(GsonConverterFactory.create(),RxJava2CallAdapterFactory.create())
}
})
.build(this)
Expand Down
15 changes: 14 additions & 1 deletion lib_http-coroutine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@ apply plugin: 'kotlin-android-extensions'
//本地依赖
apply from: 'config.gradle'
//编译配置
apply from: '../config_compile.gradle'
apply from: '../config_compile.gradle'

android{
//==========================================================================================
// lib 模块是否开启自定义的混淆
//==========================================================================================
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}
2 changes: 1 addition & 1 deletion lib_http-coroutine/config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ext {

implementation 'com.google.code.gson:gson:2.8.6'
//retrofit
api"com.squareup.retrofit2:retrofit:2.8.2"
implementation "com.squareup.retrofit2:retrofit:2.8.2"
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.allens.lib_http2.impl

import retrofit2.Retrofit
import java.util.prefs.PreferencesFactory

interface OnBuildClientListener {

fun addBuildClient(client: Retrofit.Builder)
fun addBuildClient(): MutableSet<Any>

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ package com.allens.lib_http2.manager

import android.content.Context
import android.os.Environment
import com.allens.lib_http2.RxHttp
import com.allens.lib_http2.config.HttpConfig
import com.allens.lib_http2.config.HttpNetWorkType
import com.allens.lib_http2.interceptor.*
import com.allens.lib_http2.interceptor.CacheInterceptor
import com.allens.lib_http2.interceptor.CacheNetworkInterceptor
import com.allens.lib_http2.tools.RxHttpLogTool
import com.franmontiel.persistentcookiejar.PersistentCookieJar
import com.franmontiel.persistentcookiejar.cache.SetCookieCache
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor
import com.google.gson.Gson
import okhttp3.Cache
import okhttp3.OkHttpClient
import retrofit2.CallAdapter
import retrofit2.Converter
import retrofit2.Retrofit
import java.io.File
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -111,7 +115,31 @@ object HttpManager {
private fun createRetrofit(): Retrofit {
val client = retrofitBuilder
.client(okHttpBuilder.build())
HttpConfig.onBuildClientListener?.addBuildClient(client)

val set = HttpConfig.onBuildClientListener?.addBuildClient()
RxHttpLogTool.i(RxHttp.TAG, "factory size ${set?.size}")
set?.forEach {
try {
when (it) {
is Converter.Factory -> {
client.addConverterFactory(it)
RxHttpLogTool.i(RxHttp.TAG, "addConverterFactory $it")
}
is CallAdapter.Factory -> {
client.addCallAdapterFactory(it)
RxHttpLogTool.i(RxHttp.TAG, "addCallAdapterFactory $it")
}
else -> {
RxHttpLogTool.i(
RxHttp.TAG,
"factory is not Converter.Factory or CallAdapter.Factory, please check "
)
}
}
} catch (throwable: Throwable) {
RxHttpLogTool.i(RxHttp.TAG, "add factory failed ${throwable.message}")
}
}
return client
.baseUrl(HttpConfig.baseUrl)
.build()
Expand Down

0 comments on commit 9342266

Please sign in to comment.