From ddbbca7e6275421dd3404ee4684b6efc1046bd8a Mon Sep 17 00:00:00 2001 From: Niko Diamadis Date: Thu, 14 Mar 2024 06:44:03 +0100 Subject: [PATCH] Replace deprecated OkHttp methods --- .../kotlin/com/github/gotify/login/LoginActivity.kt | 6 +++--- .../com/github/gotify/service/WebSocketConnection.kt | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt b/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt index 1f2d31e..79b1b08 100644 --- a/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/login/LoginActivity.kt @@ -32,7 +32,7 @@ import com.github.gotify.log.UncaughtExceptionHandler import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.textfield.TextInputEditText import java.security.cert.X509Certificate -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import org.tinylog.kotlin.Logger internal class LoginActivity : AppCompatActivity() { @@ -101,13 +101,13 @@ internal class LoginActivity : AppCompatActivity() { private fun doCheckUrl() { val url = binding.gotifyUrlEditext.text.toString().trim().trimEnd('/') - val parsedUrl = HttpUrl.parse(url) + val parsedUrl = url.toHttpUrlOrNull() if (parsedUrl == null) { Utils.showSnackBar(this, "Invalid URL (include http:// or https://)") return } - if ("http" == parsedUrl.scheme()) { + if ("http" == parsedUrl.scheme) { showHttpWarning() } diff --git a/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt b/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt index 6b14984..b3e809c 100644 --- a/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt +++ b/app/src/main/kotlin/com/github/gotify/service/WebSocketConnection.kt @@ -11,7 +11,7 @@ import com.github.gotify.client.model.Message import java.util.Calendar import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicLong -import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response @@ -89,7 +89,7 @@ internal class WebSocketConnection( } private fun request(): Request { - val url = HttpUrl.parse(baseUrl)!! + val url = baseUrl.toHttpUrlOrNull()!! .newBuilder() .addPathSegment("stream") .addQueryParameter("token", token) @@ -187,12 +187,12 @@ internal class WebSocketConnection( } override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { - val code = if (response != null) "StatusCode: ${response.code()}" else "" - val message = if (response != null) response.message() else "" + val code = if (response != null) "StatusCode: ${response.code}" else "" + val message = response?.message ?: "" Logger.error(t) { "WebSocket($id): failure $code Message: $message" } syncExec(id) { closed() - if (response != null && response.code() >= 400 && response.code() <= 499) { + if (response != null && response.code >= 400 && response.code <= 499) { onBadRequest.execute(message) return@syncExec }