Commit 89e11c9c authored by topjohnwu's avatar topjohnwu

Minor changes in flash viewmodel

parent 05cf53fe
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
......
......@@ -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()
}
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment