Updated method naming scheme

Added new configurations
Added flashing methods and annotated viewModel's uri as deprecated in function
This commit is contained in:
Viktor De Pasquale 2019-07-10 15:00:14 +02:00 committed by John Wu
parent 40b683111c
commit 12e00c3054
4 changed files with 70 additions and 46 deletions

View File

@ -17,52 +17,58 @@ open class CompoundDownloadService : SubstrateDownloadService() {
private val context get() = this
override fun onFinished(file: File, subject: DownloadSubject) {
when (subject) {
is DownloadSubject.Magisk -> {
if (subject.configuration == Configuration.FLASH) {
FlashActivity.flashMagisk(this, file)
}
}
is DownloadSubject.Module -> {
if (subject.configuration == Configuration.FLASH) {
FlashActivity.flashModule(this, file)
}
}
}
override fun onFinished(file: File, subject: DownloadSubject) = when (subject) {
is DownloadSubject.Magisk -> onFinishedInternal(file, subject)
is DownloadSubject.Module -> onFinishedInternal(file, subject)
}
private fun onFinishedInternal(
file: File,
subject: DownloadSubject.Magisk
) = when (subject.configuration) {
Configuration.FLASH -> FlashActivity.flash(this, file)
else -> Unit
}
private fun onFinishedInternal(
file: File,
subject: DownloadSubject.Module
) = when (subject.configuration) {
Configuration.FLASH -> FlashActivity.install(this, file)
else -> Unit
}
// ---
override fun NotificationCompat.Builder.addActions(file: File, subject: DownloadSubject) =
when (subject) {
is DownloadSubject.Magisk -> addMagiskActions(file, subject.configuration)
is DownloadSubject.Module -> addModuleActions(file, subject.configuration)
}
private fun NotificationCompat.Builder.addMagiskActions(
override fun NotificationCompat.Builder.addActions(
file: File,
configuration: Configuration
) = apply {
when (configuration) {
Configuration.FLASH -> {
val inner = FlashActivity.flashMagiskIntent(context, file)
val intent = PendingIntent
.getActivity(context, nextInt(), inner, PendingIntent.FLAG_ONE_SHOT)
setContentIntent(intent)
}
}
subject: DownloadSubject
) = when (subject) {
is DownloadSubject.Magisk -> addActionsInternal(file, subject)
is DownloadSubject.Module -> addActionsInternal(file, subject)
}
private fun NotificationCompat.Builder.addModuleActions(
private fun NotificationCompat.Builder.addActionsInternal(
file: File,
configuration: Configuration
) = apply {
subject: DownloadSubject.Magisk
) = when (subject.configuration) {
Configuration.FLASH -> setContentIntent(FlashActivity.flashIntent(context, file))
else -> this
}
private fun NotificationCompat.Builder.addActionsInternal(
file: File,
subject: DownloadSubject.Module
) = when (subject.configuration) {
Configuration.FLASH -> setContentIntent(FlashActivity.installIntent(context, file))
else -> this
}
@Suppress("ReplaceSingleLineLet")
private fun NotificationCompat.Builder.setContentIntent(intent: Intent) =
PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT)
.let { setContentIntent(it) }
companion object {
fun download(context: Context, subject: DownloadSubject) =

View File

@ -1,5 +1,5 @@
package com.topjohnwu.magisk.model.entity.internal
enum class Configuration {
FLASH, DOWNLOAD
FLASH, DOWNLOAD, UNINSTALL, PATCH
}

View File

@ -29,21 +29,39 @@ open class FlashActivity : MagiskActivity<FlashViewModel, ActivityFlashBinding>(
companion object {
private fun intent(context: Context) = Intent(context, ClassMap[FlashActivity::class.java])
private fun intent(context: Context, file: File) = intent(context).setData(file.toUri())
fun flashMagiskIntent(context: Context, file: File) = intent(context)
.setData(file.toUri())
/* Flashing is understood as installing / flashing magisk itself */
fun flashIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK)
fun flashMagisk(context: Context, file: File) =
context.startActivity(flashMagiskIntent(context, file))
fun flash(context: Context, file: File) =
context.startActivity(flashIntent(context, file))
/* Patching is understood as injecting img files with magisk */
fun flashModuleIntent(context: Context, file: File) = intent(context)
.setData(file.toUri())
fun patchIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_FILE)
fun patch(context: Context, file: File) =
context.startActivity(patchIntent(context, file))
/* Uninstalling is understood as removing magisk entirely */
fun uninstallIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.UNINSTALL)
fun uninstall(context: Context, file: File) =
context.startActivity(uninstallIntent(context, file))
/* Installing is understood as flashing modules / zips */
fun installIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP)
fun flashModule(context: Context, file: File) =
context.startActivity(flashModuleIntent(context, file))
fun install(context: Context, file: File) =
context.startActivity(installIntent(context, file))
}

View File

@ -28,7 +28,7 @@ import java.util.*
class FlashViewModel(
action: String,
uri: Uri?,
uri: Uri?, // FIXME uri is now flashable file, not additional file
private val resources: Resources
) : MagiskViewModel(), FlashResultListener {