From a8932706d8ed04c61c66fb0118b60a08dc84dea6 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 23 Jul 2019 00:55:12 -0700 Subject: [PATCH] Consolidate Magisk download subject --- .../magisk/model/download/DownloadService.kt | 1 - .../model/entity/internal/DownloadSubject.kt | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt index 6a58f2fad..63e4f1602 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/DownloadService.kt @@ -50,7 +50,6 @@ open class DownloadService : RemoteFileService() { Uninstall -> FlashActivity.uninstall(this, file) is Patch -> FlashActivity.patch(this, file, conf.fileUri) is Flash -> FlashActivity.flash(this, file, conf is Secondary) - else -> Unit } private fun onFinishedInternal( diff --git a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt index e8061f19a..843cf81d6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/entity/internal/DownloadSubject.kt @@ -16,24 +16,36 @@ sealed class DownloadSubject : Parcelable { val module: Repo, val configuration: Configuration ) : DownloadSubject() { - override val url: String get() = module.zipUrl override val fileName: String get() = "${module.name}-v${module.version}(${module.versionCode}).zip" - } - @Parcelize - data class Magisk( - val configuration: Configuration, - val magisk: MagiskJson = Info.remote.magisk - ) : DownloadSubject() { + sealed class Magisk : DownloadSubject() { - override val url: String get() = magisk.link - override val fileName get() = - if (configuration is Configuration.Flash) - "magisk.zip" - else - "Magisk-v${magisk.version}(${magisk.versionCode}).zip" + abstract val configuration: Configuration + val magisk: MagiskJson = Info.remote.magisk + + @Parcelize + protected data class Flash( + override val configuration: Configuration + ) : Magisk() { + override val url: String get() = magisk.link + override val fileName get() = "magisk.zip" + } + + @Parcelize + protected object Download : Magisk() { + override val configuration: Configuration get() = Configuration.Download + override val url: String get() = magisk.link + override val fileName get() = "Magisk-v${magisk.version}(${magisk.versionCode}).zip" + } + + companion object { + operator fun invoke(configuration: Configuration) = when (configuration) { + Configuration.Download -> Download + else -> Flash(configuration) + } + } }