Magisk/app/src/main/java/com/topjohnwu/magisk/events/dialog/UninstallDialog.kt

50 lines
1.6 KiB
Kotlin
Raw Normal View History

package com.topjohnwu.magisk.events.dialog
2019-10-20 16:47:02 +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
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
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() }
}
}
@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
}