Minor changes in flash viewmodel

This commit is contained in:
topjohnwu 2020-07-06 21:05:43 -07:00
parent 05cf53fe6f
commit 89e11c9cc8
3 changed files with 25 additions and 59 deletions

View File

@ -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

View File

@ -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<ConsoleItem>()
@ -42,8 +37,7 @@ class FlashViewModel(
val itemBinding = itemBindingOf<ConsoleItem>()
private val outItems = ObservableArrayList<String>()
private val logItems =
Collections.synchronizedList(mutableListOf<String>())
private val logItems = Collections.synchronizedList(mutableListOf<String>())
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()
}
}

View File

@ -41,7 +41,7 @@
</HorizontalScrollView>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
gone="@{!viewModel.loaded || !viewModel.canShowReboot}"
gone="@{!viewModel.loaded || !viewModel.showReboot}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"