diff --git a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/SettingsViewModel.kt b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/SettingsViewModel.kt index 81c0d9d..19b2f83 100644 --- a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/SettingsViewModel.kt +++ b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/SettingsViewModel.kt @@ -82,11 +82,11 @@ class SettingsViewModel( } private suspend fun onProxyChanged(newProxy: Proxy) { - walletRepository.getRemoteClients().first().forEach { - val currentProxy = it.httpClient.proxy() - if (currentProxy != newProxy) { - val builder = it.httpClient.newBuilder() - it.httpClient = builder.proxy(newProxy).build() + walletRepository.getRemoteClients().first().forEach { client -> + val current = client.httpClient.proxy + if (current != newProxy) { + val builder = client.httpClient.newBuilder() + client.httpClient = builder.proxy(newProxy).build() } } } diff --git a/lib/android/build.gradle b/lib/android/build.gradle index cc51283..fb84c2a 100644 --- a/lib/android/build.gradle +++ b/lib/android/build.gradle @@ -90,7 +90,7 @@ android { } dependencies { - api 'com.squareup.okhttp3:okhttp:3.12.13' + api 'com.squareup.okhttp3:okhttp:4.10.0' implementation 'androidx.core:core-ktx:1.9.0' // implementation 'androidx.appcompat:appcompat:1.3.0' diff --git a/lib/android/src/main/kotlin/im/molly/monero/RemoteNodeClient.kt b/lib/android/src/main/kotlin/im/molly/monero/RemoteNodeClient.kt index d7bb6af..3e99282 100644 --- a/lib/android/src/main/kotlin/im/molly/monero/RemoteNodeClient.kt +++ b/lib/android/src/main/kotlin/im/molly/monero/RemoteNodeClient.kt @@ -7,6 +7,8 @@ import im.molly.monero.loadbalancer.Rule import kotlinx.coroutines.* import kotlinx.coroutines.flow.Flow import okhttp3.* +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.toRequestBody import java.io.FileOutputStream import java.io.IOException import java.util.concurrent.ConcurrentHashMap @@ -69,15 +71,15 @@ class RemoteNodeClient private constructor( runCatching { requestWithRetry(method, path, header, body) }.onSuccess { response -> - val statusCode = response.code() - val responseBody = response.body() + val status = response.code + val responseBody = response.body if (responseBody == null) { - callback?.onResponse(statusCode, null, null) + callback?.onResponse(status, null, null) } else { val contentType = responseBody.contentType()?.toString() val pipe = ParcelFileDescriptor.createPipe() - callback?.onResponse(statusCode, contentType, pipe[0]) + callback?.onResponse(status, contentType, pipe[0]) responseBody.use { pipe[1].use { writeSide -> @@ -163,16 +165,14 @@ class RemoteNodeClient private constructor( body: ByteArray?, ): Response { val headers = parseHttpHeader(header) - val contentType = headers.get("Content-Type")?.let { value -> - MediaType.get(value) - } + val contentType = headers["Content-Type"]?.toMediaType() // TODO: Log unsupported headers val request = with(Request.Builder()) { when { method.equals("GET", ignoreCase = true) -> {} method.equals("POST", ignoreCase = true) -> { val content = body ?: ByteArray(0) - post(RequestBody.create(contentType, content)) + post(content.toRequestBody(contentType)) } else -> throw IllegalArgumentException("Unsupported method") }