mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-14 17:27:24 +00:00
Minor changes in flash viewmodel
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import java.util.*
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
@@ -8,10 +6,6 @@ plugins {
|
|||||||
id("androidx.navigation.safeargs.kotlin")
|
id("androidx.navigation.safeargs.kotlin")
|
||||||
}
|
}
|
||||||
|
|
||||||
val props = Properties()
|
|
||||||
val vKotlin = "1.3.72"
|
|
||||||
val vNav = "2.3.0"
|
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
correctErrorTypes = true
|
correctErrorTypes = true
|
||||||
useBuildCache = true
|
useBuildCache = true
|
||||||
|
@@ -3,9 +3,7 @@ package com.topjohnwu.magisk.ui.flash
|
|||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import androidx.core.os.postDelayed
|
|
||||||
import androidx.databinding.ObservableArrayList
|
import androidx.databinding.ObservableArrayList
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
@@ -27,14 +25,11 @@ import java.io.File
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class FlashViewModel(
|
class FlashViewModel(
|
||||||
private val args: FlashFragmentArgs,
|
args: FlashFragmentArgs,
|
||||||
private val resources: Resources
|
private val resources: Resources
|
||||||
) : BaseViewModel(),
|
) : BaseViewModel(), FlashResultListener {
|
||||||
FlashResultListener {
|
|
||||||
|
|
||||||
val canShowReboot = Shell.rootAccess()
|
|
||||||
val showRestartTitle = KObservableField(false)
|
|
||||||
|
|
||||||
|
val showReboot = KObservableField(Shell.rootAccess())
|
||||||
val behaviorText = KObservableField(resources.getString(R.string.flashing))
|
val behaviorText = KObservableField(resources.getString(R.string.flashing))
|
||||||
|
|
||||||
val adapter = BindingAdapter<ConsoleItem>()
|
val adapter = BindingAdapter<ConsoleItem>()
|
||||||
@@ -42,8 +37,7 @@ class FlashViewModel(
|
|||||||
val itemBinding = itemBindingOf<ConsoleItem>()
|
val itemBinding = itemBindingOf<ConsoleItem>()
|
||||||
|
|
||||||
private val outItems = ObservableArrayList<String>()
|
private val outItems = ObservableArrayList<String>()
|
||||||
private val logItems =
|
private val logItems = Collections.synchronizedList(mutableListOf<String>())
|
||||||
Collections.synchronizedList(mutableListOf<String>())
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
outItems.sendUpdatesTo(items) { it.map { ConsoleItem(it) } }
|
outItems.sendUpdatesTo(items) { it.map { ConsoleItem(it) } }
|
||||||
@@ -58,38 +52,25 @@ class FlashViewModel(
|
|||||||
|
|
||||||
private fun startFlashing(installer: Uri, uri: Uri?, action: String) {
|
private fun startFlashing(installer: Uri, uri: Uri?, action: String) {
|
||||||
when (action) {
|
when (action) {
|
||||||
Const.Value.FLASH_ZIP -> Flashing.Install(
|
Const.Value.FLASH_ZIP -> {
|
||||||
installer,
|
Flashing.Install(installer, outItems, logItems, this).exec()
|
||||||
outItems,
|
}
|
||||||
logItems,
|
Const.Value.UNINSTALL -> {
|
||||||
this
|
showReboot.value = false
|
||||||
).exec()
|
Flashing.Uninstall(installer, outItems, logItems, this).exec()
|
||||||
Const.Value.UNINSTALL -> Flashing.Uninstall(
|
}
|
||||||
installer,
|
Const.Value.FLASH_MAGISK -> {
|
||||||
outItems,
|
MagiskInstaller.Direct(installer, outItems, logItems, this).exec()
|
||||||
logItems,
|
}
|
||||||
this
|
Const.Value.FLASH_INACTIVE_SLOT -> {
|
||||||
).exec()
|
MagiskInstaller.SecondSlot(installer, outItems, logItems, this).exec()
|
||||||
Const.Value.FLASH_MAGISK -> MagiskInstaller.Direct(
|
}
|
||||||
installer,
|
Const.Value.PATCH_FILE -> {
|
||||||
outItems,
|
uri ?: return
|
||||||
logItems,
|
showReboot.value = false
|
||||||
this
|
MagiskInstaller.Patch(installer, uri, outItems, logItems, this).exec()
|
||||||
).exec()
|
}
|
||||||
Const.Value.FLASH_INACTIVE_SLOT -> MagiskInstaller.SecondSlot(
|
else -> back()
|
||||||
installer,
|
|
||||||
outItems,
|
|
||||||
logItems,
|
|
||||||
this
|
|
||||||
).exec()
|
|
||||||
Const.Value.PATCH_FILE -> MagiskInstaller.Patch(
|
|
||||||
installer,
|
|
||||||
uri ?: return,
|
|
||||||
outItems,
|
|
||||||
logItems,
|
|
||||||
this
|
|
||||||
).exec()
|
|
||||||
else -> backPressed()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,12 +80,6 @@ class FlashViewModel(
|
|||||||
success -> resources.getString(R.string.done)
|
success -> resources.getString(R.string.done)
|
||||||
else -> resources.getString(R.string.failure)
|
else -> resources.getString(R.string.failure)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
|
||||||
Handler().postDelayed(500) {
|
|
||||||
showRestartTitle.value = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMenuItemClicked(item: MenuItem): Boolean {
|
fun onMenuItemClicked(item: MenuItem): Boolean {
|
||||||
@@ -135,7 +110,4 @@ class FlashViewModel(
|
|||||||
.add()
|
.add()
|
||||||
|
|
||||||
fun restartPressed() = reboot()
|
fun restartPressed() = reboot()
|
||||||
|
}
|
||||||
fun backPressed() = back()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
gone="@{!viewModel.loaded || !viewModel.canShowReboot}"
|
gone="@{!viewModel.loaded || !viewModel.showReboot}"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
|
Reference in New Issue
Block a user