Modify: 添加网络请求日志拦截器(带UI)
This commit is contained in:
@ -76,4 +76,6 @@ dependencies {
|
||||
kapt GitHub.GlideCompiler
|
||||
kapt GitHub.ARouteCompiler
|
||||
kapt GitHub.EventBusAPT
|
||||
|
||||
debugImplementation GitHub.Chuck
|
||||
}
|
||||
@ -15,8 +15,14 @@ import com.tencent.bugly.crashreport.CrashReport
|
||||
*/
|
||||
open class BaseApplication : Application() {
|
||||
|
||||
companion object {
|
||||
// 全局Context
|
||||
lateinit var context: Context
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
context = applicationContext
|
||||
initialize()
|
||||
}
|
||||
|
||||
|
||||
@ -44,4 +44,6 @@ dependencies {
|
||||
kapt GitHub.GlideCompiler
|
||||
kapt GitHub.ARouteCompiler
|
||||
kapt GitHub.EventBusAPT
|
||||
|
||||
debugImplementation GitHub.Chuck
|
||||
}
|
||||
@ -1,7 +1,9 @@
|
||||
package com.quyunshuo.common.net
|
||||
|
||||
import com.quyunshuo.base.BaseApplication
|
||||
import com.quyunshuo.base.BuildConfig
|
||||
import com.quyunshuo.common.constant.NetUrl
|
||||
import com.readystatesoftware.chuck.ChuckInterceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
@ -32,10 +34,11 @@ object NetServiceCreator {
|
||||
|
||||
private val okHttpClient by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
OkHttpClient.Builder()
|
||||
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS) // 连接超时
|
||||
.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS) // 读取超时
|
||||
.addInterceptor(if (BuildConfig.DEBUG) BODY else NONE) // 请求日志拦截器
|
||||
.retryOnConnectionFailure(true) // 失败重连
|
||||
.connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS) // 连接超时
|
||||
.readTimeout(READ_TIME_OUT, TimeUnit.SECONDS) // 读取超时
|
||||
.addInterceptor(if (BuildConfig.DEBUG) BODY else NONE) // 请求日志拦截器
|
||||
.addInterceptor(ChuckInterceptor(BaseApplication.context)) // 请求日志拦截器(UI)
|
||||
.retryOnConnectionFailure(true) // 失败重连
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
note: 1. 测试打包脚本
|
||||
2. 对比开源项目flow的封装
|
||||
3. 网络请求库
|
||||
|
||||
资源文件相关{
|
||||
资源相关文件属于项目相关的,因此需要放在Common组件内,不要放在Base组件里
|
||||
|
||||
@ -43,6 +43,7 @@ object Version {
|
||||
const val Bugly = "3.2.33" // Bugly 异常上报
|
||||
const val PermissionX = "1.3.0" // 权限申请
|
||||
const val LeakCanary = "2.4" // 检测内存泄漏
|
||||
const val Chuck = "1.1.0" // OkHttp 请求信息拦截器(UI)
|
||||
}
|
||||
|
||||
object AndroidX {
|
||||
@ -100,4 +101,5 @@ object GitHub {
|
||||
const val Bugly = "com.tencent.bugly:crashreport:${Version.Bugly}"
|
||||
const val PermissionX = "com.permissionx.guolindev:permissionx:${Version.PermissionX}"
|
||||
const val LeakCanary = "com.squareup.leakcanary:leakcanary-android:${Version.LeakCanary}"
|
||||
const val Chuck = "com.readystatesoftware.chuck:library:${Version.Chuck}"
|
||||
}
|
||||
@ -79,4 +79,5 @@ dependencies {
|
||||
kapt GitHub.GlideCompiler
|
||||
kapt GitHub.ARouteCompiler
|
||||
kapt GitHub.EventBusAPT
|
||||
debugImplementation GitHub.Chuck
|
||||
}
|
||||
Reference in New Issue
Block a user