Consolidate some of the app update classes

We only use GitHub for all update checks, so the abstraction isn't useful.
This commit is contained in:
arkon
2021-06-01 17:54:34 -04:00
parent 3854995ef2
commit 5113c78ab6
8 changed files with 18 additions and 44 deletions

View File

@@ -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
/**

View File

@@ -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
}
}
}

View File

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

View File

@@ -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
}

View File

@@ -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()
}

View File

@@ -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()

View File

@@ -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()
}