refactor: r8 build optmisations
This commit is contained in:
@@ -1,40 +1,22 @@
|
||||
package com.bitcointxoko.gudariwallet.api
|
||||
|
||||
import com.bitcointxoko.gudariwallet.BuildConfig
|
||||
import com.bitcointxoko.gudariwallet.security.SecretStore
|
||||
import com.bitcointxoko.gudariwallet.util.WalletConstants
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object LNbitsClient {
|
||||
|
||||
val logging = HttpLoggingInterceptor { message ->
|
||||
Timber.tag("OkHttp").d(message)
|
||||
}.apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY // logs full request + response body
|
||||
}
|
||||
|
||||
// Single shared client — used by both Retrofit and WebSocket
|
||||
val httpClient: OkHttpClient = OkHttpClient.Builder()
|
||||
.connectTimeout(WalletConstants.CONNECT_TIMEOUT_S, TimeUnit.SECONDS)
|
||||
.readTimeout(WalletConstants.READ_TIMEOUT_S, TimeUnit.SECONDS)
|
||||
.writeTimeout(WalletConstants.WRITE_TIMEOUT_S, TimeUnit.SECONDS)
|
||||
.addInterceptor(logging)
|
||||
.apply {
|
||||
if (BuildConfig.DEBUG) {
|
||||
addInterceptor(HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
})
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
||||
fun create(secrets: SecretStore): LNbitsApi {
|
||||
@@ -71,21 +53,11 @@ object LNbitsClient {
|
||||
}
|
||||
|
||||
val client = httpClient.newBuilder()
|
||||
// .addInterceptor(authInterceptor)
|
||||
.addInterceptor(dynamicBaseUrlInterceptor)
|
||||
.apply {
|
||||
// Logging goes LAST — after URL rewrite — so logs show the real URL
|
||||
if (BuildConfig.DEBUG) {
|
||||
addInterceptor(HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
})
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
||||
return Retrofit.Builder()
|
||||
.baseUrl("https://placeholder.invalid/") // structurally required by Retrofit;
|
||||
// always overwritten by the interceptor
|
||||
.client(client)
|
||||
.addConverterFactory(GsonConverterFactory.create(GsonProvider.gson))
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user