Skip to content

Commit e7fda2f

Browse files
committed
allow errors
1 parent fd49972 commit e7fda2f

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

app/src/main/java/com/github/capntrips/kernelflasher/ui/components/SlotCard.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fun SlotCard(
2626
DataCard (
2727
title = title,
2828
button = {
29-
if (!isSlotScreen && !viewModel.hasError) {
29+
if (!isSlotScreen) {
3030
AnimatedVisibility(!viewModel.isRefreshing) {
3131
ViewButton {
3232
navController.navigate("slot${viewModel.slotSuffix}")
@@ -36,36 +36,37 @@ fun SlotCard(
3636
}
3737
) {
3838
val cardWidth = remember { mutableIntStateOf(0) }
39-
if (!viewModel.hasError) {
39+
if (viewModel.sha1 != null) {
4040
DataRow(
4141
label = stringResource(R.string.boot_sha1),
42-
value = viewModel.sha1.substring(0, 8),
42+
value = viewModel.sha1!!.substring(0, 8),
4343
valueStyle = MaterialTheme.typography.titleSmall.copy(
4444
fontFamily = FontFamily.Monospace,
4545
fontWeight = FontWeight.Medium
4646
),
4747
mutableMaxWidth = cardWidth
4848
)
49-
AnimatedVisibility(!viewModel.isRefreshing && viewModel.kernelVersion != null) {
50-
DataRow(
51-
label = stringResource(R.string.kernel_version),
52-
value = if (viewModel.kernelVersion != null) viewModel.kernelVersion!! else "",
53-
mutableMaxWidth = cardWidth,
54-
clickable = true
55-
)
56-
}
57-
if (showDlkm && viewModel.hasVendorDlkm) {
58-
var vendorDlkmValue = stringResource(R.string.not_found)
59-
if (viewModel.isVendorDlkmMapped) {
60-
vendorDlkmValue = if (viewModel.isVendorDlkmMounted) {
61-
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.mounted))
62-
} else {
63-
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.unmounted))
64-
}
49+
}
50+
AnimatedVisibility(!viewModel.isRefreshing && viewModel.kernelVersion != null) {
51+
DataRow(
52+
label = stringResource(R.string.kernel_version),
53+
value = if (viewModel.kernelVersion != null) viewModel.kernelVersion!! else "",
54+
mutableMaxWidth = cardWidth,
55+
clickable = true
56+
)
57+
}
58+
if (showDlkm && viewModel.hasVendorDlkm) {
59+
var vendorDlkmValue = stringResource(R.string.not_found)
60+
if (viewModel.isVendorDlkmMapped) {
61+
vendorDlkmValue = if (viewModel.isVendorDlkmMounted) {
62+
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.mounted))
63+
} else {
64+
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.unmounted))
6565
}
66-
DataRow(stringResource(R.string.vendor_dlkm), vendorDlkmValue, mutableMaxWidth = cardWidth)
6766
}
68-
} else {
67+
DataRow(stringResource(R.string.vendor_dlkm), vendorDlkmValue, mutableMaxWidth = cardWidth)
68+
}
69+
if (viewModel.hasError) {
6970
Row {
7071
DataValue(
7172
value = viewModel.error,

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/main/MainViewModel.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ class MainViewModel(
7171
val initBootA = PartitionUtil.findPartitionBlockDevice(context, "init_boot", "_a")
7272
val initBootB = PartitionUtil.findPartitionBlockDevice(context, "init_boot", "_b")
7373
slotA = SlotViewModel(context, fileSystemManager, navController, _isRefreshing, slotSuffix == "_a", "_a", bootA, initBootA, _backups)
74-
if (slotA.hasError && slotSuffix == "_a") {
75-
_error = slotA.error
76-
}
7774
slotB = SlotViewModel(context, fileSystemManager, navController, _isRefreshing, slotSuffix == "_b", "_b", bootB, initBootB, _backups)
78-
if (slotB.hasError && slotSuffix == "_b") {
79-
_error = slotB.error
80-
}
8175
} else {
8276
val boot = PartitionUtil.findPartitionBlockDevice(context, "boot", "")!!
8377
val initBoot = PartitionUtil.findPartitionBlockDevice(context, "init_boot", "")

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotFlashContent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ import com.github.capntrips.kernelflasher.ui.components.DataCard
3333
import com.github.capntrips.kernelflasher.ui.components.FlashButton
3434
import com.github.capntrips.kernelflasher.ui.components.FlashList
3535
import com.github.capntrips.kernelflasher.ui.components.SlotCard
36+
import kotlinx.serialization.ExperimentalSerializationApi
3637

3738
@ExperimentalAnimationApi
3839
@ExperimentalMaterialApi
3940
@ExperimentalMaterial3Api
4041
@ExperimentalUnitApi
42+
@ExperimentalSerializationApi
4143
@Composable
4244
fun ColumnScope.SlotFlashContent(
4345
viewModel: SlotViewModel,

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class SlotViewModel(
6666
private var inInit = true
6767
private var _error: String? = null
6868

69-
val sha1: String
70-
get() = _sha1!!
69+
val sha1: String?
70+
get() = _sha1
7171
val flashOutput: List<String>
7272
get() = _flashOutput
7373
val uiPrintedOutput: List<String>
@@ -120,12 +120,12 @@ class SlotViewModel(
120120
when (Shell.cmd("$magiskboot cpio ramdisk.cpio test").exec().code) {
121121
0 -> _sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull()
122122
1 -> _sha1 = Shell.cmd("$magiskboot cpio ramdisk.cpio sha1").exec().out.firstOrNull()
123-
else -> log(context, "Invalid ramdisk in boot.img", shouldThrow = true)
123+
else -> _error = "Invalid ramdisk in boot.img"
124124
}
125125
} else if (kernel.exists()) {
126126
_sha1 = Shell.cmd("$magiskboot sha1 $boot").exec().out.firstOrNull()
127127
} else {
128-
log(context, "Invalid boot.img, no ramdisk or kernel found", shouldThrow = true)
128+
_error = "Invalid boot.img, no ramdisk or kernel found"
129129
}
130130
Shell.cmd("$magiskboot cleanup").exec()
131131

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<string name="kernel_name" tools:keep="@string/kernel_name">Kernel Name</string>
99
<string name="kernel_version">Kernel Version</string>
1010
<string name="slot_suffix">Slot Suffix</string>
11-
<string name="slot">Slot</string>
11+
<string name="slot" tools:ignore="MissingTranslation">Slot</string>
1212
<string name="slot_a">Slot A</string>
1313
<string name="slot_b">Slot B</string>
1414
<string name="boot_sha1" tools:ignore="Typos">Boot SHA1</string>

0 commit comments

Comments
 (0)