Skip to content

Commit

Permalink
fix create part flow hardcoding sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Jan 19, 2025
1 parent 37b481f commit 9c7b876
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 37 deletions.
109 changes: 72 additions & 37 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private fun Shop(c: CreatePartDataHolder) {
throw IllegalStateException("duplicate $id in idNeeded?")
parts.add(Part(l.getLong("size"),
l.getBoolean("isPercent"),
l.getString("type"),
l.optString("type", "8305"),
id, l.getBoolean("needUnsparse")))
if (!idUnneeded.remove(id))
vm.idNeeded.add(id)
Expand Down Expand Up @@ -606,16 +606,47 @@ private fun Os(c: CreatePartDataHolder) {
.fillMaxWidth()
.padding(10.dp)
) {
var sizeInSectors: Long = -1
var remaining = c.endSectorRelative - c.startSectorRelative
for (iPart in c.parts.slice(0..i)) {
sizeInSectors = iPart.resolveSectorSize(c, remaining)
remaining -= sizeInSectors
}
remaining += sizeInSectors
if (c.vm.deviceInfo.metaonsd) {
var sizeInSectors: Long = -1
var remaining = c.endSectorRelative - c.startSectorRelative
for (iPart in c.parts.slice(0..i)) {
sizeInSectors = iPart.resolveSectorSize(c, remaining)
remaining -= sizeInSectors
}
remaining += sizeInSectors

val selUnit =
stringResource(if (part.isPercent) R.string.percent else R.string.bytes)
Text(
text = stringResource(
R.string.sector_used,
part.size,
selUnit,
sizeInSectors,
remaining
)
)
} else {
var sizeInBytes: Long = -1
var remaining = c.desiredSize
for (iPart in c.parts.slice(0..i)) {
sizeInBytes = iPart.resolveBytesSize(c, remaining)
remaining -= sizeInBytes
}
remaining += sizeInBytes

val selUnit = stringResource(if (part.isPercent) R.string.percent else R.string.bytes)
Text(text = stringResource(R.string.sector_used, part.size, selUnit, sizeInSectors, remaining))
val selUnit =
stringResource(if (part.isPercent) R.string.percent else R.string.bytes)
Text(
text = stringResource(
R.string.bytes_used,
part.size,
selUnit,
sizeInBytes,
remaining
)
)
}
TextField(value = part.size.toString(), onValueChange = {
if (it.matches(Regex("\\d+"))) {
part.size = it.toLong()
Expand Down Expand Up @@ -657,34 +688,38 @@ private fun Os(c: CreatePartDataHolder) {
Text(text = stringResource(R.string.percent))
}
}
ExposedDropdownMenuBox(expanded = d, onExpandedChange = { d = it }) {
TextField(
readOnly = true,
value = stringResource(partitionTypeCodes.find { it.first == part.code }!!.second),
onValueChange = { },
label = { Text(stringResource(R.string.type)) },
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(
expanded = d
)
},
colors = ExposedDropdownMenuDefaults.textFieldColors()
)
ExposedDropdownMenu(
if (c.vm.deviceInfo.metaonsd) {
ExposedDropdownMenuBox(
expanded = d,
onDismissRequest = {
d = false
}
) {
for (g in partitionTypeCodes) {
DropdownMenuItem(
onClick = {
part.code = g.first
d = false
}, text = {
Text(text = stringResource(g.second))
}
)
onExpandedChange = { d = it }) {
TextField(
readOnly = true,
value = stringResource(partitionTypeCodes.find { it.first == part.code }!!.second),
onValueChange = { },
label = { Text(stringResource(R.string.type)) },
trailingIcon = {
ExposedDropdownMenuDefaults.TrailingIcon(
expanded = d
)
},
colors = ExposedDropdownMenuDefaults.textFieldColors()
)
ExposedDropdownMenu(
expanded = d,
onDismissRequest = {
d = false
}
) {
for (g in partitionTypeCodes) {
DropdownMenuItem(
onClick = {
part.code = g.first
d = false
}, text = {
Text(text = stringResource(g.second))
}
)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<string name="os_userdata">OS userdata</string>
<string name="os_system">OS system data</string>
<string name="sector_used">Selected value: %d %s (using %d from %d sectors)</string>
<string name="bytes_used">Selected value: %d %s (using %d from %d bytes)</string>
<string name="size">Size</string>
<string name="type">Type</string>
<string name="id">ID</string>
Expand Down

0 comments on commit 9c7b876

Please sign in to comment.