diff --git a/app/src/main/java/com/sw/platecabinet/network/ApiClient.kt b/app/src/main/java/com/sw/platecabinet/network/ApiClient.kt index 73c75d5..02ee2c2 100644 --- a/app/src/main/java/com/sw/platecabinet/network/ApiClient.kt +++ b/app/src/main/java/com/sw/platecabinet/network/ApiClient.kt @@ -12,37 +12,29 @@ import timber.log.Timber import java.util.concurrent.TimeUnit object ApiClient { - //private const val BASE_URL = "https://vip.shuziweidao.com" -// private const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889/" - private var DEVICE_BASE_URL = GlobalData.appBaseUrl - // private const val BASE_URL = "http://192.168.1.8:9092" -// private const val TIME_OUT = 30L // 超时时间(秒) - private const val TIME_OUT = 60L // 超时时间(秒) - val okHttpClient = OkHttpClient.Builder() + private const val TIME_OUT = 60L // 超时时间(秒) + + private val okHttpClient = OkHttpClient.Builder() .connectTimeout(TIME_OUT, TimeUnit.SECONDS) .readTimeout(TIME_OUT, TimeUnit.SECONDS) .writeTimeout(TIME_OUT, TimeUnit.SECONDS) - .addNetworkInterceptor(HttpLoggingInterceptor(logger = { - Timber.d("okhttp logger ==>${it}") - }).apply { - level = if (MyApp.DEBUG) { - HttpLoggingInterceptor.Level.BODY - } else { - HttpLoggingInterceptor.Level.NONE - } + .addNetworkInterceptor(HttpLoggingInterceptor { Timber.d("okhttp ==>${it}") }.apply { + level = if (MyApp.DEBUG) HttpLoggingInterceptor.Level.BODY + else HttpLoggingInterceptor.Level.NONE }) .addInterceptor(RequestInterceptor()) .build() - private val retrofit = Retrofit.Builder() - .baseUrl(DEVICE_BASE_URL) - .client(okHttpClient) - .addConverterFactory(GsonConverterFactory.create()) -// .addCallAdapterFactory(CoroutineCallAdapterFactory()) // 协程适配器 - .build() + private val retrofit by lazy { + Retrofit.Builder() + .baseUrl(GlobalData.appBaseUrl) + .client(okHttpClient) + .addConverterFactory(GsonConverterFactory.create()) + .build() + } val apiService: ApiService by lazy { retrofit.create(ApiService::class.java) } -} \ No newline at end of file +}