Просмотр исходного кода

修改可以获取所有更新

HapeLee 1 год назад
Родитель
Сommit
2d2b4d949a

+ 1 - 0
app/src/main/java/io/legato/kazusa/help/update/AppReleaseInfo.kt

@@ -19,6 +19,7 @@ data class AppReleaseInfo(
 enum class AppVariant {
     OFFICIAL,
     BETA_RELEASE,
+    ALL,
     UNKNOWN;
 
     fun isBeta(): Boolean {

+ 39 - 19
app/src/main/java/io/legato/kazusa/help/update/AppUpdateGitHub.kt

@@ -18,34 +18,49 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
         get() = when (AppConfig.updateToVariant) {
             "official_version" -> AppVariant.OFFICIAL
             "beta_release_version" -> AppVariant.BETA_RELEASE
+            "all_version" -> AppVariant.ALL
             else -> AppConst.appInfo.appVariant
         }
 
     private suspend fun getLatestRelease(): List<AppReleaseInfo> {
-        val lastReleaseUrl = if (checkVariant.isBeta()) {
-            "https://api.github.com/repos/HapeLee/legado-with-MD3/releases"
-        } else {
+        val url = if (checkVariant == AppVariant.OFFICIAL)
             "https://api.github.com/repos/HapeLee/legado-with-MD3/releases/latest"
-        }
+        else
+            "https://api.github.com/repos/HapeLee/legado-with-MD3/releases"
 
-        val res = okHttpClient.newCallResponse { url(lastReleaseUrl) }
+        val res = okHttpClient.newCallResponse { url(url) }
         if (!res.isSuccessful) throw NoStackTraceException("获取新版本出错(${res.code})")
+
         val body = res.body.text()
         if (body.isBlank()) throw NoStackTraceException("获取新版本出错")
 
-        return if (checkVariant.isBeta()) {
-            val releases = GSON.fromJsonArray<GithubRelease>(body)
-                .getOrElse { throw NoStackTraceException("获取新版本出错 ${it.localizedMessage}") }
+        return when (checkVariant) {
+            AppVariant.BETA_RELEASE -> {
+                val releases = GSON.fromJsonArray<GithubRelease>(body)
+                    .getOrElse { throw NoStackTraceException("解析失败 ${it.localizedMessage}") }
 
-            releases.filter { it.isPreRelease }
-                .flatMap { it.gitReleaseToAppReleaseInfo() }
-                .sortedByDescending { it.createdAt }
-        } else {
-            val release = GSON.fromJsonObject<GithubRelease>(body)
-                .getOrElse { throw NoStackTraceException("获取新版本出错 ${it.localizedMessage}") }
+                releases.filter { it.isPreRelease }
+                    .flatMap { it.gitReleaseToAppReleaseInfo() }
+                    .sortedByDescending { it.createdAt }
+            }
+
+            AppVariant.OFFICIAL -> {
+                val release = GSON.fromJsonObject<GithubRelease>(body)
+                    .getOrElse { throw NoStackTraceException("解析失败 ${it.localizedMessage}") }
 
-            release.gitReleaseToAppReleaseInfo()
-                .sortedByDescending { it.createdAt }
+                release.gitReleaseToAppReleaseInfo()
+                    .sortedByDescending { it.createdAt }
+            }
+
+            AppVariant.ALL -> {
+                val releases = GSON.fromJsonArray<GithubRelease>(body)
+                    .getOrElse { throw NoStackTraceException("解析失败 ${it.localizedMessage}") }
+
+                releases.flatMap { it.gitReleaseToAppReleaseInfo() }
+                    .sortedByDescending { it.createdAt }
+            }
+
+            else -> emptyList()
         }
     }
 
@@ -53,12 +68,17 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
         return Coroutine.async(scope) {
             val currentVersion = AppConst.appInfo.versionName
             val releases = getLatestRelease()
-                .filter { it.appVariant == checkVariant }
 
-            val latest = releases.firstOrNull { r ->
+            val filtered = if (checkVariant == AppVariant.ALL) {
+                releases
+            } else {
+                releases.filter { it.appVariant == checkVariant }
+            }
+
+            val latest = filtered.firstOrNull { r ->
                 try {
                     r.versionName.versionCompare(currentVersion) > 0
-                } catch (e: Exception) {
+                } catch (_: Exception) {
                     false
                 }
             }

+ 1 - 0
app/src/main/java/io/legato/kazusa/ui/about/UpdateDialog.kt

@@ -34,6 +34,7 @@ class UpdateDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_update) {
         get() = when (AppConfig.updateToVariant) {
             "official_version" -> AppVariant.OFFICIAL
             "beta_release_version" -> AppVariant.BETA_RELEASE
+            "all_version" -> AppVariant.ALL
             else -> AppConst.appInfo.appVariant
         }