@@ -113,8 +113,9 @@ fun WooShippingLabelCreationScreen(viewModel: WooShippingLabelCreationViewModel)
113113 onEditOriginAddress = viewModel::onEditOriginAddress,
114114 onSelectedRateSortOrderChanged = viewModel::onSelectedRateSortOrderChanged,
115115 onRefreshShippingRates = viewModel::onRefreshShippingRates,
116- customWeightList = viewModel.customWeight,
117- onCustomWeightChange = viewModel::onCustomWeightChange,
116+ weightInputList = viewModel.weightInputsFlow.collectAsState().value,
117+ weightUnit = viewState.weightUnit,
118+ onWeightChange = viewModel::onWeightChange,
118119 uiState = viewState.uiState,
119120 onNavigateBack = viewModel::onNavigateBack,
120121 onEditCustomsClick = viewModel::onEditCustomsClick,
@@ -160,8 +161,9 @@ fun WooShippingLabelCreationScreen(
160161 onSelectPackageClick : () -> Unit ,
161162 onSelectedRateSortOrderChanged : (ShippingSortOption ) -> Unit ,
162163 onRefreshShippingRates : () -> Unit ,
163- onCustomWeightChange : (String ) -> Unit ,
164- customWeightList : List <String >,
164+ weightInputList : List <WooShippingLabelCreationViewModel .WeightInput >,
165+ weightUnit : String ,
166+ onWeightChange : (String ) -> Unit ,
165167 uiState : WooShippingLabelCreationViewModel .UIControlsState ,
166168 onEditCustomsClick : () -> Unit ,
167169 onNavigateBack : () -> Unit ,
@@ -205,8 +207,9 @@ fun WooShippingLabelCreationScreen(
205207 onEditOriginAddress = onEditOriginAddress,
206208 onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged,
207209 onRefreshShippingRates = onRefreshShippingRates,
208- customWeightList = customWeightList,
209- onCustomWeightChange = onCustomWeightChange,
210+ weightInputList = weightInputList,
211+ weightUnit = weightUnit,
212+ onWeightChange = onWeightChange,
210213 uiState = uiState,
211214 onNavigateBack = onNavigateBack,
212215 onEditCustomsClick = onEditCustomsClick,
@@ -260,8 +263,9 @@ private fun LabelCreationScreenWithBottomSheet(
260263 onOriginAddressSelected : (OriginShippingAddress ) -> Unit ,
261264 onSelectedRateSortOrderChanged : (ShippingSortOption ) -> Unit ,
262265 onRefreshShippingRates : () -> Unit ,
263- customWeightList : List <String >,
264- onCustomWeightChange : (String ) -> Unit ,
266+ weightInputList : List <WooShippingLabelCreationViewModel .WeightInput >,
267+ weightUnit : String ,
268+ onWeightChange : (String ) -> Unit ,
265269 uiState : WooShippingLabelCreationViewModel .UIControlsState ,
266270 scaffoldState : BottomSheetScaffoldState ,
267271 onNavigateBack : () -> Unit ,
@@ -403,9 +407,10 @@ private fun LabelCreationScreenWithBottomSheet(
403407 onHazmatNoticeClick = onHazmatNoticeClick,
404408 onEditCustomsClick = onEditCustomsClick,
405409 onSelectPackageClick = onSelectPackageClick,
406- customWeight = customWeightList[uiState.selectedIndex],
410+ weight = weightInputList[uiState.selectedIndex].weight,
411+ weightUnit = weightUnit,
412+ onWeightChange = onWeightChange,
407413 uiState = uiState,
408- onCustomWeightChange = onCustomWeightChange,
409414 onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged,
410415 onRefreshShippingRates = onRefreshShippingRates,
411416 onLabelPaperSizeOptionSelected = onLabelPaperSizeOptionSelected,
@@ -448,9 +453,10 @@ private fun CreateShippingCards(
448453 onHazmatNoticeClick : () -> Unit = {},
449454 onEditCustomsClick : () -> Unit ,
450455 onSelectPackageClick : () -> Unit ,
451- customWeight : String ,
456+ weight : String ,
457+ weightUnit : String ,
458+ onWeightChange : (String ) -> Unit ,
452459 uiState : WooShippingLabelCreationViewModel .UIControlsState ,
453- onCustomWeightChange : (String ) -> Unit ,
454460 onSelectedRateSortOrderChanged : (ShippingSortOption ) -> Unit ,
455461 onRefreshShippingRates : () -> Unit ,
456462 onLabelPaperSizeOptionSelected : (WooShippingLabelPaperSize ) -> Unit ,
@@ -501,11 +507,12 @@ private fun CreateShippingCards(
501507 .padding(16 .dp)
502508 )
503509 PackageCard (
504- modifier = Modifier .padding(16 .dp),
505510 packageSelectionState = shipmentUI.packageSelectionState,
506511 onSelectPackageClick = onSelectPackageClick,
507- customWeight = customWeight,
508- onCustomWeightChange = onCustomWeightChange
512+ weight = weight,
513+ weightUnit = weightUnit,
514+ onWeightChange = onWeightChange,
515+ modifier = Modifier .padding(16 .dp),
509516 )
510517 ShippingRatesSection (
511518 shippingRatesState = shipmentUI.shippingRatesState,
@@ -609,9 +616,10 @@ private fun CustomsCard(
609616@Composable
610617private fun PackageCard (
611618 packageSelectionState : PackageSelectionState ,
612- customWeight : String ,
613619 onSelectPackageClick : () -> Unit ,
614- onCustomWeightChange : (String ) -> Unit ,
620+ weight : String ,
621+ weightUnit : String ,
622+ onWeightChange : (String ) -> Unit ,
615623 modifier : Modifier = Modifier ,
616624) {
617625 when (packageSelectionState) {
@@ -624,10 +632,9 @@ private fun PackageCard(
624632 modifier = modifier,
625633 packageData = packageSelectionState.selectedPackage,
626634 onSelectPackageClick = onSelectPackageClick,
627- defaultWeight = packageSelectionState.defaultWeight,
628- customWeight = customWeight,
629- customWeightUnit = packageSelectionState.weightUnit,
630- onCustomWeightChange = onCustomWeightChange
635+ weight = weight,
636+ weightUnit = weightUnit,
637+ onWeightChange = onWeightChange
631638 )
632639 }
633640}
@@ -685,11 +692,10 @@ private fun SelectPackageCard(
685692@Composable
686693private fun PackageSelectionAvailableCard (
687694 packageData : PackageData ,
688- defaultWeight : String ,
689- customWeight : String ,
690- customWeightUnit : String ,
691695 onSelectPackageClick : () -> Unit ,
692- onCustomWeightChange : (String ) -> Unit ,
696+ weight : String ,
697+ weightUnit : String ,
698+ onWeightChange : (String ) -> Unit ,
693699 modifier : Modifier = Modifier
694700) {
695701 Column (modifier = modifier.background(color = MaterialTheme .colors.surface)) {
@@ -777,21 +783,14 @@ private fun PackageSelectionAvailableCard(
777783 Box (modifier = Modifier .weight(1f )) {
778784 BasicTextField (
779785 modifier = Modifier .fillMaxWidth(),
780- value = customWeight ,
781- onValueChange = onCustomWeightChange ,
786+ value = weight ,
787+ onValueChange = onWeightChange ,
782788 keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .Number ),
783789 textStyle = MaterialTheme .typography.body2.copy(color = MaterialTheme .colors.onSurface),
784790 )
785- if (customWeight.isEmpty()) {
786- Text (
787- text = defaultWeight,
788- style = MaterialTheme .typography.body2,
789- color = colorResource(id = R .color.color_on_surface_disabled)
790- )
791- }
792791 }
793792 Text (
794- text = customWeightUnit ,
793+ text = weightUnit ,
795794 style = MaterialTheme .typography.body2,
796795 color = colorResource(id = R .color.color_on_surface_disabled)
797796 )
@@ -860,8 +859,9 @@ private fun WooShippingLabelCreationScreenPreview() {
860859 onOriginAddressSelected = {},
861860 onRefreshShippingRates = {},
862861 onSelectedRateSortOrderChanged = {},
863- customWeightList = listOf (" " ),
864- onCustomWeightChange = {},
862+ weightInputList = listOf (WooShippingLabelCreationViewModel .WeightInput (weight = " " , autoFilled = true )),
863+ weightUnit = " kg" ,
864+ onWeightChange = {},
865865 onNavigateBack = {},
866866 onEditOriginAddress = {},
867867 uiState = WooShippingLabelCreationViewModel .UIControlsState (
@@ -889,9 +889,10 @@ private fun PackageNotSelectedPreview() {
889889 PackageCard (
890890 modifier = Modifier .padding(16 .dp),
891891 packageSelectionState = NotSelected ,
892- customWeight = " " ,
893892 onSelectPackageClick = {},
894- onCustomWeightChange = {}
893+ weight = " " ,
894+ weightUnit = " kg" ,
895+ onWeightChange = {}
895896 )
896897 }
897898}
@@ -901,22 +902,23 @@ private fun PackageNotSelectedPreview() {
901902private fun PackageSelectedPreview () {
902903 WooThemeWithBackground {
903904 PackageCard (
904- modifier = Modifier .padding(16 .dp),
905905 packageSelectionState = DataAvailable (
906906 selectedPackage = PackageData (
907907 name = " Package 1" ,
908- dimensions = " 10 x 10 x 10 " ,
909- weight = " 1 .5" ,
908+ dimensions = " 1 x 1 x 1 " ,
909+ weight = " 0 .5" ,
910910 isSelected = true ,
911911 isLetter = false ,
912912 id = " 1" ,
913913 ),
914- defaultWeight = " 1" ,
915- weightUnit = " kg" ,
914+ shipmentWeight = " 1.5 " ,
915+ weightUnit = " kg"
916916 ),
917- customWeight = " " ,
918917 onSelectPackageClick = {},
919- onCustomWeightChange = {}
918+ weight = " 1.5" ,
919+ weightUnit = " kg" ,
920+ onWeightChange = {},
921+ modifier = Modifier .padding(16 .dp),
920922 )
921923 }
922924}
0 commit comments