2020-08-19 11:05:23 +02:00
|
|
|
package com.topjohnwu.magisk.events.dialog
|
2019-11-11 18:01:23 +01:00
|
|
|
|
|
|
|
import com.topjohnwu.magisk.R
|
2020-09-23 22:53:40 +02:00
|
|
|
import com.topjohnwu.magisk.core.Info
|
2020-08-21 15:45:40 +02:00
|
|
|
import com.topjohnwu.magisk.core.download.Action
|
2020-01-13 15:01:46 +01:00
|
|
|
import com.topjohnwu.magisk.core.download.DownloadService
|
2020-08-21 15:45:40 +02:00
|
|
|
import com.topjohnwu.magisk.core.download.Subject
|
2020-10-11 07:40:57 +02:00
|
|
|
import com.topjohnwu.magisk.core.model.module.OnlineModule
|
2019-11-11 18:01:23 +01:00
|
|
|
import com.topjohnwu.magisk.view.MagiskDialog
|
|
|
|
|
2020-10-11 07:40:57 +02:00
|
|
|
class ModuleInstallDialog(private val item: OnlineModule) : DialogEvent() {
|
2019-11-11 18:01:23 +01:00
|
|
|
|
|
|
|
override fun build(dialog: MagiskDialog) {
|
|
|
|
with(dialog) {
|
|
|
|
|
2020-08-28 13:46:05 +02:00
|
|
|
fun download(install: Boolean) {
|
2021-01-22 11:28:53 +01:00
|
|
|
val config = if (install) Action.Flash else Action.Download
|
2020-08-28 13:46:05 +02:00
|
|
|
val subject = Subject.Module(item, config)
|
2020-08-28 13:50:46 +02:00
|
|
|
DownloadService.start(context, subject)
|
2019-11-11 18:01:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
applyTitle(context.getString(R.string.repo_install_title, item.name))
|
|
|
|
.applyMessage(context.getString(R.string.repo_install_msg, item.downloadFilename))
|
|
|
|
.cancellable(true)
|
|
|
|
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
|
|
|
|
titleRes = R.string.download
|
2019-11-19 17:15:44 +01:00
|
|
|
icon = R.drawable.ic_download_md2
|
2019-11-11 18:01:23 +01:00
|
|
|
onClick { download(false) }
|
|
|
|
}
|
2020-09-23 22:53:40 +02:00
|
|
|
|
|
|
|
if (Info.env.isActive) {
|
|
|
|
applyButton(MagiskDialog.ButtonType.POSITIVE) {
|
|
|
|
titleRes = R.string.install
|
|
|
|
icon = R.drawable.ic_install
|
|
|
|
onClick { download(true) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reveal()
|
2019-11-11 18:01:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-13 15:01:46 +01:00
|
|
|
}
|