@@ -543,22 +543,14 @@ private fun Os(c: CreatePartDataHolder) {
543543 }
544544 }
545545 if (expanded == 2 ) {
546- Column (
547- Modifier
548- .fillMaxWidth()) {
549-
550- for (i in 1 .. c.count) {
551- val selectedValue = remember { mutableIntStateOf(c.selVals.getOrElse(i- 1 ) { 1 }) }
552- val intValue = remember { mutableLongStateOf(c.intVals.getOrElse(i- 1 ) { 100L }) }
553- var codeValue by remember { mutableStateOf(c.codeVals.getOrElse(i- 1 ) { " 8305" }) }
554- var idValue by remember { mutableStateOf(c.idVals.getOrElse(i- 1 ) { " " }) }
546+ Column (Modifier .fillMaxWidth()) {
547+ for (i in 0 .. < c.count) {
548+ var selectedValue by remember { mutableIntStateOf(c.selVals.getOrElse(i) { 1 }) }
549+ var intValue by remember { mutableLongStateOf(c.intVals.getOrElse(i) { 100L }) }
550+ var codeValue by remember { mutableStateOf(c.codeVals.getOrElse(i) { " 8305" }) }
551+ var idValue by remember { mutableStateOf(c.idVals.getOrElse(i) { " " }) }
555552 var d by remember { mutableStateOf(false ) }
556- var sparse by remember { mutableStateOf(c.sparseVals.getOrElse(i- 1 ) { false }) }
557- val items = listOf (" bytes" , " percent" )
558- val items2 = listOf (" 0700" , " 8302" , " 8305" )
559- val codes = listOf (stringResource(R .string.portable_part), stringResource(R .string.os_userdata), stringResource(R .string.os_system))
560- val isSelectedItem: (String ) -> Boolean = { items[selectedValue.intValue] == it }
561- val onChangeState: (String ) -> Unit = { selectedValue.intValue = items.indexOf(it) }
553+ var sparse by remember { mutableStateOf(c.sparseVals.getOrElse(i) { false }) }
562554
563555 Card (
564556 modifier = Modifier
@@ -570,79 +562,92 @@ private fun Os(c: CreatePartDataHolder) {
570562 .fillMaxWidth()
571563 .padding(10 .dp)
572564 ) {
573- var sts : Long = - 1
565+ var sizeInSectors : Long = - 1
574566 var remaining = c.endSectorRelative - c.startSectorRelative
575- if (i- 1 < c.selVals.size) {
576- c.selVals[i - 1 ] = selectedValue.intValue
567+ if (i < c.selVals.size) {
568+ c.selVals[i] = selectedValue
577569 } else {
578- c.selVals.add(i - 1 , selectedValue.intValue )
570+ c.selVals.add(i, selectedValue)
579571 }
580- if (i- 1 < c.intVals.size) {
581- c.intVals[i - 1 ] = intValue.longValue
572+ if (i < c.intVals.size) {
573+ c.intVals[i] = intValue
582574 } else {
583- c.intVals.add(i - 1 , intValue.longValue )
575+ c.intVals.add(i, intValue)
584576 }
585- if (i- 1 < c.codeVals.size) {
586- c.codeVals[i - 1 ] = codeValue
577+ if (i < c.codeVals.size) {
578+ c.codeVals[i] = codeValue
587579 } else {
588- c.codeVals.add(i - 1 , codeValue)
580+ c.codeVals.add(i, codeValue)
589581 }
590- if (i- 1 < c.idVals.size) {
591- c.idVals[i - 1 ] = idValue
582+ if (i < c.idVals.size) {
583+ c.idVals[i] = idValue
592584 } else {
593- c.idVals.add(i - 1 , idValue)
585+ c.idVals.add(i, idValue)
594586 }
595- if (i- 1 < c.sparseVals.size) {
596- c.sparseVals[i - 1 ] = sparse
587+ if (i < c.sparseVals.size) {
588+ c.sparseVals[i] = sparse
597589 } else {
598- c.sparseVals.add(i - 1 , sparse)
590+ c.sparseVals.add(i, sparse)
599591 }
600- for (j in 1 .. i) {
601- val k = c.intVals.getOrElse(j- 1 ) { 0L }
602- val l = c.selVals.getOrElse(j- 1 ) { 1 }
603- sts = if (l == 0 /* bytes*/ ) {
592+ for (j in 0 .. i) {
593+ val k = c.intVals.getOrElse(j) { 0L }
594+ val l = c.selVals.getOrElse(j) { 1 }
595+ sizeInSectors = if (l == 0 /* bytes*/ ) {
604596 k / c.meta!! .logicalSectorSizeBytes
605597 } else /* percent*/ {
606598 (BigDecimal (remaining).multiply(BigDecimal (k).divide(BigDecimal (100 )))).toLong()
607599 }
608- remaining - = sts
600+ remaining - = sizeInSectors
609601 }
610- remaining + = sts
602+ remaining + = sizeInSectors
611603
612- Text (text = stringResource(R .string.sector_used, intValue.longValue, items[selectedValue.intValue], sts, remaining))
613- TextField (value = intValue.longValue.toString(), onValueChange = {
604+ val selUnit = stringResource(if (selectedValue == 1 ) R .string.percent else R .string.bytes)
605+ Text (text = stringResource(R .string.sector_used, intValue, selUnit, sizeInSectors, remaining))
606+ TextField (value = intValue.toString(), onValueChange = {
614607 if (it.matches(Regex (" \\ d+" ))) {
615- intValue.longValue = it.toLong()
608+ intValue = it.toLong()
616609 }
617610 }, label = {
618611 Text (stringResource(R .string.size))
619612 })
620613 Row (Modifier .padding(8 .dp)) {
621- items.forEach { item ->
622- Row (
623- verticalAlignment = Alignment .CenterVertically ,
624- modifier = Modifier
625- .selectable(
626- selected = isSelectedItem(item),
627- onClick = { onChangeState(item) },
628- role = Role .RadioButton
629- )
630- .padding(8 .dp)
631- ) {
632- RadioButton (
633- selected = isSelectedItem(item),
634- onClick = null
614+ Row (
615+ verticalAlignment = Alignment .CenterVertically ,
616+ modifier = Modifier
617+ .selectable(
618+ selected = selectedValue == 0 ,
619+ onClick = { selectedValue = 0 },
620+ role = Role .RadioButton
635621 )
636- Text (
637- text = item
622+ .padding(8 .dp)
623+ ) {
624+ RadioButton (
625+ selected = selectedValue == 0 ,
626+ onClick = null
627+ )
628+ Text (text = stringResource(R .string.bytes))
629+ }
630+ Row (
631+ verticalAlignment = Alignment .CenterVertically ,
632+ modifier = Modifier
633+ .selectable(
634+ selected = selectedValue == 1 ,
635+ onClick = { selectedValue = 1 },
636+ role = Role .RadioButton
638637 )
639- }
638+ .padding(8 .dp)
639+ ) {
640+ RadioButton (
641+ selected = selectedValue == 1 ,
642+ onClick = null
643+ )
644+ Text (text = stringResource(R .string.percent))
640645 }
641646 }
642647 ExposedDropdownMenuBox (expanded = d, onExpandedChange = { d = it }) {
643648 TextField (
644649 readOnly = true ,
645- value = codes[items2.indexOf( codeValue)] ,
650+ value = stringResource(partitionTypeCodes.find { it.first == codeValue } !! .second) ,
646651 onValueChange = { },
647652 label = { Text (stringResource(R .string.type)) },
648653 trailingIcon = {
@@ -658,14 +663,13 @@ private fun Os(c: CreatePartDataHolder) {
658663 d = false
659664 }
660665 ) {
661-
662- for (g in codes) {
666+ for (g in partitionTypeCodes) {
663667 DropdownMenuItem (
664668 onClick = {
665- codeValue = items2[codes.indexOf(g)]
669+ codeValue = g.first
666670 d = false
667671 }, text = {
668- Text (text = g )
672+ Text (text = stringResource(g.second) )
669673 }
670674 )
671675 }
@@ -805,7 +809,7 @@ private fun Download(c: CreatePartDataHolder) {
805809 Text (stringResource(R .string.undo))
806810 }
807811 } else {
808- if (c.inetAvailable.containsKey(i) || i == " _install.sh_" ) {
812+ if (i == " _install.sh_" || c.inetAvailable.containsKey(i) ) {
809813 Button (onClick = {
810814 CoroutineScope (Dispatchers .IO ).launch {
811815 try {
0 commit comments