From 5113c78ab6d599286e3e2bd445b5b21dd7abf994 Mon Sep 17 00:00:00 2001 From: arkon Date: Tue, 1 Jun 2021 17:54:34 -0400 Subject: [PATCH] Consolidate some of the app update classes We only use GitHub for all update checks, so the abstraction isn't useful. --- .../data/updater/{github => }/GithubRelease.kt | 9 ++++----- .../data/updater/{github => }/GithubUpdateChecker.kt | 7 +++---- .../tachiyomi/data/updater/GithubUpdateResult.kt | 6 ++++++ .../java/eu/kanade/tachiyomi/data/updater/Release.kt | 12 ------------ .../eu/kanade/tachiyomi/data/updater/UpdateResult.kt | 7 ------- .../eu/kanade/tachiyomi/data/updater/UpdaterJob.kt | 3 +-- .../data/updater/github/GithubUpdateResult.kt | 9 --------- .../eu/kanade/tachiyomi/ui/more/AboutController.kt | 9 ++++----- 8 files changed, 18 insertions(+), 44 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/data/updater/{github => }/GithubRelease.kt (80%) rename app/src/main/java/eu/kanade/tachiyomi/data/updater/{github => }/GithubUpdateChecker.kt (89%) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateResult.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/updater/Release.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateResult.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateResult.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubRelease.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubRelease.kt similarity index 80% rename from app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubRelease.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubRelease.kt index 23c7ef6a3..9f669aa75 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubRelease.kt +++ b/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 -) : 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 /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateChecker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateChecker.kt similarity index 89% rename from app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateChecker.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateChecker.kt index 2ce06aeae..7f937e7f7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateChecker.kt +++ b/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 } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateResult.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/GithubUpdateResult.kt new file mode 100644 index 000000000..ac0581739 --- /dev/null +++ b/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() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/Release.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/Release.kt deleted file mode 100644 index 61f2bd787..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/Release.kt +++ /dev/null @@ -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 -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateResult.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateResult.kt deleted file mode 100644 index a147c01df..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdateResult.kt +++ /dev/null @@ -1,7 +0,0 @@ -package eu.kanade.tachiyomi.data.updater - -abstract class UpdateResult { - - open class NewUpdate(val release: T) : UpdateResult() - open class NoNewUpdate : UpdateResult() -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt index 6be3120e1..f0b7d81ca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt +++ b/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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateResult.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateResult.kt deleted file mode 100644 index 8462f937e..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubUpdateResult.kt +++ /dev/null @@ -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(release) - class NoNewUpdate : UpdateResult.NoNewUpdate() -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 7c0f065a6..f1aebb6ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/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) } }