diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt new file mode 100644 index 000000000..4a91de88f --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/ModuleInstallDialog.kt @@ -0,0 +1,35 @@ +package com.topjohnwu.magisk.model.events.dialog + +import com.topjohnwu.magisk.R +import com.topjohnwu.magisk.model.download.DownloadService +import com.topjohnwu.magisk.model.entity.internal.Configuration +import com.topjohnwu.magisk.model.entity.internal.DownloadSubject +import com.topjohnwu.magisk.model.entity.module.Repo +import com.topjohnwu.magisk.view.MagiskDialog + +class ModuleInstallDialog(private val item: Repo) : DialogEvent() { + + override fun build(dialog: MagiskDialog) { + with(dialog) { + + fun download(install: Boolean) = DownloadService(context) { + val config = if (install) Configuration.Flash.Primary else Configuration.Download + subject = DownloadSubject.Module(item, config) + } + + applyTitle(context.getString(R.string.repo_install_title, item.name)) + .applyMessage(context.getString(R.string.repo_install_msg, item.downloadFilename)) + .cancellable(true) + .applyButton(MagiskDialog.ButtonType.POSITIVE) { + titleRes = R.string.install + onClick { download(true) } + } + .applyButton(MagiskDialog.ButtonType.NEGATIVE) { + titleRes = R.string.download + onClick { download(false) } + } + .reveal() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index cee5e68a3..10f258e1d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -195,6 +195,10 @@ class ModuleViewModel( .subscribeK() } + fun download(item: RepoItem) { + ModuleInstallDialog(item.item).publish() + } + // --- private fun cleanup() = Completable diff --git a/app/src/main/res/layout/item_repo_md2.xml b/app/src/main/res/layout/item_repo_md2.xml index 592feb068..5fa385fec 100644 --- a/app/src/main/res/layout/item_repo_md2.xml +++ b/app/src/main/res/layout/item_repo_md2.xml @@ -96,6 +96,7 @@ android:id="@+id/module_download" style="?styleIconPrimary" android:contentDescription="@string/download" + android:onClick="@{() -> viewModel.download(item)}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/module_divider"