Commit 12e00c30 authored by Viktor De Pasquale's avatar Viktor De Pasquale Committed by John Wu

Updated method naming scheme

Added new configurations
Added flashing methods and annotated viewModel's uri as deprecated in function
parent 40b68311
...@@ -17,52 +17,58 @@ open class CompoundDownloadService : SubstrateDownloadService() { ...@@ -17,52 +17,58 @@ open class CompoundDownloadService : SubstrateDownloadService() {
private val context get() = this private val context get() = this
override fun onFinished(file: File, subject: DownloadSubject) { override fun onFinished(file: File, subject: DownloadSubject) = when (subject) {
when (subject) { is DownloadSubject.Magisk -> onFinishedInternal(file, subject)
is DownloadSubject.Magisk -> { is DownloadSubject.Module -> onFinishedInternal(file, subject)
if (subject.configuration == Configuration.FLASH) {
FlashActivity.flashMagisk(this, file)
}
}
is DownloadSubject.Module -> {
if (subject.configuration == Configuration.FLASH) {
FlashActivity.flashModule(this, file)
}
}
}
} }
// --- private fun onFinishedInternal(
file: File,
override fun NotificationCompat.Builder.addActions(file: File, subject: DownloadSubject) = subject: DownloadSubject.Magisk
when (subject) { ) = when (subject.configuration) {
is DownloadSubject.Magisk -> addMagiskActions(file, subject.configuration) Configuration.FLASH -> FlashActivity.flash(this, file)
is DownloadSubject.Module -> addModuleActions(file, subject.configuration) else -> Unit
} }
private fun NotificationCompat.Builder.addMagiskActions( private fun onFinishedInternal(
file: File, file: File,
configuration: Configuration subject: DownloadSubject.Module
) = apply { ) = when (subject.configuration) {
when (configuration) { Configuration.FLASH -> FlashActivity.install(this, file)
Configuration.FLASH -> { else -> Unit
val inner = FlashActivity.flashMagiskIntent(context, file) }
val intent = PendingIntent
.getActivity(context, nextInt(), inner, PendingIntent.FLAG_ONE_SHOT)
setContentIntent(intent) // ---
}
}
override fun NotificationCompat.Builder.addActions(
file: File,
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, file: File,
configuration: Configuration subject: DownloadSubject.Magisk
) = apply { ) = 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 { companion object {
fun download(context: Context, subject: DownloadSubject) = fun download(context: Context, subject: DownloadSubject) =
......
package com.topjohnwu.magisk.model.entity.internal package com.topjohnwu.magisk.model.entity.internal
enum class Configuration { enum class Configuration {
FLASH, DOWNLOAD FLASH, DOWNLOAD, UNINSTALL, PATCH
} }
\ No newline at end of file
...@@ -29,21 +29,39 @@ open class FlashActivity : MagiskActivity<FlashViewModel, ActivityFlashBinding>( ...@@ -29,21 +29,39 @@ open class FlashActivity : MagiskActivity<FlashViewModel, ActivityFlashBinding>(
companion object { companion object {
private fun intent(context: Context) = Intent(context, ClassMap[FlashActivity::class.java]) 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) /* Flashing is understood as installing / flashing magisk itself */
.setData(file.toUri())
fun flashIntent(context: Context, file: File) = intent(context, file)
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK)
fun flashMagisk(context: Context, file: File) = fun flash(context: Context, file: File) =
context.startActivity(flashMagiskIntent(context, file)) context.startActivity(flashIntent(context, file))
/* Patching is understood as injecting img files with magisk */
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 flashModuleIntent(context: Context, file: File) = intent(context) fun installIntent(context: Context, file: File) = intent(context, file)
.setData(file.toUri())
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP) .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP)
fun flashModule(context: Context, file: File) = fun install(context: Context, file: File) =
context.startActivity(flashModuleIntent(context, file)) context.startActivity(installIntent(context, file))
} }
......
...@@ -28,7 +28,7 @@ import java.util.* ...@@ -28,7 +28,7 @@ import java.util.*
class FlashViewModel( class FlashViewModel(
action: String, action: String,
uri: Uri?, uri: Uri?, // FIXME uri is now flashable file, not additional file
private val resources: Resources private val resources: Resources
) : MagiskViewModel(), FlashResultListener { ) : MagiskViewModel(), FlashResultListener {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment