From 6cbb5deff673ce363f621089032e5fca4b290f80 Mon Sep 17 00:00:00 2001 From: tunbmoon Date: Sun, 8 Feb 2026 17:15:38 +0800 Subject: [PATCH] fix: respect update channel selection when checking for updates --- .../ui/page/settings/about/UpdatePage.kt | 2 +- .../antoniegil/astronia/util/UpdateUtil.kt | 31 ++++++++++++------- .../android/en-US/full_description.txt | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/antoniegil/astronia/ui/page/settings/about/UpdatePage.kt b/app/src/main/java/com/antoniegil/astronia/ui/page/settings/about/UpdatePage.kt index f095142..53de2e5 100644 --- a/app/src/main/java/com/antoniegil/astronia/ui/page/settings/about/UpdatePage.kt +++ b/app/src/main/java/com/antoniegil/astronia/ui/page/settings/about/UpdatePage.kt @@ -124,7 +124,7 @@ fun UpdatePage(onNavigateBack: () -> Unit) { isLoading = true withContext(Dispatchers.IO) { runCatching { - UpdateUtil.checkForUpdate(context)?.let { + UpdateUtil.checkForUpdate(context, updateChannel == PRE_RELEASE)?.let { latestRelease = it showUpdateDialog = true } ?: run { diff --git a/app/src/main/java/com/antoniegil/astronia/util/UpdateUtil.kt b/app/src/main/java/com/antoniegil/astronia/util/UpdateUtil.kt index 1d0b8cf..42188d5 100644 --- a/app/src/main/java/com/antoniegil/astronia/util/UpdateUtil.kt +++ b/app/src/main/java/com/antoniegil/astronia/util/UpdateUtil.kt @@ -16,22 +16,31 @@ object UpdateUtil { private const val REPO = "Astronia" private val client = OkHttpClient() - private val requestForReleases = - Request.Builder().url("https://api.github.com/repos/${OWNER}/${REPO}/releases/latest") - .build() - private val jsonFormat = Json { ignoreUnknownKeys = true } - private fun getLatestRelease(): LatestRelease = - client.newCall(requestForReleases).execute().run { - val latestRelease = jsonFormat.decodeFromString(this.body.string()) - body.close() - latestRelease + private fun getLatestRelease(includePreRelease: Boolean): LatestRelease? { + val url = if (includePreRelease) { + "https://api.github.com/repos/${OWNER}/${REPO}/releases" + } else { + "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" } + + val request = Request.Builder().url(url).build() + return client.newCall(request).execute().run { + val result = if (includePreRelease) { + val releases = jsonFormat.decodeFromString>(body.string()) + releases.firstOrNull { it.preRelease } + } else { + jsonFormat.decodeFromString(body.string()) + } + body.close() + result + } + } - fun checkForUpdate(context: Context): LatestRelease? { + fun checkForUpdate(context: Context, includePreRelease: Boolean = false): LatestRelease? { val currentVersion = context.getCurrentVersion() - val latestRelease = getLatestRelease() + val latestRelease = getLatestRelease(includePreRelease) ?: return null val latestVersion = latestRelease.name.toVersion() return if (currentVersion < latestVersion) latestRelease else null diff --git a/fastlane/metadata/android/en-US/full_description.txt b/fastlane/metadata/android/en-US/full_description.txt index 57a6cf4..1009f66 100644 --- a/fastlane/metadata/android/en-US/full_description.txt +++ b/fastlane/metadata/android/en-US/full_description.txt @@ -1,6 +1,7 @@ Astronia is a lightweight and modern M3U8 video player for Android, built with Material Design 3. It provides a clean and intuitive interface for streaming video content. Features + - 🎬 M3U8 video streaming playback - 📱 Material Design 3 UI - 🌙 Dark mode support