Updated the install flow

Now the binary is downloaded after user selects a method. It also shows download progress as the file's being downloaded
This commit is contained in:
Viktor De Pasquale
2019-10-25 19:13:54 +02:00
parent 8a2872afa4
commit 3cc5cb3123
13 changed files with 461 additions and 159 deletions

View File

@@ -4,6 +4,7 @@ import com.topjohnwu.magisk.redesign.MainViewModel
import com.topjohnwu.magisk.redesign.flash.FlashViewModel
import com.topjohnwu.magisk.redesign.hide.HideViewModel
import com.topjohnwu.magisk.redesign.home.HomeViewModel
import com.topjohnwu.magisk.redesign.install.InstallViewModel
import com.topjohnwu.magisk.redesign.log.LogViewModel
import com.topjohnwu.magisk.redesign.module.ModuleViewModel
import com.topjohnwu.magisk.redesign.request.RequestViewModel
@@ -11,7 +12,6 @@ import com.topjohnwu.magisk.redesign.safetynet.SafetynetViewModel
import com.topjohnwu.magisk.redesign.settings.SettingsViewModel
import com.topjohnwu.magisk.redesign.superuser.SuperuserViewModel
import com.topjohnwu.magisk.redesign.theme.ThemeViewModel
import com.topjohnwu.magisk.ui.install.InstallViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

View File

@@ -128,6 +128,10 @@ abstract class RemoteFileService : NotificationService() {
fun send(progress: Float, subject: DownloadSubject) {
internalProgressBroadcast.postValue(progress to subject)
}
fun reset() {
internalProgressBroadcast.value = null
}
}
}

View File

@@ -6,11 +6,11 @@ import android.os.Build
import com.topjohnwu.magisk.ClassMap
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.Const
import com.topjohnwu.magisk.redesign.install.InstallFragment
import com.topjohnwu.magisk.redesign.safetynet.SafetynetFragment
import com.topjohnwu.magisk.ui.MainActivity
import com.topjohnwu.magisk.ui.hide.MagiskHideFragment
import com.topjohnwu.magisk.ui.home.HomeFragment
import com.topjohnwu.magisk.ui.install.InstallFragment
import com.topjohnwu.magisk.ui.log.LogFragment
import com.topjohnwu.magisk.ui.module.ModulesFragment
import com.topjohnwu.magisk.ui.module.ReposFragment

View File

@@ -8,7 +8,9 @@ import com.topjohnwu.magisk.utils.KObservableField
import io.reactivex.disposables.Disposable
import org.koin.core.KoinComponent
abstract class CompatViewModel : BaseViewModel(), KoinComponent {
abstract class CompatViewModel(
initialState: State = State.LOADING
) : BaseViewModel(initialState), KoinComponent {
val insets = KObservableField(Insets.NONE)

View File

@@ -81,7 +81,7 @@ class HomeViewModel(
init {
RemoteFileService.progressBroadcast.observeForever {
when (it.second) {
when (it?.second) {
is Magisk.Download,
is Magisk.Flash -> stateMagiskProgress.value = it.first.times(100f).roundToInt()
is Manager -> stateManagerProgress.value = it.first.times(100f).roundToInt()

View File

@@ -1,4 +1,4 @@
package com.topjohnwu.magisk.ui.install
package com.topjohnwu.magisk.redesign.install
import android.content.Intent
import android.graphics.Insets

View File

@@ -1,9 +1,10 @@
package com.topjohnwu.magisk.ui.install
package com.topjohnwu.magisk.redesign.install
import android.net.Uri
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.extensions.addOnPropertyChangedCallback
import com.topjohnwu.magisk.model.download.DownloadService
import com.topjohnwu.magisk.model.download.RemoteFileService
import com.topjohnwu.magisk.model.entity.internal.Configuration
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
import com.topjohnwu.magisk.model.events.RequestFileEvent
@@ -12,8 +13,9 @@ import com.topjohnwu.magisk.utils.KObservableField
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.ShellUtils
import org.koin.core.get
import kotlin.math.roundToInt
class InstallViewModel : CompatViewModel() {
class InstallViewModel : CompatViewModel(State.LOADED) {
val isRooted = Shell.rootAccess()
val isAB = isABDevice()
@@ -21,9 +23,23 @@ class InstallViewModel : CompatViewModel() {
val step = KObservableField(0)
val method = KObservableField(-1)
val progress = KObservableField(0)
var data = KObservableField<Uri?>(null)
init {
RemoteFileService.reset()
RemoteFileService.progressBroadcast.observeForever {
val (progress, subject) = it ?: return@observeForever
if (subject !is DownloadSubject.Magisk) {
return@observeForever
}
this.progress.value = progress.times(100).roundToInt()
if (this.progress.value >= 100) {
// this might cause issues if the flash activity launches on top of this sooner
back()
}
}
method.addOnPropertyChangedCallback {
if (method.value == R.id.method_patch) {
RequestFileEvent().publish()
@@ -37,7 +53,7 @@ class InstallViewModel : CompatViewModel() {
fun install() = DownloadService(get()) {
subject = DownloadSubject.Magisk(resolveConfiguration())
}
}.also { state = State.LOADING }
// ---