Преглед изворни кода

Consolidate some of the app update classes

We only use GitHub for all update checks, so the abstraction isn't useful.
arkon пре 3 година
родитељ
комит
5113c78ab6

+ 4 - 5
app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubRelease.kt → app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubRelease.kt

@@ -1,6 +1,5 @@
-package eu.kanade.tachiyomi.data.updater.github
+package eu.kanade.tachiyomi.data.updater
 
-import eu.kanade.tachiyomi.data.updater.Release
 import kotlinx.serialization.SerialName
 import kotlinx.serialization.Serializable
 
@@ -15,15 +14,15 @@ import kotlinx.serialization.Serializable
 @Serializable
 class GithubRelease(
     @SerialName("tag_name") val version: String,
-    @SerialName("body") override val info: String,
+    @SerialName("body") val info: String,
     @SerialName("assets") private val assets: List<Assets>
-) : Release {
+) {
 
     /**
      * Get download link of latest release from the assets.
      * @return download link of latest release.
      */
-    override val downloadLink: String
+    val downloadLink: String
         get() = assets[0].downloadLink
 
     /**

+ 3 - 4
app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateChecker.kt → app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateChecker.kt

@@ -1,7 +1,6 @@
-package eu.kanade.tachiyomi.data.updater.github
+package eu.kanade.tachiyomi.data.updater
 
 import eu.kanade.tachiyomi.BuildConfig
-import eu.kanade.tachiyomi.data.updater.UpdateResult
 import eu.kanade.tachiyomi.network.GET
 import eu.kanade.tachiyomi.network.NetworkHelper
 import eu.kanade.tachiyomi.network.await
@@ -21,7 +20,7 @@ class GithubUpdateChecker {
         }
     }
 
-    suspend fun checkForUpdate(): UpdateResult {
+    suspend fun checkForUpdate(): GithubUpdateResult {
         return withIOContext {
             networkService.client
                 .newCall(GET("https://api.github.com/repos/$repo/releases/latest"))
@@ -32,7 +31,7 @@ class GithubUpdateChecker {
                     if (isNewVersion(it.version)) {
                         GithubUpdateResult.NewUpdate(it)
                     } else {
-                        GithubUpdateResult.NoNewUpdate()
+                        GithubUpdateResult.NoNewUpdate
                     }
                 }
         }

+ 6 - 0
app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateResult.kt

@@ -0,0 +1,6 @@
+package eu.kanade.tachiyomi.data.updater
+
+sealed class GithubUpdateResult {
+    class NewUpdate(val release: GithubRelease) : GithubUpdateResult()
+    object NoNewUpdate : GithubUpdateResult()
+}

+ 0 - 12
app/src/main/java/eu/kanade/tachiyomi/data/updater/Release.kt

@@ -1,12 +0,0 @@
-package eu.kanade.tachiyomi.data.updater
-
-interface Release {
-
-    val info: String
-
-    /**
-     * Get download link of latest release.
-     * @return download link of latest release.
-     */
-    val downloadLink: String
-}

+ 0 - 7
app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateResult.kt

@@ -1,7 +0,0 @@
-package eu.kanade.tachiyomi.data.updater
-
-abstract class UpdateResult {
-
-    open class NewUpdate<T : Release>(val release: T) : UpdateResult()
-    open class NoNewUpdate : UpdateResult()
-}

+ 1 - 2
app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt

@@ -8,7 +8,6 @@ import androidx.work.PeriodicWorkRequestBuilder
 import androidx.work.WorkManager
 import androidx.work.Worker
 import androidx.work.WorkerParameters
-import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
 import kotlinx.coroutines.runBlocking
 import java.util.concurrent.TimeUnit
 
@@ -19,7 +18,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) :
         try {
             val result = GithubUpdateChecker().checkForUpdate()
 
-            if (result is UpdateResult.NewUpdate<*>) {
+            if (result is GithubUpdateResult.NewUpdate) {
                 UpdaterNotifier(context).promptUpdate(result.release.downloadLink)
             }
             Result.success()

+ 0 - 9
app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateResult.kt

@@ -1,9 +0,0 @@
-package eu.kanade.tachiyomi.data.updater.github
-
-import eu.kanade.tachiyomi.data.updater.UpdateResult
-
-sealed class GithubUpdateResult : UpdateResult() {
-
-    class NewUpdate(release: GithubRelease) : UpdateResult.NewUpdate<GithubRelease>(release)
-    class NoNewUpdate : UpdateResult.NoNewUpdate()
-}

+ 4 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt

@@ -8,9 +8,9 @@ import com.afollestad.materialdialogs.MaterialDialog
 import com.mikepenz.aboutlibraries.LibsBuilder
 import eu.kanade.tachiyomi.BuildConfig
 import eu.kanade.tachiyomi.R
-import eu.kanade.tachiyomi.data.updater.UpdateResult
+import eu.kanade.tachiyomi.data.updater.GithubUpdateChecker
+import eu.kanade.tachiyomi.data.updater.GithubUpdateResult
 import eu.kanade.tachiyomi.data.updater.UpdaterService
-import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
 import eu.kanade.tachiyomi.ui.base.controller.DialogController
 import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
 import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
@@ -23,7 +23,6 @@ import eu.kanade.tachiyomi.util.preference.onClick
 import eu.kanade.tachiyomi.util.preference.preference
 import eu.kanade.tachiyomi.util.preference.titleRes
 import eu.kanade.tachiyomi.util.system.copyToClipboard
-import eu.kanade.tachiyomi.util.system.openInBrowser
 import eu.kanade.tachiyomi.util.system.toast
 import timber.log.Timber
 import java.text.DateFormat
@@ -110,14 +109,14 @@ class AboutController : SettingsController(), NoToolbarElevationController {
         launchNow {
             try {
                 when (val result = updateChecker.checkForUpdate()) {
-                    is UpdateResult.NewUpdate<*> -> {
+                    is GithubUpdateResult.NewUpdate -> {
                         val body = result.release.info
                         val url = result.release.downloadLink
 
                         // Create confirmation window
                         NewUpdateDialogController(body, url).showDialog(router)
                     }
-                    is UpdateResult.NoNewUpdate -> {
+                    is GithubUpdateResult.NoNewUpdate -> {
                         activity?.toast(R.string.update_check_no_new_updates)
                     }
                 }