From 47e236788cbcd0f0d028d652ab36d126760792d7 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sun, 20 Oct 2019 16:47:02 +0200 Subject: [PATCH] Added uninstall dialog --- .../model/events/dialog/UninstallDialog.kt | 55 +++++++++++++++++++ .../magisk/redesign/home/HomeViewModel.kt | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt diff --git a/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt new file mode 100644 index 000000000..7aecaaa51 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/model/events/dialog/UninstallDialog.kt @@ -0,0 +1,55 @@ +package com.topjohnwu.magisk.model.events.dialog + +import android.widget.Toast +import com.topjohnwu.magisk.Info +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.utils.Utils +import com.topjohnwu.magisk.view.MagiskDialog +import com.topjohnwu.superuser.Shell + +class UninstallDialog : DialogEvent() { + + override fun build(dialog: MagiskDialog) { + dialog.applyTitle(R.string.uninstall_magisk_title) + .applyMessage(R.string.uninstall_magisk_msg) + .applyButton(MagiskDialog.ButtonType.POSITIVE) { + titleRes = R.string.restore_img + preventDismiss = true + onClick { restore(dialog) } + } + if (Info.remote.uninstaller.link.isNotEmpty()) { + dialog.applyButton(MagiskDialog.ButtonType.NEGATIVE) { + titleRes = R.string.complete_uninstall + onClick { completeUninstall() } + } + } + } + + private fun restore(dialog: MagiskDialog) { + dialog.applyTitle(R.string.restore_img) + .applyMessage(R.string.restore_img_msg) + .applyButton(MagiskDialog.ButtonType.POSITIVE) { + title = "" + } + .cancellable(false) + + Shell.su("restore_imgs").submit { result -> + dialog.dismiss() + if (result.isSuccess) { + Utils.toast(R.string.restore_done, Toast.LENGTH_SHORT) + } else { + Utils.toast(R.string.restore_fail, Toast.LENGTH_LONG) + } + } + } + + private fun completeUninstall() { + DownloadService(dialog.context) { + subject = DownloadSubject.Magisk(Configuration.Uninstall) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt index e37b0dbed..26e74b2a8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/home/HomeViewModel.kt @@ -14,6 +14,7 @@ import com.topjohnwu.magisk.model.events.OpenInappLinkEvent import com.topjohnwu.magisk.model.events.dialog.EnvFixDialog import com.topjohnwu.magisk.model.events.dialog.MagiskInstallDialog import com.topjohnwu.magisk.model.events.dialog.ManagerInstallDialog +import com.topjohnwu.magisk.model.events.dialog.UninstallDialog import com.topjohnwu.magisk.model.observer.Observer import com.topjohnwu.magisk.redesign.compat.CompatViewModel import com.topjohnwu.magisk.ui.home.MagiskState @@ -111,7 +112,7 @@ class HomeViewModel( fun onLinkPressed(link: String) = OpenInappLinkEvent(link).publish() - fun onDeletePressed() {} + fun onDeletePressed() = UninstallDialog().publish() fun onManagerPressed() = ManagerInstallDialog().publish()