Rename classes and fields
This commit is contained in:
parent
abc5457136
commit
1ed67eed35
@ -3,9 +3,9 @@ package com.topjohnwu.magisk.core
|
|||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.topjohnwu.magisk.core.base.BaseReceiver
|
import com.topjohnwu.magisk.core.base.BaseReceiver
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.core.magiskdb.PolicyDao
|
import com.topjohnwu.magisk.core.magiskdb.PolicyDao
|
||||||
import com.topjohnwu.magisk.core.model.ManagerJson
|
import com.topjohnwu.magisk.core.model.ManagerJson
|
||||||
import com.topjohnwu.magisk.core.su.SuCallbackHandler
|
import com.topjohnwu.magisk.core.su.SuCallbackHandler
|
||||||
@ -51,7 +51,7 @@ open class GeneralReceiver : BaseReceiver() {
|
|||||||
Info.remote = Info.remote.copy(app = it)
|
Info.remote = Info.remote.copy(app = it)
|
||||||
}
|
}
|
||||||
DownloadService(context) {
|
DownloadService(context) {
|
||||||
subject = DownloadSubject.Manager(Configuration.APK.Upgrade)
|
subject = Subject.Manager(Action.APK.Upgrade)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Const.Key.BROADCAST_REBOOT -> reboot()
|
Const.Key.BROADCAST_REBOOT -> reboot()
|
||||||
|
@ -4,9 +4,9 @@ import android.net.Uri
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
|
||||||
sealed class Configuration : Parcelable {
|
sealed class Action : Parcelable {
|
||||||
|
|
||||||
sealed class Flash : Configuration() {
|
sealed class Flash : Action() {
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object Primary : Flash()
|
object Primary : Flash()
|
||||||
@ -16,7 +16,7 @@ sealed class Configuration : Parcelable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class APK : Configuration() {
|
sealed class APK : Action() {
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object Upgrade : APK()
|
object Upgrade : APK()
|
||||||
@ -26,15 +26,15 @@ sealed class Configuration : Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object Download : Configuration()
|
object Download : Action()
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object Uninstall : Configuration()
|
object Uninstall : Action()
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object EnvFix : Configuration()
|
object EnvFix : Action()
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class Patch(val fileUri: Uri) : Configuration()
|
data class Patch(val fileUri: Uri) : Action()
|
||||||
|
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
intent?.getParcelableExtra<DownloadSubject>(ARG_URL)?.let { subject ->
|
intent?.getParcelableExtra<Subject>(ARG_URL)?.let { subject ->
|
||||||
update(subject.notifyID())
|
update(subject.notifyID())
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
@ -67,12 +67,12 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
|
|
||||||
// -- Download logic
|
// -- Download logic
|
||||||
|
|
||||||
private suspend fun DownloadSubject.startDownload() {
|
private suspend fun Subject.startDownload() {
|
||||||
val skip = this is DownloadSubject.Magisk && file.exists() && file.checkSum("MD5", magisk.md5)
|
val skip = this is Subject.Magisk && file.exists() && file.checkSum("MD5", magisk.md5)
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
val stream = service.fetchFile(url).toProgressStream(this)
|
val stream = service.fetchFile(url).toProgressStream(this)
|
||||||
when (this) {
|
when (this) {
|
||||||
is DownloadSubject.Module -> // Download and process on-the-fly
|
is Subject.Module -> // Download and process on-the-fly
|
||||||
stream.toModule(file, service.fetchInstaller().byteStream())
|
stream.toModule(file, service.fetchInstaller().byteStream())
|
||||||
else ->
|
else ->
|
||||||
stream.writeTo(file)
|
stream.writeTo(file)
|
||||||
@ -85,7 +85,7 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ResponseBody.toProgressStream(subject: DownloadSubject): InputStream {
|
private fun ResponseBody.toProgressStream(subject: Subject): InputStream {
|
||||||
val max = contentLength()
|
val max = contentLength()
|
||||||
val total = max.toFloat() / 1048576
|
val total = max.toFloat() / 1048576
|
||||||
val id = subject.notifyID()
|
val id = subject.notifyID()
|
||||||
@ -110,16 +110,16 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
|
|
||||||
// --- Notification managements
|
// --- Notification managements
|
||||||
|
|
||||||
fun DownloadSubject.notifyID() = hashCode()
|
fun Subject.notifyID() = hashCode()
|
||||||
|
|
||||||
private fun notifyFail(subject: DownloadSubject) = lastNotify(subject.notifyID()) {
|
private fun notifyFail(subject: Subject) = lastNotify(subject.notifyID()) {
|
||||||
broadcast(-1f, subject)
|
broadcast(-1f, subject)
|
||||||
it.setContentText(getString(R.string.download_file_error))
|
it.setContentText(getString(R.string.download_file_error))
|
||||||
.setSmallIcon(android.R.drawable.stat_notify_error)
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
||||||
.setOngoing(false)
|
.setOngoing(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyFinish(subject: DownloadSubject) = lastNotify(subject.notifyID()) {
|
private fun notifyFinish(subject: Subject) = lastNotify(subject.notifyID()) {
|
||||||
broadcast(1f, subject)
|
broadcast(1f, subject)
|
||||||
it.setIntent(subject)
|
it.setIntent(subject)
|
||||||
.setContentText(getString(R.string.download_complete))
|
.setContentText(getString(R.string.download_complete))
|
||||||
@ -174,9 +174,9 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
|
|
||||||
// --- Implement custom logic
|
// --- Implement custom logic
|
||||||
|
|
||||||
protected abstract suspend fun onFinish(subject: DownloadSubject, id: Int)
|
protected abstract suspend fun onFinish(subject: Subject, id: Int)
|
||||||
|
|
||||||
protected abstract fun Notification.Builder.setIntent(subject: DownloadSubject)
|
protected abstract fun Notification.Builder.setIntent(subject: Subject)
|
||||||
: Notification.Builder
|
: Notification.Builder
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
@ -184,9 +184,9 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
companion object : KoinComponent {
|
companion object : KoinComponent {
|
||||||
const val ARG_URL = "arg_url"
|
const val ARG_URL = "arg_url"
|
||||||
|
|
||||||
private val progressBroadcast = MutableLiveData<Pair<Float, DownloadSubject>>()
|
private val progressBroadcast = MutableLiveData<Pair<Float, Subject>>()
|
||||||
|
|
||||||
fun observeProgress(owner: LifecycleOwner, callback: (Float, DownloadSubject) -> Unit) {
|
fun observeProgress(owner: LifecycleOwner, callback: (Float, Subject) -> Unit) {
|
||||||
progressBroadcast.value = null
|
progressBroadcast.value = null
|
||||||
progressBroadcast.observe(owner) {
|
progressBroadcast.observe(owner) {
|
||||||
val (progress, subject) = it ?: return@observe
|
val (progress, subject) = it ?: return@observe
|
||||||
@ -194,7 +194,7 @@ abstract class BaseDownloadService : BaseService(), KoinComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun broadcast(progress: Float, subject: DownloadSubject) {
|
private fun broadcast(progress: Float, subject: Subject) {
|
||||||
progressBroadcast.postValue(progress to subject)
|
progressBroadcast.postValue(progress to subject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import android.app.PendingIntent
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.topjohnwu.magisk.core.download.Configuration.*
|
import com.topjohnwu.magisk.core.download.Action.*
|
||||||
import com.topjohnwu.magisk.core.download.Configuration.Flash.Secondary
|
import com.topjohnwu.magisk.core.download.Action.Flash.Secondary
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject.*
|
import com.topjohnwu.magisk.core.download.Subject.*
|
||||||
import com.topjohnwu.magisk.core.intent
|
import com.topjohnwu.magisk.core.intent
|
||||||
import com.topjohnwu.magisk.core.tasks.EnvFixTask
|
import com.topjohnwu.magisk.core.tasks.EnvFixTask
|
||||||
import com.topjohnwu.magisk.ui.flash.FlashFragment
|
import com.topjohnwu.magisk.ui.flash.FlashFragment
|
||||||
@ -20,25 +20,25 @@ open class DownloadService : BaseDownloadService() {
|
|||||||
|
|
||||||
private val context get() = this
|
private val context get() = this
|
||||||
|
|
||||||
override suspend fun onFinish(subject: DownloadSubject, id: Int) = when (subject) {
|
override suspend fun onFinish(subject: Subject, id: Int) = when (subject) {
|
||||||
is Magisk -> subject.onFinish(id)
|
is Magisk -> subject.onFinish(id)
|
||||||
is Module -> subject.onFinish(id)
|
is Module -> subject.onFinish(id)
|
||||||
is Manager -> subject.onFinish(id)
|
is Manager -> subject.onFinish(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun Magisk.onFinish(id: Int) = when (val conf = configuration) {
|
private suspend fun Magisk.onFinish(id: Int) = when (val action = action) {
|
||||||
Uninstall -> FlashFragment.uninstall(file, id)
|
Uninstall -> FlashFragment.uninstall(file, id)
|
||||||
EnvFix -> {
|
EnvFix -> {
|
||||||
cancel(id)
|
cancel(id)
|
||||||
EnvFixTask(file).exec()
|
EnvFixTask(file).exec()
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
is Patch -> FlashFragment.patch(file, conf.fileUri, id)
|
is Patch -> FlashFragment.patch(file, action.fileUri, id)
|
||||||
is Flash -> FlashFragment.flash(file, conf is Secondary, id)
|
is Flash -> FlashFragment.flash(file, action is Secondary, id)
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Module.onFinish(id: Int) = when (configuration) {
|
private fun Module.onFinish(id: Int) = when (action) {
|
||||||
is Flash -> FlashFragment.install(file, id)
|
is Flash -> FlashFragment.install(file, id)
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ open class DownloadService : BaseDownloadService() {
|
|||||||
|
|
||||||
// --- Customize finish notification
|
// --- Customize finish notification
|
||||||
|
|
||||||
override fun Notification.Builder.setIntent(subject: DownloadSubject)
|
override fun Notification.Builder.setIntent(subject: Subject)
|
||||||
= when (subject) {
|
= when (subject) {
|
||||||
is Magisk -> setIntent(subject)
|
is Magisk -> setIntent(subject)
|
||||||
is Module -> setIntent(subject)
|
is Module -> setIntent(subject)
|
||||||
@ -58,21 +58,21 @@ open class DownloadService : BaseDownloadService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun Notification.Builder.setIntent(subject: Magisk)
|
private fun Notification.Builder.setIntent(subject: Magisk)
|
||||||
= when (val conf = subject.configuration) {
|
= when (val action = subject.action) {
|
||||||
Uninstall -> setContentIntent(FlashFragment.uninstallIntent(context, subject.file))
|
Uninstall -> setContentIntent(FlashFragment.uninstallIntent(context, subject.file))
|
||||||
is Flash -> setContentIntent(FlashFragment.flashIntent(context, subject.file, conf is Secondary))
|
is Flash -> setContentIntent(FlashFragment.flashIntent(context, subject.file, action is Secondary))
|
||||||
is Patch -> setContentIntent(FlashFragment.patchIntent(context, subject.file, conf.fileUri))
|
is Patch -> setContentIntent(FlashFragment.patchIntent(context, subject.file, action.fileUri))
|
||||||
else -> setContentIntent(Intent())
|
else -> setContentIntent(Intent())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Notification.Builder.setIntent(subject: Module)
|
private fun Notification.Builder.setIntent(subject: Module)
|
||||||
= when (subject.configuration) {
|
= when (subject.action) {
|
||||||
is Flash -> setContentIntent(FlashFragment.installIntent(context, subject.file))
|
is Flash -> setContentIntent(FlashFragment.installIntent(context, subject.file))
|
||||||
else -> setContentIntent(Intent())
|
else -> setContentIntent(Intent())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Notification.Builder.setIntent(subject: Manager)
|
private fun Notification.Builder.setIntent(subject: Manager)
|
||||||
= when (subject.configuration) {
|
= when (subject.action) {
|
||||||
APK.Upgrade -> setContentIntent(APKInstall.installIntent(context, subject.file))
|
APK.Upgrade -> setContentIntent(APKInstall.installIntent(context, subject.file))
|
||||||
else -> setContentIntent(Intent())
|
else -> setContentIntent(Intent())
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ open class DownloadService : BaseDownloadService() {
|
|||||||
// ---
|
// ---
|
||||||
|
|
||||||
class Builder {
|
class Builder {
|
||||||
lateinit var subject: DownloadSubject
|
lateinit var subject: Subject
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -6,8 +6,8 @@ import com.topjohnwu.magisk.ProcessPhoenix
|
|||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.Configuration.APK.Restore
|
import com.topjohnwu.magisk.core.download.Action.APK.Restore
|
||||||
import com.topjohnwu.magisk.core.download.Configuration.APK.Upgrade
|
import com.topjohnwu.magisk.core.download.Action.APK.Upgrade
|
||||||
import com.topjohnwu.magisk.core.intent
|
import com.topjohnwu.magisk.core.intent
|
||||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||||
import com.topjohnwu.magisk.core.utils.PatchAPK
|
import com.topjohnwu.magisk.core.utils.PatchAPK
|
||||||
@ -66,8 +66,8 @@ private fun DownloadService.restore(apk: File, id: Int) {
|
|||||||
Shell.su("pm install $apk && pm uninstall $packageName").exec()
|
Shell.su("pm install $apk && pm uninstall $packageName").exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun DownloadService.handleAPK(subject: DownloadSubject.Manager) =
|
suspend fun DownloadService.handleAPK(subject: Subject.Manager) =
|
||||||
when (subject.configuration) {
|
when (subject.action) {
|
||||||
is Upgrade -> upgrade(subject.file, subject.notifyID())
|
is Upgrade -> upgrade(subject.file, subject.notifyID())
|
||||||
is Restore -> restore(subject.file, subject.notifyID())
|
is Restore -> restore(subject.file, subject.notifyID())
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,18 @@ import kotlinx.android.parcel.IgnoredOnParcel
|
|||||||
import kotlinx.android.parcel.Parcelize
|
import kotlinx.android.parcel.Parcelize
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
sealed class DownloadSubject : Parcelable {
|
sealed class Subject : Parcelable {
|
||||||
|
|
||||||
abstract val url: String
|
abstract val url: String
|
||||||
abstract val file: File
|
abstract val file: File
|
||||||
|
abstract val action: Action
|
||||||
open val title: String get() = file.name
|
open val title: String get() = file.name
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class Module(
|
class Module(
|
||||||
val module: Repo,
|
val module: Repo,
|
||||||
val configuration: Configuration
|
override val action: Action
|
||||||
) : DownloadSubject() {
|
) : Subject() {
|
||||||
override val url: String get() = module.zipUrl
|
override val url: String get() = module.zipUrl
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
@ -34,8 +35,8 @@ sealed class DownloadSubject : Parcelable {
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
class Manager(
|
class Manager(
|
||||||
val configuration: Configuration.APK
|
override val action: Action.APK
|
||||||
) : DownloadSubject() {
|
) : Subject() {
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
val manager: ManagerJson = Info.remote.app
|
val manager: ManagerJson = Info.remote.app
|
||||||
@ -53,14 +54,13 @@ sealed class DownloadSubject : Parcelable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Magisk : DownloadSubject() {
|
abstract class Magisk : Subject() {
|
||||||
|
|
||||||
abstract val configuration: Configuration
|
|
||||||
val magisk: MagiskJson = Info.remote.magisk
|
val magisk: MagiskJson = Info.remote.magisk
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
private class DownloadInternal(
|
private class Internal(
|
||||||
override val configuration: Configuration
|
override val action: Action
|
||||||
) : Magisk() {
|
) : Magisk() {
|
||||||
override val url: String get() = magisk.link
|
override val url: String get() = magisk.link
|
||||||
override val title: String get() = "Magisk-${magisk.version}(${magisk.versionCode})"
|
override val title: String get() = "Magisk-${magisk.version}(${magisk.versionCode})"
|
||||||
@ -73,7 +73,7 @@ sealed class DownloadSubject : Parcelable {
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
private class Uninstall : Magisk() {
|
private class Uninstall : Magisk() {
|
||||||
override val configuration get() = Configuration.Uninstall
|
override val action get() = Action.Uninstall
|
||||||
override val url: String get() = Info.remote.uninstaller.link
|
override val url: String get() = Info.remote.uninstaller.link
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
@ -84,7 +84,7 @@ sealed class DownloadSubject : Parcelable {
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
private class Download : Magisk() {
|
private class Download : Magisk() {
|
||||||
override val configuration get() = Configuration.Download
|
override val action get() = Action.Download
|
||||||
override val url: String get() = magisk.link
|
override val url: String get() = magisk.link
|
||||||
|
|
||||||
@IgnoredOnParcel
|
@IgnoredOnParcel
|
||||||
@ -94,10 +94,10 @@ sealed class DownloadSubject : Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
operator fun invoke(configuration: Configuration) = when (configuration) {
|
operator fun invoke(config: Action) = when (config) {
|
||||||
Configuration.Download -> Download()
|
Action.Download -> Download()
|
||||||
Configuration.Uninstall -> Uninstall()
|
Action.Uninstall -> Uninstall()
|
||||||
Configuration.EnvFix, is Configuration.Flash, is Configuration.Patch -> DownloadInternal(configuration)
|
Action.EnvFix, is Action.Flash, is Action.Patch -> Internal(config)
|
||||||
else -> throw IllegalArgumentException()
|
else -> throw IllegalArgumentException()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,9 +6,9 @@ import android.content.Intent
|
|||||||
import android.content.IntentFilter
|
import android.content.IntentFilter
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.download.Configuration.EnvFix
|
import com.topjohnwu.magisk.core.download.Action.EnvFix
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject.Magisk
|
import com.topjohnwu.magisk.core.download.Subject.Magisk
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
|
|
||||||
class EnvFixDialog : DialogEvent() {
|
class EnvFixDialog : DialogEvent() {
|
||||||
|
@ -2,9 +2,9 @@ package com.topjohnwu.magisk.events.dialog
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.ktx.res
|
import com.topjohnwu.magisk.ktx.res
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||||
@ -16,7 +16,7 @@ class ManagerInstallDialog : DialogEvent() {
|
|||||||
|
|
||||||
override fun build(dialog: MagiskDialog) {
|
override fun build(dialog: MagiskDialog) {
|
||||||
with(dialog) {
|
with(dialog) {
|
||||||
val subject = DownloadSubject.Manager(Configuration.APK.Upgrade)
|
val subject = Subject.Manager(Action.APK.Upgrade)
|
||||||
|
|
||||||
applyTitle(R.string.repo_install_title.res(R.string.app_name.res()))
|
applyTitle(R.string.repo_install_title.res(R.string.app_name.res()))
|
||||||
applyMessage(R.string.repo_install_msg.res(subject.title))
|
applyMessage(R.string.repo_install_msg.res(subject.title))
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.topjohnwu.magisk.events.dialog
|
package com.topjohnwu.magisk.events.dialog
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.core.model.module.Repo
|
import com.topjohnwu.magisk.core.model.module.Repo
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
|
|
||||||
@ -13,8 +13,8 @@ class ModuleInstallDialog(private val item: Repo) : DialogEvent() {
|
|||||||
with(dialog) {
|
with(dialog) {
|
||||||
|
|
||||||
fun download(install: Boolean) = DownloadService(context) {
|
fun download(install: Boolean) = DownloadService(context) {
|
||||||
val config = if (install) Configuration.Flash.Primary else Configuration.Download
|
val config = if (install) Action.Flash.Primary else Action.Download
|
||||||
subject = DownloadSubject.Module(item, config)
|
subject = Subject.Module(item, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
applyTitle(context.getString(R.string.repo_install_title, item.name))
|
applyTitle(context.getString(R.string.repo_install_title, item.name))
|
||||||
|
@ -3,9 +3,9 @@ package com.topjohnwu.magisk.events.dialog
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
import com.topjohnwu.magisk.view.MagiskDialog
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
@ -48,7 +48,7 @@ class UninstallDialog : DialogEvent() {
|
|||||||
|
|
||||||
private fun completeUninstall() {
|
private fun completeUninstall() {
|
||||||
DownloadService(dialog.context) {
|
DownloadService(dialog.context) {
|
||||||
subject = DownloadSubject.Magisk(Configuration.Uninstall)
|
subject = Subject.Magisk(Action.Uninstall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ import com.topjohnwu.magisk.R
|
|||||||
import com.topjohnwu.magisk.arch.*
|
import com.topjohnwu.magisk.arch.*
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject.Manager
|
import com.topjohnwu.magisk.core.download.Subject.Manager
|
||||||
import com.topjohnwu.magisk.core.model.MagiskJson
|
import com.topjohnwu.magisk.core.model.MagiskJson
|
||||||
import com.topjohnwu.magisk.core.model.ManagerJson
|
import com.topjohnwu.magisk.core.model.ManagerJson
|
||||||
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
||||||
@ -111,7 +111,7 @@ class HomeViewModel(
|
|||||||
}
|
}
|
||||||
}.publish()
|
}.publish()
|
||||||
|
|
||||||
fun onProgressUpdate(progress: Float, subject: DownloadSubject) {
|
fun onProgressUpdate(progress: Float, subject: Subject) {
|
||||||
when (subject) {
|
when (subject) {
|
||||||
is Manager -> stateManagerProgress = progress.times(100f).roundToInt()
|
is Manager -> stateManagerProgress = progress.times(100f).roundToInt()
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ import com.topjohnwu.magisk.BR
|
|||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.arch.BaseViewModel
|
import com.topjohnwu.magisk.arch.BaseViewModel
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.data.repository.StringRepository
|
import com.topjohnwu.magisk.data.repository.StringRepository
|
||||||
import com.topjohnwu.magisk.events.RequestFileEvent
|
import com.topjohnwu.magisk.events.RequestFileEvent
|
||||||
import com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog
|
import com.topjohnwu.magisk.events.dialog.SecondSlotWarningDialog
|
||||||
@ -64,8 +64,8 @@ class InstallViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onProgressUpdate(progress: Float, subject: DownloadSubject) {
|
fun onProgressUpdate(progress: Float, subject: Subject) {
|
||||||
if (subject !is DownloadSubject.Magisk) {
|
if (subject !is Subject.Magisk) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.progress = progress.times(100).roundToInt()
|
this.progress = progress.times(100).roundToInt()
|
||||||
@ -79,16 +79,16 @@ class InstallViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun install() = DownloadService(get()) {
|
fun install() = DownloadService(get()) {
|
||||||
subject = DownloadSubject.Magisk(resolveConfiguration())
|
subject = Subject.Magisk(resolveConfiguration())
|
||||||
}.also { state = State.LOADING }
|
}.also { state = State.LOADING }
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
private fun resolveConfiguration() = when (method) {
|
private fun resolveConfiguration() = when (method) {
|
||||||
R.id.method_download -> Configuration.Download
|
R.id.method_download -> Action.Download
|
||||||
R.id.method_patch -> Configuration.Patch(data!!)
|
R.id.method_patch -> Action.Patch(data!!)
|
||||||
R.id.method_direct -> Configuration.Flash.Primary
|
R.id.method_direct -> Action.Flash.Primary
|
||||||
R.id.method_inactive_slot -> Configuration.Flash.Secondary
|
R.id.method_inactive_slot -> Action.Flash.Secondary
|
||||||
else -> throw IllegalArgumentException("Unknown value")
|
else -> throw IllegalArgumentException("Unknown value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import com.topjohnwu.magisk.BR
|
|||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.arch.*
|
import com.topjohnwu.magisk.arch.*
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.core.model.module.Module
|
import com.topjohnwu.magisk.core.model.module.Module
|
||||||
import com.topjohnwu.magisk.core.tasks.RepoUpdater
|
import com.topjohnwu.magisk.core.tasks.RepoUpdater
|
||||||
import com.topjohnwu.magisk.data.database.RepoByNameDao
|
import com.topjohnwu.magisk.data.database.RepoByNameDao
|
||||||
@ -147,8 +147,8 @@ class ModuleViewModel(
|
|||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
fun onProgressUpdate(progress: Float, subject: DownloadSubject) {
|
fun onProgressUpdate(progress: Float, subject: Subject) {
|
||||||
if (subject !is DownloadSubject.Module)
|
if (subject !is Subject.Module)
|
||||||
return
|
return
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
@ -15,9 +15,9 @@ import com.topjohnwu.magisk.arch.diffListOf
|
|||||||
import com.topjohnwu.magisk.arch.itemBindingOf
|
import com.topjohnwu.magisk.arch.itemBindingOf
|
||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.download.Configuration
|
import com.topjohnwu.magisk.core.download.Action
|
||||||
import com.topjohnwu.magisk.core.download.DownloadService
|
import com.topjohnwu.magisk.core.download.DownloadService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadSubject
|
import com.topjohnwu.magisk.core.download.Subject
|
||||||
import com.topjohnwu.magisk.core.utils.PatchAPK
|
import com.topjohnwu.magisk.core.utils.PatchAPK
|
||||||
import com.topjohnwu.magisk.data.database.RepoDao
|
import com.topjohnwu.magisk.data.database.RepoDao
|
||||||
import com.topjohnwu.magisk.events.AddHomeIconEvent
|
import com.topjohnwu.magisk.events.AddHomeIconEvent
|
||||||
@ -145,7 +145,7 @@ class SettingsViewModel(
|
|||||||
|
|
||||||
private fun restoreManager() {
|
private fun restoreManager() {
|
||||||
DownloadService(get()) {
|
DownloadService(get()) {
|
||||||
subject = DownloadSubject.Manager(Configuration.APK.Restore)
|
subject = Subject.Manager(Action.APK.Restore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user