100% functional manager self upgrade

Fix #2929
This commit is contained in:
topjohnwu
2020-08-28 04:46:05 -07:00
parent 7e133b0cf4
commit 01efe7a4ea
17 changed files with 102 additions and 123 deletions
@@ -4,7 +4,7 @@ import android.content.Intent
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.BaseUIFragment
import com.topjohnwu.magisk.core.download.BaseDownloadService
import com.topjohnwu.magisk.core.download.BaseDownloader
import com.topjohnwu.magisk.databinding.FragmentInstallMd2Binding
import com.topjohnwu.magisk.events.RequestFileEvent
import com.topjohnwu.magisk.ktx.coroutineScope
@@ -26,7 +26,7 @@ class InstallFragment : BaseUIFragment<InstallViewModel, FragmentInstallMd2Bindi
// Allow markwon to run in viewmodel scope
binding.releaseNotes.coroutineScope = viewModel.viewModelScope
BaseDownloadService.observeProgress(this, viewModel::onProgressUpdate)
BaseDownloader.observeProgress(this, viewModel::onProgressUpdate)
}
}
@@ -78,17 +78,16 @@ class InstallViewModel(
step = nextStep
}
fun install() = DownloadService(get()) {
subject = Subject.Magisk(resolveConfiguration())
}.also { state = State.LOADING }
fun install() =
DownloadService(get(), Subject.Magisk(resolveAction())).also { state = State.LOADING }
// ---
private fun resolveConfiguration() = when (method) {
private fun resolveAction() = when (method) {
R.id.method_download -> Action.Download
R.id.method_patch -> Action.Patch(data!!)
R.id.method_direct -> Action.Flash.Primary
R.id.method_inactive_slot -> Action.Flash.Secondary
else -> throw IllegalArgumentException("Unknown value")
else -> error("Unknown value")
}
}