feat: 网络
This commit is contained in:
@@ -4,8 +4,6 @@ import android.app.Application
|
|||||||
import com.yuanxuan.rokid.device.DeviceServiceManager
|
import com.yuanxuan.rokid.device.DeviceServiceManager
|
||||||
import com.yuanxuan.rokid.network.http.ApiRepository
|
import com.yuanxuan.rokid.network.http.ApiRepository
|
||||||
import com.yuanxuan.rokid.network.http.ApiService
|
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.http.RetrofitClient
|
||||||
import com.yuanxuan.rokid.network.websocket.WebSocketManager
|
import com.yuanxuan.rokid.network.websocket.WebSocketManager
|
||||||
|
|
||||||
@@ -37,15 +35,20 @@ object AppDependencies {
|
|||||||
provider.provideWebSocketManager()
|
provider.provideWebSocketManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val retrofitClient by lazy {
|
||||||
|
provider.provideRetrofitClient()
|
||||||
|
}
|
||||||
|
|
||||||
val requestApi by lazy {
|
val requestApi by lazy {
|
||||||
provider.provideApiRepository(
|
provider.provideApiRepository(
|
||||||
apiService = RetrofitClient.apiService
|
apiService = retrofitClient.apiService
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Provider {
|
interface Provider {
|
||||||
fun provideDeviceServiceManager(): DeviceServiceManager
|
fun provideDeviceServiceManager(): DeviceServiceManager
|
||||||
fun provideWebSocketManager(): WebSocketManager
|
fun provideWebSocketManager(): WebSocketManager
|
||||||
|
fun provideRetrofitClient(): RetrofitClient
|
||||||
fun provideApiRepository(apiService: ApiService): ApiRepository
|
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.ApiRepository
|
||||||
import com.yuanxuan.rokid.network.http.ApiService
|
import com.yuanxuan.rokid.network.http.ApiService
|
||||||
import com.yuanxuan.rokid.network.http.OkHttpManager
|
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 com.yuanxuan.rokid.network.websocket.WebSocketManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
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 {
|
override fun provideApiRepository(apiService: ApiService): ApiRepository {
|
||||||
return ApiRepository(
|
return ApiRepository(
|
||||||
apiService = apiService
|
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 timber.log.Timber
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
object RetrofitClient {
|
class RetrofitClient {
|
||||||
private val okHttpClient: OkHttpClient by lazy {
|
private val okHttpClient: OkHttpClient by lazy {
|
||||||
val httpLoggingInterceptor by lazy {
|
val httpLoggingInterceptor by lazy {
|
||||||
HttpLoggingInterceptor { message ->
|
HttpLoggingInterceptor { message ->
|
||||||
|
|||||||
Reference in New Issue
Block a user