refactor(frame): 调整项目结构
移除buildGradleScript、lib_net模块,将网络层迁移至lib_common层 升级Gradle版本及
This commit is contained in:
@@ -7,7 +7,7 @@ import android.util.Log
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.google.auto.service.AutoService
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.ApplicationLifecycle
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.BaseApplication
|
||||
import com.quyunshuo.androidbaseframemvvm.base.BaseApplication
|
||||
import com.quyunshuo.androidbaseframemvvm.base.app.InitDepend
|
||||
import com.quyunshuo.androidbaseframemvvm.base.constant.VersionStatus
|
||||
import com.quyunshuo.androidbaseframemvvm.base.utils.ProcessUtils
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.constant
|
||||
|
||||
/**
|
||||
* 接口公共地址
|
||||
*
|
||||
* @author Qu Yunshuo
|
||||
* @since 4/17/21 3:27 PM
|
||||
*/
|
||||
internal object NetBaseUrlConstant {
|
||||
|
||||
val MAIN_URL = "http://www.baidu.com"
|
||||
get() {
|
||||
if (field.isEmpty()){
|
||||
throw NotImplementedError("请求改你的 MAIN_URL 的值为自己的请求地址")
|
||||
}
|
||||
return field
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.quyunshuo.androidbaseframemvvm.common.di
|
||||
|
||||
import com.quyunshuo.androidbaseframemvvm.base.BuildConfig
|
||||
import com.quyunshuo.androidbaseframemvvm.common.constant.NetBaseUrlConstant
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import java.util.concurrent.TimeUnit
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level.NONE
|
||||
import okhttp3.logging.HttpLoggingInterceptor.Level.BODY
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* 全局作用域的网络层的依赖注入模块
|
||||
*
|
||||
* @author Qu Yunshuo
|
||||
* @since 6/4/21 8:58 AM
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class DINetworkModule {
|
||||
|
||||
/**
|
||||
* [OkHttpClient]依赖提供方法
|
||||
*
|
||||
* @return OkHttpClient
|
||||
*/
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideOkHttpClient(): OkHttpClient {
|
||||
// 日志拦截器部分
|
||||
val level = if (BuildConfig.DEBUG) BODY else NONE
|
||||
val logInterceptor = HttpLoggingInterceptor().setLevel(level)
|
||||
|
||||
return OkHttpClient.Builder()
|
||||
.connectTimeout(15L * 1000L, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(20L * 1000L, TimeUnit.MILLISECONDS)
|
||||
.addInterceptor(logInterceptor)
|
||||
.retryOnConnectionFailure(true)
|
||||
.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目主要服务器地址的[Retrofit]依赖提供方法
|
||||
*
|
||||
* @param okHttpClient OkHttpClient OkHttp客户端
|
||||
* @return Retrofit
|
||||
*/
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideMainRetrofit(okHttpClient: OkHttpClient): Retrofit {
|
||||
return Retrofit.Builder()
|
||||
.baseUrl(NetBaseUrlConstant.MAIN_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(okHttpClient)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user