Added uninstall dialog
This commit is contained in:
parent
236ad57608
commit
47e236788c
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user