|
@@ -21,16 +21,15 @@ import android.app.ProgressDialog
|
|
|
import com.drake.brv.BindingAdapter
|
|
|
import com.drake.net.NetConfig
|
|
|
import com.drake.net.interceptor.LogRecordInterceptor
|
|
|
-import com.drake.net.interceptor.RequestInterceptor
|
|
|
import com.drake.net.okhttp.setConverter
|
|
|
import com.drake.net.okhttp.setDebug
|
|
|
import com.drake.net.okhttp.setDialogFactory
|
|
|
import com.drake.net.okhttp.setRequestInterceptor
|
|
|
-import com.drake.net.request.BaseRequest
|
|
|
import com.drake.net.sample.BR
|
|
|
import com.drake.net.sample.BuildConfig
|
|
|
import com.drake.net.sample.R
|
|
|
import com.drake.net.sample.converter.GsonConverter
|
|
|
+import com.drake.net.sample.interfaces.MyRequestInterceptor
|
|
|
import com.drake.statelayout.StateConfig
|
|
|
import com.scwang.smart.refresh.footer.ClassicsFooter
|
|
|
import com.scwang.smart.refresh.header.MaterialHeader
|
|
@@ -43,23 +42,21 @@ class App : Application() {
|
|
|
override fun onCreate() {
|
|
|
super.onCreate()
|
|
|
|
|
|
- NetConfig.initialize("http://43.128.31.195/") {
|
|
|
+ NetConfig.initialize("http://43.128.31.195/", this) {
|
|
|
|
|
|
// 超时设置
|
|
|
connectTimeout(30, TimeUnit.SECONDS)
|
|
|
readTimeout(30, TimeUnit.SECONDS)
|
|
|
writeTimeout(30, TimeUnit.SECONDS)
|
|
|
|
|
|
- setDebug(BuildConfig.DEBUG) // LogCat异常日志
|
|
|
- addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) // 添加日志记录器
|
|
|
- setRequestInterceptor(object : RequestInterceptor { // 添加请求拦截器
|
|
|
- override fun interceptor(request: BaseRequest) {
|
|
|
- request.addHeader("client", "Net")
|
|
|
- request.setHeader("token", "123456")
|
|
|
- }
|
|
|
- })
|
|
|
+ // 本框架支持Http缓存协议和强制缓存模式
|
|
|
+ cache(Cache(cacheDir, 1024 * 1024 * 128)) // 缓存设置, 当超过maxSize最大值会根据最近最少使用算法清除缓存来限制缓存大小
|
|
|
+
|
|
|
+ setDebug(BuildConfig.DEBUG) // LogCat是否输出异常日志, 异常日志可以快速定位网络请求错误
|
|
|
+
|
|
|
+ addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG)) // 添加日志记录拦截器
|
|
|
+ setRequestInterceptor(MyRequestInterceptor()) // 添加请求拦截器, 可配置全局/动态参数
|
|
|
setConverter(GsonConverter()) // 数据转换器
|
|
|
- cache(Cache(cacheDir, 1024 * 1024 * 128)) // 缓存设置
|
|
|
setDialogFactory { // 全局加载对话框
|
|
|
ProgressDialog(it).apply {
|
|
|
setMessage("我是全局自定义的加载对话框...")
|
|
@@ -67,13 +64,11 @@ class App : Application() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- initDependent()
|
|
|
+ initializeThirdPart()
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 初始化Net的可选附属库
|
|
|
- */
|
|
|
- private fun initDependent() {
|
|
|
+ /** 初始化第三方依赖库库 */
|
|
|
+ private fun initializeThirdPart() {
|
|
|
|
|
|
// 全局缺省页配置 [https://github.com/liangjingkanji/StateLayout]
|
|
|
StateConfig.apply {
|