diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 28ccb3c..b47d135 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,8 +11,8 @@ android { applicationId = "de.ggb.kwabatv" minSdk = 21 targetSdk = 34 - versionCode = 1 - versionName = "1.0" + versionCode = 2 + versionName = "1.1.0" buildConfigField("String", "WEBSITE_URL", "\"https://kwaba-dev.whodovoodoo.pasteaf.de/tv\"") } diff --git a/app/src/main/java/de/ggb/kwabatv/UpdateChecker.kt b/app/src/main/java/de/ggb/kwabatv/UpdateChecker.kt index 71bb713..02b5b76 100644 --- a/app/src/main/java/de/ggb/kwabatv/UpdateChecker.kt +++ b/app/src/main/java/de/ggb/kwabatv/UpdateChecker.kt @@ -1,6 +1,8 @@ package de.ggb.kwabatv import org.json.JSONArray +import java.net.HttpURLConnection +import java.net.URL /** A qualifying update found on Gitea: display version and the APK's direct download URL. */ data class UpdateInfo(val version: String, val apkDownloadUrl: String) @@ -65,4 +67,24 @@ object UpdateChecker { } return best?.second } + + /** + * Fetches the releases list and returns the newest qualifying update, or null - including + * on any failure (network unreachable, non-200 response, malformed body). An update check + * is a nice-to-have; it must never be able to crash or visibly disrupt normal app use. + */ + fun checkForUpdate(currentVersion: String): UpdateInfo? { + return try { + val connection = URL(RELEASES_API_URL).openConnection() as HttpURLConnection + connection.connectTimeout = 8000 + connection.readTimeout = 8000 + connection.requestMethod = "GET" + connection.setRequestProperty("Accept", "application/json") + if (connection.responseCode != 200) return null + val body = connection.inputStream.bufferedReader().use { it.readText() } + pickUpdate(body, currentVersion) + } catch (e: Exception) { + null + } + } }