feat: 网络
This commit is contained in:
parent
570de3c4e7
commit
4327a8638c
|
|
@ -4,8 +4,6 @@ import android.app.Application
|
|||
import com.yuanxuan.rokid.device.DeviceServiceManager
|
||||
import com.yuanxuan.rokid.network.http.ApiRepository
|
||||
import com.yuanxuan.rokid.network.http.ApiService
|
||||
import com.yuanxuan.rokid.network.http.OkHttpManager
|
||||
import com.yuanxuan.rokid.network.http.RequestApi
|
||||
import com.yuanxuan.rokid.network.http.RetrofitClient
|
||||
import com.yuanxuan.rokid.network.websocket.WebSocketManager
|
||||
|
||||
|
|
@ -37,15 +35,20 @@ object AppDependencies {
|
|||
provider.provideWebSocketManager()
|
||||
}
|
||||
|
||||
val retrofitClient by lazy {
|
||||
provider.provideRetrofitClient()
|
||||
}
|
||||
|
||||
val requestApi by lazy {
|
||||
provider.provideApiRepository(
|
||||
apiService = RetrofitClient.apiService
|
||||
apiService = retrofitClient.apiService
|
||||
)
|
||||
}
|
||||
|
||||
interface Provider {
|
||||
fun provideDeviceServiceManager(): DeviceServiceManager
|
||||
fun provideWebSocketManager(): WebSocketManager
|
||||
fun provideRetrofitClient(): RetrofitClient
|
||||
fun provideApiRepository(apiService: ApiService): ApiRepository
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import com.yuanxuan.rokid.device.DeviceServiceManager
|
|||
import com.yuanxuan.rokid.network.http.ApiRepository
|
||||
import com.yuanxuan.rokid.network.http.ApiService
|
||||
import com.yuanxuan.rokid.network.http.OkHttpManager
|
||||
import com.yuanxuan.rokid.network.http.RequestApi
|
||||
import com.yuanxuan.rokid.network.http.RetrofitClient
|
||||
import com.yuanxuan.rokid.network.websocket.WebSocketManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
|
|
@ -22,6 +22,10 @@ class ApplicationDependencyProvider(val context: Application, val scope: Corouti
|
|||
)
|
||||
}
|
||||
|
||||
override fun provideRetrofitClient(): RetrofitClient {
|
||||
return RetrofitClient()
|
||||
}
|
||||
|
||||
override fun provideApiRepository(apiService: ApiService): ApiRepository {
|
||||
return ApiRepository(
|
||||
apiService = apiService
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package com.yuanxuan.rokid.network.http
|
||||
|
||||
class RequestApi(
|
||||
private val okHttp: OkHttpManager
|
||||
) {
|
||||
|
||||
suspend fun testApi(): Result<Test> {
|
||||
return runCatching {
|
||||
okHttp.testApi()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ import retrofit2.converter.gson.GsonConverterFactory
|
|||
import timber.log.Timber
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
object RetrofitClient {
|
||||
class RetrofitClient {
|
||||
private val okHttpClient: OkHttpClient by lazy {
|
||||
val httpLoggingInterceptor by lazy {
|
||||
HttpLoggingInterceptor { message ->
|
||||
|
|
|
|||
Loading…
Reference in New Issue