feat: 网络

This commit is contained in:
yangxisong 2025-11-13 10:25:54 +08:00
parent 570de3c4e7
commit 4327a8638c
4 changed files with 12 additions and 18 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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()
}
}
}

View File

@ -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 ->