diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/dialog/OnlineModuleInstallDialog.kt b/app/apk/src/main/java/com/topjohnwu/magisk/dialog/OnlineModuleInstallDialog.kt index 2aa293977..690664344 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/dialog/OnlineModuleInstallDialog.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/dialog/OnlineModuleInstallDialog.kt @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.dialog +import android.content.Context import com.topjohnwu.magisk.core.R import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.download.DownloadEngine @@ -7,6 +8,8 @@ import com.topjohnwu.magisk.core.download.Subject import com.topjohnwu.magisk.core.model.module.OnlineModule import com.topjohnwu.magisk.ui.flash.FlashFragment import com.topjohnwu.magisk.view.MagiskDialog +import com.topjohnwu.magisk.view.Notifications +import kotlinx.parcelize.Parcelize class OnlineModuleInstallDialog(private val item: OnlineModule) : MarkDownDialog() { @@ -17,14 +20,21 @@ class OnlineModuleInstallDialog(private val item: OnlineModule) : MarkDownDialog return if (str.length > 1000) str.substring(0, 1000) else str } + @Parcelize + class Module( + override val module: OnlineModule, + override val autoLaunch: Boolean, + override val notifyId: Int = Notifications.nextId() + ) : Subject.Module() { + override fun pendingIntent(context: Context) = FlashFragment.installIntent(context, file) + } + override fun build(dialog: MagiskDialog) { super.build(dialog) dialog.apply { fun download(install: Boolean) { - val module = Subject.Module(item, install) - module.piCreator = FlashFragment::installIntent - DownloadEngine.startWithActivity(activity, module) + DownloadEngine.startWithActivity(activity, Module(item, install)) } val title = context.getString(R.string.repo_install_title, diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt index a7431b090..b9f551d96 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/download/Subject.kt @@ -17,7 +17,7 @@ import kotlinx.parcelize.Parcelize import java.io.File import java.util.UUID -sealed class Subject : Parcelable { +abstract class Subject : Parcelable { abstract val url: String abstract val file: Uri @@ -27,24 +27,13 @@ sealed class Subject : Parcelable { open fun pendingIntent(context: Context): PendingIntent? = null - @Parcelize - class Module( - private val module: OnlineModule, - override val autoLaunch: Boolean, - override val notifyId: Int = Notifications.nextId() - ) : Subject() { - override val url: String get() = module.zipUrl - override val title: String get() = module.downloadFilename - - @IgnoredOnParcel - override val file by lazy { + abstract class Module : Subject() { + abstract val module: OnlineModule + final override val url: String get() = module.zipUrl + final override val title: String get() = module.downloadFilename + final override val file by lazy { MediaStoreUtils.getFile(title).uri } - - @IgnoredOnParcel - var piCreator: ((Context, Uri) -> PendingIntent)? = null - - override fun pendingIntent(context: Context) = piCreator?.invoke(context, file) } @Parcelize