Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Twmcy authored Feb 18, 2024
1 parent c6808e1 commit 04eeba0
Showing 1 changed file with 6 additions and 37 deletions.
43 changes: 6 additions & 37 deletions app/src/main/java/com/projectkr/shell/DialogPower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,33 @@ import com.omarea.common.shell.KeepShellPublic
import com.omarea.common.ui.DialogHelper

class DialogPower(var context: Activity) {
private fun showConfirmationDialog(cmdResId: Int, onConfirmed: () -> Unit) {
val cmd = context.getString(cmdResId)
val confirmationMessage = "Are you sure you want to execute: $cmd ?"

DialogHelper.showConfirmationDialog(
context,
"Confirmation",
confirmationMessage,
positiveText = "Yes",
negativeText = "Cancel",
onPositiveClick = onConfirmed
)
}

fun showPowerMenu() {
val view = context.layoutInflater.inflate(R.layout.dialog_power_operation, null)
val dialog = DialogHelper.customDialog(context, view)

view.findViewById<View>(R.id.power_shutdown).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_shutdown_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_shutdown_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_shutdown_cmd))
}

view.findViewById<View>(R.id.power_reboot).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_reboot_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_reboot_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_reboot_cmd))
}

view.findViewById<View>(R.id.power_hot_reboot).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_hot_reboot_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_hot_reboot_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_hot_reboot_cmd))
}

view.findViewById<View>(R.id.power_recovery).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_recovery_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_recovery_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_recovery_cmd))
}

view.findViewById<View>(R.id.power_fastboot).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_fastboot_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_fastboot_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_fastboot_cmd))
}

view.findViewById<View>(R.id.power_emergency).setOnClickListener {
dialog.dismiss()
showConfirmationDialog(R.string.power_emergency_cmd) {
KeepShellPublic.doCmdSync(context.getString(R.string.power_emergency_cmd))
}
KeepShellPublic.doCmdSync(context.getString(R.string.power_emergency_cmd))
}
}
}

0 comments on commit 04eeba0

Please sign in to comment.