2020-08-19 11:05:23 +02:00
|
|
|
package com.topjohnwu.magisk.events.dialog
|
2019-10-20 16:47:02 +02:00
|
|
|
|
2020-10-08 09:27:07 +02:00
|
|
|
import android.app.ProgressDialog
|
2019-10-20 16:47:02 +02:00
|
|
|
import android.widget.Toast
|
|
|
|
import com.topjohnwu.magisk.R
|
2021-04-30 13:41:46 +02:00
|
|
|
import com.topjohnwu.magisk.arch.BaseUIActivity
|
2021-01-22 11:28:53 +01:00
|
|
|
import com.topjohnwu.magisk.ui.flash.FlashFragment
|
2020-08-18 15:31:15 +02:00
|
|
|
import com.topjohnwu.magisk.utils.Utils
|
2019-10-20 16:47:02 +02:00
|
|
|
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
|
2020-10-08 09:27:07 +02:00
|
|
|
onClick { restore() }
|
2019-10-20 16:47:02 +02:00
|
|
|
}
|
2021-01-24 03:10:26 +01:00
|
|
|
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
2019-10-20 16:47:02 +02:00
|
|
|
titleRes = R.string.complete_uninstall
|
|
|
|
onClick { completeUninstall() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 09:27:07 +02:00
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
private fun restore() {
|
|
|
|
val dialog = ProgressDialog(dialog.context).apply {
|
|
|
|
setMessage(dialog.context.getString(R.string.restore_img_msg))
|
|
|
|
show()
|
|
|
|
}
|
2019-10-20 16:47:02 +02:00
|
|
|
|
|
|
|
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() {
|
2021-04-30 13:41:46 +02:00
|
|
|
(dialog.ownerActivity as? BaseUIActivity<*, *>)
|
|
|
|
?.navigation?.navigate(FlashFragment.uninstall())
|
2019-10-20 16:47:02 +02:00
|
|
|
}
|
|
|
|
|
2020-01-13 15:01:46 +01:00
|
|
|
}
|