From 89e11c9cc8083660ae065f41de8ee0c5a44a4669 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 6 Jul 2020 21:05:43 -0700 Subject: [PATCH] Minor changes in flash viewmodel --- app/build.gradle.kts | 6 -- .../magisk/ui/flash/FlashViewModel.kt | 76 ++++++------------- .../main/res/layout/fragment_flash_md2.xml | 2 +- 3 files changed, 25 insertions(+), 59 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e0832f997..2474cd66e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,3 @@ -import java.util.* - plugins { id("com.android.application") kotlin("android") @@ -8,10 +6,6 @@ plugins { id("androidx.navigation.safeargs.kotlin") } -val props = Properties() -val vKotlin = "1.3.72" -val vNav = "2.3.0" - kapt { correctErrorTypes = true useBuildCache = true diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 3747c5c36..d628f0a86 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -3,9 +3,7 @@ package com.topjohnwu.magisk.ui.flash import android.Manifest import android.content.res.Resources import android.net.Uri -import android.os.Handler import android.view.MenuItem -import androidx.core.os.postDelayed import androidx.databinding.ObservableArrayList import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config @@ -27,14 +25,11 @@ import java.io.File import java.util.* class FlashViewModel( - private val args: FlashFragmentArgs, + args: FlashFragmentArgs, private val resources: Resources -) : BaseViewModel(), - FlashResultListener { - - val canShowReboot = Shell.rootAccess() - val showRestartTitle = KObservableField(false) +) : BaseViewModel(), FlashResultListener { + val showReboot = KObservableField(Shell.rootAccess()) val behaviorText = KObservableField(resources.getString(R.string.flashing)) val adapter = BindingAdapter() @@ -42,8 +37,7 @@ class FlashViewModel( val itemBinding = itemBindingOf() private val outItems = ObservableArrayList() - private val logItems = - Collections.synchronizedList(mutableListOf()) + private val logItems = Collections.synchronizedList(mutableListOf()) init { outItems.sendUpdatesTo(items) { it.map { ConsoleItem(it) } } @@ -58,38 +52,25 @@ class FlashViewModel( private fun startFlashing(installer: Uri, uri: Uri?, action: String) { when (action) { - Const.Value.FLASH_ZIP -> Flashing.Install( - installer, - outItems, - logItems, - this - ).exec() - Const.Value.UNINSTALL -> Flashing.Uninstall( - installer, - outItems, - logItems, - this - ).exec() - Const.Value.FLASH_MAGISK -> MagiskInstaller.Direct( - installer, - outItems, - logItems, - this - ).exec() - Const.Value.FLASH_INACTIVE_SLOT -> MagiskInstaller.SecondSlot( - installer, - outItems, - logItems, - this - ).exec() - Const.Value.PATCH_FILE -> MagiskInstaller.Patch( - installer, - uri ?: return, - outItems, - logItems, - this - ).exec() - else -> backPressed() + Const.Value.FLASH_ZIP -> { + Flashing.Install(installer, outItems, logItems, this).exec() + } + Const.Value.UNINSTALL -> { + showReboot.value = false + Flashing.Uninstall(installer, outItems, logItems, this).exec() + } + Const.Value.FLASH_MAGISK -> { + MagiskInstaller.Direct(installer, outItems, logItems, this).exec() + } + Const.Value.FLASH_INACTIVE_SLOT -> { + MagiskInstaller.SecondSlot(installer, outItems, logItems, this).exec() + } + Const.Value.PATCH_FILE -> { + uri ?: return + showReboot.value = false + MagiskInstaller.Patch(installer, uri, outItems, logItems, this).exec() + } + else -> back() } } @@ -99,12 +80,6 @@ class FlashViewModel( success -> resources.getString(R.string.done) else -> resources.getString(R.string.failure) } - - if (success) { - Handler().postDelayed(500) { - showRestartTitle.value = true - } - } } fun onMenuItemClicked(item: MenuItem): Boolean { @@ -135,7 +110,4 @@ class FlashViewModel( .add() fun restartPressed() = reboot() - - fun backPressed() = back() - -} \ No newline at end of file +} diff --git a/app/src/main/res/layout/fragment_flash_md2.xml b/app/src/main/res/layout/fragment_flash_md2.xml index aa2d61da0..410a8a817 100644 --- a/app/src/main/res/layout/fragment_flash_md2.xml +++ b/app/src/main/res/layout/fragment_flash_md2.xml @@ -41,7 +41,7 @@