mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-06 15:30:46 -05:00
Added custom install dialogs
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.topjohnwu.magisk.model.events.dialog
|
||||
|
||||
import android.content.Context
|
||||
import com.skoumal.teanity.viewevents.ViewEvent
|
||||
import com.topjohnwu.magisk.model.events.ContextExecutor
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
|
||||
abstract class DialogEvent : ViewEvent(), ContextExecutor {
|
||||
|
||||
override fun invoke(context: Context) {
|
||||
MagiskDialog(context).apply(this::build).reveal()
|
||||
}
|
||||
|
||||
abstract fun build(dialog: MagiskDialog)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.topjohnwu.magisk.model.events.dialog
|
||||
|
||||
import com.topjohnwu.magisk.Info
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.extensions.res
|
||||
import com.topjohnwu.magisk.model.events.OpenInappLinkEvent
|
||||
import com.topjohnwu.magisk.view.MagiskDialog
|
||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.topjohnwu.superuser.ShellUtils
|
||||
|
||||
class MagiskInstallDialog : DialogEvent() {
|
||||
|
||||
override fun build(dialog: MagiskDialog) {
|
||||
with(dialog) {
|
||||
|
||||
val filename =
|
||||
"Magisk v${Info.remote.magisk.version}(${Info.remote.magisk.versionCode})"
|
||||
applyTitle(R.string.repo_install_title.res(R.string.magisk.res()))
|
||||
applyMessage(R.string.repo_install_msg.res(filename))
|
||||
setCancelable(true)
|
||||
applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
titleRes = R.string.install
|
||||
preventDismiss = true
|
||||
onClick {
|
||||
updateForInstallMethod(dialog)
|
||||
}
|
||||
}
|
||||
if (Info.remote.magisk.note.isEmpty()) return
|
||||
applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
titleRes = R.string.release_notes
|
||||
onClick {
|
||||
if (Info.remote.magisk.note.contains("forum.xda-developers")) {
|
||||
OpenInappLinkEvent(Info.remote.magisk.note).invoke(context)
|
||||
} else {
|
||||
MarkDownWindow.show(context, null, Info.remote.magisk.note)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateForInstallMethod(dialog: MagiskDialog) {
|
||||
with(dialog) {
|
||||
applyTitle(R.string.select_method)
|
||||
applyMessage("")
|
||||
applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
titleRes = R.string.download_zip_only
|
||||
preventDismiss = false
|
||||
onClick {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
applyButton(MagiskDialog.ButtonType.NEUTRAL) {
|
||||
titleRes = R.string.select_patch_file
|
||||
onClick {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
if (!Shell.rootAccess()) return
|
||||
applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
titleRes = R.string.direct_install
|
||||
onClick {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
if (!isABDevice()) return
|
||||
applyButton(MagiskDialog.ButtonType.IDGAF) {
|
||||
titleRes = R.string.install_inactive_slot
|
||||
onClick {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isABDevice() = ShellUtils
|
||||
.fastCmd("grep_prop ro.build.ab_update")
|
||||
.let { it.isNotEmpty() && it.toBoolean() }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.topjohnwu.magisk.model.events.dialog
|
||||
|
||||
import com.topjohnwu.magisk.Info
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.extensions.res
|
||||
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.view.MagiskDialog
|
||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||
|
||||
class ManagerInstallDialog : DialogEvent() {
|
||||
|
||||
override fun build(dialog: MagiskDialog) {
|
||||
with(dialog) {
|
||||
val subject = DownloadSubject.Manager(Configuration.APK.Upgrade)
|
||||
|
||||
applyTitle(R.string.repo_install_title.res(R.string.app_name.res()))
|
||||
applyMessage(R.string.repo_install_msg.res(subject.title))
|
||||
|
||||
setCancelable(true)
|
||||
|
||||
applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
||||
titleRes = R.string.install
|
||||
onClick { DownloadService(context) { this.subject = subject } }
|
||||
}
|
||||
|
||||
if (Info.remote.app.note.isEmpty()) return
|
||||
applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
||||
titleRes = R.string.app_changelog
|
||||
onClick { MarkDownWindow.show(context, null, Info.remote.app.note) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user