From bddd0b37d6345c9cb96a1d1fdc79f33e4c5db3eb Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 12:16:05 -0300 Subject: [PATCH 01/32] Replace WooShippingSavedPackageScreen placeholder code with actual initial implementation --- .../forms/WooShippingSavedPackageScreen.kt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 120209e5dfa..4cb84284a5f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -1,9 +1,30 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel @Composable -fun WooShippingSavedPackageScreen() { - Text("Saved Package Form") +fun WooShippingSavedPackageScreen(viewModel: WooShippingLabelPackageCreationViewModel) { + val viewState = viewModel.viewState.observeAsState() + WooShippingSavedPackageScreen() +} + +@Composable +fun WooShippingSavedPackageScreen( + modifier: Modifier = Modifier +) { + Column( + modifier = modifier + .fillMaxSize() + .padding(16.dp) + ) { + + } } From ebfe847e8fd6c896bfed6649b7a0d68e0e4949c6 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 12:24:32 -0300 Subject: [PATCH 02/32] Introduce PackageData model to WooShippingLabelPackageCreationViewModel --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 9 +++++++++ .../packages/forms/WooShippingSavedPackageScreen.kt | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 836d69570c1..a9a17d67cd6 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -97,6 +97,15 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( val type: PageType ) : Parcelable + @Parcelize + data class PackageData( + val type: PackageType, + val name: String, + val length: String, + val width: String, + val height: String + ) : Parcelable + @Parcelize data class CustomPackageCreationData( val type: PackageType, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 4cb84284a5f..5f837a74bb9 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -3,7 +3,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Modifier From f79c482e71500729c5b055e15b216f9451e71ed5 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 12:27:55 -0300 Subject: [PATCH 03/32] Add Saved packages to ViewState --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index a9a17d67cd6..1a255bf8b2e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -22,7 +22,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( private val _viewState = savedState.getStateFlow( scope = viewModelScope, - initialValue = ViewState(pageTabs, CustomPackageCreationData.EMPTY) + initialValue = ViewState(pageTabs) ) val viewState = _viewState.asLiveData() @@ -88,7 +88,8 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( @Parcelize data class ViewState( val pageTabs: List = emptyList(), - val customPackageCreationData: CustomPackageCreationData + val customPackageCreationData: CustomPackageCreationData = CustomPackageCreationData.EMPTY, + val savedPackages: List = emptyList() ) : Parcelable @Parcelize From 8a4b83149af018402c360ef6ec813b4dd62744c8 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 12:29:16 -0300 Subject: [PATCH 04/32] Wire savedPackages viewState field with Compose code --- .../forms/WooShippingSavedPackageScreen.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 5f837a74bb9..6d9eb507b20 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -8,22 +8,35 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData @Composable fun WooShippingSavedPackageScreen(viewModel: WooShippingLabelPackageCreationViewModel) { val viewState = viewModel.viewState.observeAsState() - WooShippingSavedPackageScreen() + WooShippingSavedPackageScreen( + savedPackages = viewState.value?.savedPackages.orEmpty() + ) } @Composable fun WooShippingSavedPackageScreen( - modifier: Modifier = Modifier + modifier: Modifier = Modifier, + savedPackages: List ) { Column( modifier = modifier .fillMaxSize() .padding(16.dp) ) { + savedPackages.forEach { packageData -> + WooShippingSavedPackageItem(packageData) + } + } +} + +@Composable +fun WooShippingSavedPackageItem(packageData: PackageData) { + Column { } } From 769a3823ca96bc94a842e324b9dff294842421c7 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 13:50:00 -0300 Subject: [PATCH 05/32] Add Preview for WooShippingSavedPackageScreen --- .../forms/WooShippingSavedPackageScreen.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 6d9eb507b20..a655e97049f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -6,9 +6,11 @@ import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType @Composable fun WooShippingSavedPackageScreen(viewModel: WooShippingLabelPackageCreationViewModel) { @@ -40,3 +42,33 @@ fun WooShippingSavedPackageItem(packageData: PackageData) { } } + +@Preview +@Composable +fun WooShippingSavedPackageScreenPreview() { + WooShippingSavedPackageScreen( + savedPackages = listOf( + PackageData( + type = PackageType.ENVELOPE, + name = "Package 1", + length = "10", + width = "10", + height = "10" + ), + PackageData( + type = PackageType.BOX, + name = "Package 2", + length = "20", + width = "20", + height = "20" + ), + PackageData( + type = PackageType.BOX, + name = "Package 3", + length = "30", + width = "30", + height = "30" + ) + ) + ) +} From 3a35b99163579826f0f3e529318ea7af6377ea74 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Tue, 5 Nov 2024 14:05:52 -0300 Subject: [PATCH 06/32] Set basic row UI --- .../WooShippingLabelPackageCreationScreen.kt | 2 +- .../forms/WooShippingSavedPackageScreen.kt | 58 +++++++++++-------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index a2e2d91c9b4..5950b56e1bc 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -40,7 +40,7 @@ fun WooShippingLabelPackageCreationScreen( tabs = viewState.value?.pageTabs.orEmpty(), createCustomPackageScreen = { WooShippingCustomPackageCreationScreen(viewModel) }, createCarrierPackageScreen = { WooShippingCarrierPackageScreen() }, - createSavedPackageScreen = { WooShippingSavedPackageScreen() } + createSavedPackageScreen = { WooShippingSavedPackageScreen(viewModel) } ) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index a655e97049f..337fd04f7bd 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -3,11 +3,14 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.material.Divider +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType @@ -39,36 +42,43 @@ fun WooShippingSavedPackageScreen( @Composable fun WooShippingSavedPackageItem(packageData: PackageData) { Column { - + Text(text = packageData.name) + Text(text = "Type: ${packageData.type}") + Text(text = "Length: ${packageData.length}") + Text(text = "Width: ${packageData.width}") + Text(text = "Height: ${packageData.height}") + Divider() } } @Preview @Composable fun WooShippingSavedPackageScreenPreview() { - WooShippingSavedPackageScreen( - savedPackages = listOf( - PackageData( - type = PackageType.ENVELOPE, - name = "Package 1", - length = "10", - width = "10", - height = "10" - ), - PackageData( - type = PackageType.BOX, - name = "Package 2", - length = "20", - width = "20", - height = "20" - ), - PackageData( - type = PackageType.BOX, - name = "Package 3", - length = "30", - width = "30", - height = "30" + WooThemeWithBackground { + WooShippingSavedPackageScreen( + savedPackages = listOf( + PackageData( + type = PackageType.ENVELOPE, + name = "Package 1", + length = "10", + width = "10", + height = "10" + ), + PackageData( + type = PackageType.BOX, + name = "Package 2", + length = "20", + width = "20", + height = "20" + ), + PackageData( + type = PackageType.BOX, + name = "Package 3", + length = "30", + width = "30", + height = "30" + ) ) ) - ) + } } From 83eae2194b4023c8c8d0d5bbe5babf1f87e98783 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 08:20:33 -0300 Subject: [PATCH 07/32] Update checkbox style in WooShippingSavedPackageScreen --- .../forms/WooShippingSavedPackageScreen.kt | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 337fd04f7bd..66f35a084e3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -1,8 +1,10 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.material.Checkbox import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -10,6 +12,7 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.woocommerce.android.ui.compose.component.SelectionCheck import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData @@ -40,13 +43,23 @@ fun WooShippingSavedPackageScreen( } @Composable -fun WooShippingSavedPackageItem(packageData: PackageData) { +fun WooShippingSavedPackageItem( + packageData: PackageData +) { Column { - Text(text = packageData.name) - Text(text = "Type: ${packageData.type}") - Text(text = "Length: ${packageData.length}") - Text(text = "Width: ${packageData.width}") - Text(text = "Height: ${packageData.height}") + Row { + SelectionCheck( + isSelected = true, + onSelectionChange = {} + ) + Column { + Text(text = packageData.name) + Text(text = "Type: ${packageData.type}") + Text(text = "Length: ${packageData.length}") + Text(text = "Width: ${packageData.width}") + Text(text = "Height: ${packageData.height}") + } + } Divider() } } From a3b4ca5ae4bddfc50d414eaf60143b419939f1bc Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 10:34:24 -0300 Subject: [PATCH 08/32] Introduce better string interpolations for the Saved packages UI --- ...ooShippingLabelPackageCreationViewModel.kt | 6 +++++- .../forms/WooShippingSavedPackageScreen.kt | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 1a255bf8b2e..026b761ddcf 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -102,10 +102,14 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( data class PackageData( val type: PackageType, val name: String, + val description: String, val length: String, val width: String, val height: String - ) : Parcelable + ) : Parcelable { + val dimensionsForDisplay: String + get() = "$length x $width x $height cm" + } @Parcelize data class CustomPackageCreationData( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 66f35a084e3..7be7d1ca51d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -4,11 +4,11 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.material.Checkbox import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -47,17 +47,15 @@ fun WooShippingSavedPackageItem( packageData: PackageData ) { Column { - Row { + Row (verticalAlignment = Alignment.CenterVertically) { SelectionCheck( isSelected = true, onSelectionChange = {} ) Column { + Text(text = packageData.description) Text(text = packageData.name) - Text(text = "Type: ${packageData.type}") - Text(text = "Length: ${packageData.length}") - Text(text = "Width: ${packageData.width}") - Text(text = "Height: ${packageData.height}") + Text(text = packageData.dimensionsForDisplay) } } Divider() @@ -72,21 +70,24 @@ fun WooShippingSavedPackageScreenPreview() { savedPackages = listOf( PackageData( type = PackageType.ENVELOPE, - name = "Package 1", + name = "Small Flat Rate Box", + description = "USPS Priority Mail Flat Rate Boxes", length = "10", width = "10", height = "10" ), PackageData( type = PackageType.BOX, - name = "Package 2", + name = "Small Flat Rate Box", + description = "Custom package", length = "20", width = "20", height = "20" ), PackageData( type = PackageType.BOX, - name = "Package 3", + name = "Small Flat Rate Box", + description = "DHL Express", length = "30", width = "30", height = "30" From c27370f96a46bbec30f97f7479337184aae75e92 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 10:41:13 -0300 Subject: [PATCH 09/32] Adjust WooShippingSavedPackageItem text styles --- .../forms/WooShippingSavedPackageScreen.kt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 7be7d1ca51d..d857c7d47be 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -1,10 +1,12 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material.Divider +import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState @@ -47,15 +49,27 @@ fun WooShippingSavedPackageItem( packageData: PackageData ) { Column { - Row (verticalAlignment = Alignment.CenterVertically) { + Row ( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { SelectionCheck( isSelected = true, onSelectionChange = {} ) Column { - Text(text = packageData.description) - Text(text = packageData.name) - Text(text = packageData.dimensionsForDisplay) + Text( + text = packageData.description, + style = MaterialTheme.typography.caption + ) + Text( + text = packageData.name, + style = MaterialTheme.typography.body1 + ) + Text( + text = packageData.dimensionsForDisplay, + style = MaterialTheme.typography.body2 + ) } } Divider() From 0dd2c9e73e5057534ccee2fe8e68d3ae80929214 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 11:37:03 -0300 Subject: [PATCH 10/32] Finish formatting the WooShippingSavedPackageItem --- .../forms/WooShippingSavedPackageScreen.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index d857c7d47be..c08bb2ff260 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -12,8 +12,10 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.res.colorResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.woocommerce.android.R import com.woocommerce.android.ui.compose.component.SelectionCheck import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel @@ -39,16 +41,20 @@ fun WooShippingSavedPackageScreen( .padding(16.dp) ) { savedPackages.forEach { packageData -> - WooShippingSavedPackageItem(packageData) + WooShippingSavedPackageItem(modifier, packageData) } } } @Composable fun WooShippingSavedPackageItem( + modifier: Modifier, packageData: PackageData ) { - Column { + Column ( + modifier = modifier.padding(top = 8.dp), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { Row ( horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically @@ -57,10 +63,11 @@ fun WooShippingSavedPackageItem( isSelected = true, onSelectionChange = {} ) - Column { + Column (verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( text = packageData.description, - style = MaterialTheme.typography.caption + style = MaterialTheme.typography.caption, + color = colorResource(id = R.color.color_on_surface_disabled) ) Text( text = packageData.name, From eb7efe9b6760d6ade6c429ce50e5286b5cd41237 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 11:55:36 -0300 Subject: [PATCH 11/32] Add selection UI control --- .../WooShippingLabelPackageCreationViewModel.kt | 3 ++- .../packages/forms/WooShippingSavedPackageScreen.kt | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 026b761ddcf..038078462ff 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -105,7 +105,8 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( val description: String, val length: String, val width: String, - val height: String + val height: String, + val isSelected: Boolean ) : Parcelable { val dimensionsForDisplay: String get() = "$length x $width x $height cm" diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index c08bb2ff260..c9ba7a02d88 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -60,7 +60,7 @@ fun WooShippingSavedPackageItem( verticalAlignment = Alignment.CenterVertically ) { SelectionCheck( - isSelected = true, + isSelected = packageData.isSelected, onSelectionChange = {} ) Column (verticalArrangement = Arrangement.spacedBy(4.dp)) { @@ -95,7 +95,8 @@ fun WooShippingSavedPackageScreenPreview() { description = "USPS Priority Mail Flat Rate Boxes", length = "10", width = "10", - height = "10" + height = "10", + isSelected = true ), PackageData( type = PackageType.BOX, @@ -103,7 +104,8 @@ fun WooShippingSavedPackageScreenPreview() { description = "Custom package", length = "20", width = "20", - height = "20" + height = "20", + isSelected = false ), PackageData( type = PackageType.BOX, @@ -111,7 +113,8 @@ fun WooShippingSavedPackageScreenPreview() { description = "DHL Express", length = "30", width = "30", - height = "30" + height = "30", + isSelected = false ) ) ) From e2aff996a9618de00e22cf8074a86fd3dce43c53 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:05:00 -0300 Subject: [PATCH 12/32] Introduce Saved package selection control to WooShippingLabelPackageCreationViewModel --- .../WooShippingLabelPackageCreationViewModel.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 038078462ff..4dd31e6ffb4 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -42,6 +42,16 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( ) ) + fun onSavedPackageSelected(packageData: PackageData) { + _viewState.update { viewState -> + viewState.savedPackages + .filter { it != packageData } + .map { it.copy(isSelected = false) } + .let { it + packageData.copy(isSelected = true) } + .let { viewState.copy(savedPackages = it) } + } + } + fun onAddPackageClick() { triggerEvent(PackageSelected(_viewState.value.customPackageCreationData)) } From 32cf5266fbf5c7e9f42709d9737e44701d997c7f Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:18:11 -0300 Subject: [PATCH 13/32] Introduce basic FetchSavedPackagesFromStore --- .../packages/FetchSavedPackagesFromStore.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt new file mode 100644 index 00000000000..10f71b10da6 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt @@ -0,0 +1,9 @@ +package com.woocommerce.android.ui.orders.wooshippinglabels.packages + +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData + +class FetchSavedPackagesFromStore { + operator fun invoke(): List { + return emptyList() + } +} From ae88f6eb137aed2ee55a191cf7fd0f1b2d8c0d17 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:18:33 -0300 Subject: [PATCH 14/32] Trigger Saved package fetching operation when starting the ViewModel --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 4dd31e6ffb4..5fb06e4d53e 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -17,7 +17,8 @@ import javax.inject.Inject @HiltViewModel class WooShippingLabelPackageCreationViewModel @Inject constructor( savedState: SavedStateHandle, - private val resourceProvider: ResourceProvider + private val resourceProvider: ResourceProvider, + private val fetchSavedPackages: FetchSavedPackagesFromStore ) : ScopedViewModel(savedState) { private val _viewState = savedState.getStateFlow( @@ -42,6 +43,12 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( ) ) + init { + _viewState.update { viewState -> + viewState.copy(savedPackages = fetchSavedPackages()) + } + } + fun onSavedPackageSelected(packageData: PackageData) { _viewState.update { viewState -> viewState.savedPackages From 48bfd153b6cfc7dbcc45f5c10db962ea49049ac3 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:24:32 -0300 Subject: [PATCH 15/32] Update WooShippingLabelPackageCreationViewModelTest with selection coverage --- ...ippingLabelPackageCreationViewModelTest.kt | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index f5ab1b3e7fa..ba6826e25dc 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -3,6 +3,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages import androidx.lifecycle.SavedStateHandle import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreationData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageSelected import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog @@ -14,6 +15,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test +import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -21,8 +23,8 @@ import org.mockito.kotlin.whenever class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { private lateinit var sut: WooShippingLabelPackageCreationViewModel - private val savedStateHandle: SavedStateHandle = SavedStateHandle() private val resourceProvider: ResourceProvider = mock() + private val fetchSavedPackages: FetchSavedPackagesFromStore = mock() @Before fun setUp() { @@ -35,7 +37,9 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { whenever( resourceProvider.getString(R.string.woo_shipping_labels_package_creation_tab_saved) ).thenReturn("Saved") - sut = WooShippingLabelPackageCreationViewModel(savedStateHandle, resourceProvider) + + whenever(fetchSavedPackages()).thenReturn(emptyList()) + sut = WooShippingLabelPackageCreationViewModel(SavedStateHandle(), resourceProvider, fetchSavedPackages) } @Test @@ -124,4 +128,38 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { assertThat(lastViewState?.customPackageCreationData?.saveAsTemplate).isEqualTo(newSaveAsTemplate) } + + @Test + fun `onSavedPackageSelected selects only one package at a time`() = testBlocking { + var lastViewState: ViewState? = null + sut.viewState.observeForever { lastViewState = it } + + val package1 = PackageData( + type = PackageType.BOX, + name = "Package 1", + description = "Description 1", + length = "10", + width = "10", + height = "10", + isSelected = false + ) + val package2 = PackageData( + type = PackageType.ENVELOPE, + name = "Package 2", + description = "Description 2", + length = "20", + width = "20", + height = "20", + isSelected = false + ) + whenever(fetchSavedPackages()).thenReturn(listOf(package1, package2)) + + sut.onSavedPackageSelected(package1) + + val selectedPackages = lastViewState?.savedPackages?.filter { it.isSelected } + + assertThat(selectedPackages).isNotNull + assertThat(selectedPackages).size().isEqualTo(1) + assertThat(selectedPackages?.first()).isEqualTo(package1.copy(isSelected = true)) + } } From 89bbd257c0e7caa11226e4d463a564c74653c0aa Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:26:14 -0300 Subject: [PATCH 16/32] Rename onAddPackageClick to onAddCustomPackageClick --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 4 +++- .../packages/forms/WooShippingCustomPackageScreen.kt | 2 +- .../packages/WooShippingLabelPackageCreationViewModelTest.kt | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 5fb06e4d53e..5aef1e6c852 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -59,10 +59,12 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( } } - fun onAddPackageClick() { + fun onAddCustomPackageClick() { triggerEvent(PackageSelected(_viewState.value.customPackageCreationData)) } + + fun onPackageTypeSpinnerClick() { triggerEvent(ShowPackageTypeDialog(_viewState.value.customPackageCreationData.type)) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt index 8240ffada01..f00cd17f81f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt @@ -37,7 +37,7 @@ fun WooShippingCustomPackageCreationScreen(viewModel: WooShippingLabelPackageCre packageLength = viewState?.customPackageCreationData?.length.orEmpty(), packageWidth = viewState?.customPackageCreationData?.width.orEmpty(), isAddPackageEnabled = viewState?.customPackageCreationData?.isValid ?: false, - onAddPackageClick = viewModel::onAddPackageClick, + onAddPackageClick = viewModel::onAddCustomPackageClick, onPackageTypeClick = viewModel::onPackageTypeSpinnerClick, onLengthChange = viewModel::onLengthChange, onWidthChange = viewModel::onWidthChange, diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index ba6826e25dc..14a8fc1e407 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -15,7 +15,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test -import org.mockito.kotlin.any import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -61,7 +60,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { sut.onSavePackageChanged(true) sut.onPackageTypeSelected(PackageType.ENVELOPE) - sut.onAddPackageClick() + sut.onAddCustomPackageClick() assertThat(lastEvent).isEqualTo(PackageSelected(customPackageData)) } From cbfd0bbf3b14adf93c4673768f5f9d6702a8081e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 12:54:15 -0300 Subject: [PATCH 17/32] Fix missing Dagger injection from FetchSavedPackagesFromStore --- .../wooshippinglabels/packages/FetchSavedPackagesFromStore.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt index 10f71b10da6..7ef26503a29 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt @@ -1,8 +1,9 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData +import javax.inject.Inject -class FetchSavedPackagesFromStore { +class FetchSavedPackagesFromStore @Inject constructor() { operator fun invoke(): List { return emptyList() } From e2dddfa7994ef90eba09a66eab1a8b2b8eb8d62a Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 13:21:08 -0300 Subject: [PATCH 18/32] Refactor WooShippingLabelPackageCreationViewModel to differentiate Custom for Saved package selection --- ...ooShippingLabelPackageCreationViewModel.kt | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 5aef1e6c852..2730477b21d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -45,25 +45,28 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( init { _viewState.update { viewState -> - viewState.copy(savedPackages = fetchSavedPackages()) + viewState.copy(savedPackageSelection = SavedPackageSelection(fetchSavedPackages())) } } fun onSavedPackageSelected(packageData: PackageData) { _viewState.update { viewState -> - viewState.savedPackages + viewState.savedPackageSelection.packages .filter { it != packageData } .map { it.copy(isSelected = false) } - .let { it + packageData.copy(isSelected = true) } - .let { viewState.copy(savedPackages = it) } + .let { SavedPackageSelection(it + packageData.copy(isSelected = true)) } + .let { viewState.copy(savedPackageSelection = it) } } } - fun onAddCustomPackageClick() { - triggerEvent(PackageSelected(_viewState.value.customPackageCreationData)) + fun onAddSavedPackageClick() { + _viewState.value.savedPackageSelection.packages.find { it.isSelected } + ?.let { triggerEvent(SavedPackageSelected(it)) } } - + fun onAddCustomPackageClick() { + triggerEvent(CustomPackageCreated(_viewState.value.customPackageCreationData)) + } fun onPackageTypeSpinnerClick() { triggerEvent(ShowPackageTypeDialog(_viewState.value.customPackageCreationData.type)) @@ -108,7 +111,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( data class ViewState( val pageTabs: List = emptyList(), val customPackageCreationData: CustomPackageCreationData = CustomPackageCreationData.EMPTY, - val savedPackages: List = emptyList() + val savedPackageSelection: SavedPackageSelection = SavedPackageSelection(emptyList()) ) : Parcelable @Parcelize @@ -131,6 +134,14 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( get() = "$length x $width x $height cm" } + @Parcelize + data class SavedPackageSelection( + val packages: List + ): Parcelable { + val hasSelection: Boolean + get() = packages.find { it.isSelected } != null + } + @Parcelize data class CustomPackageCreationData( val type: PackageType, @@ -164,6 +175,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( ENVELOPE(R.string.woo_shipping_labels_package_creation_envelope_type) } - data class PackageSelected(val packageData: CustomPackageCreationData) : MultiLiveEvent.Event() + data class SavedPackageSelected(val packageData: PackageData) : MultiLiveEvent.Event() + data class CustomPackageCreated(val packageData: CustomPackageCreationData) : MultiLiveEvent.Event() data class ShowPackageTypeDialog(val currentSelection: PackageType) : MultiLiveEvent.Event() } From ee5e9028175405835590204e57b540a51ea0a85e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 13:24:09 -0300 Subject: [PATCH 19/32] Introduce Add Package button and logic to WooShippingSavedPackageScreen --- .../forms/WooShippingSavedPackageScreen.kt | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index c9ba7a02d88..fb500e38225 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -4,7 +4,9 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.material.Button import androidx.compose.material.Divider import androidx.compose.material.MaterialTheme import androidx.compose.material.Text @@ -13,6 +15,7 @@ import androidx.compose.runtime.livedata.observeAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.woocommerce.android.R @@ -26,22 +29,36 @@ import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingL fun WooShippingSavedPackageScreen(viewModel: WooShippingLabelPackageCreationViewModel) { val viewState = viewModel.viewState.observeAsState() WooShippingSavedPackageScreen( - savedPackages = viewState.value?.savedPackages.orEmpty() + savedPackages = viewState.value?.savedPackageSelection?.packages.orEmpty(), + isAddPackageEnabled = viewState.value?.savedPackageSelection?.hasSelection ?: false, + onAddPackageClick = viewModel::onAddSavedPackageClick + ) } @Composable fun WooShippingSavedPackageScreen( modifier: Modifier = Modifier, - savedPackages: List + savedPackages: List, + isAddPackageEnabled: Boolean, + onAddPackageClick: () -> Unit ) { Column( modifier = modifier .fillMaxSize() .padding(16.dp) ) { - savedPackages.forEach { packageData -> - WooShippingSavedPackageItem(modifier, packageData) + Column(modifier = modifier.weight(1f)) { + savedPackages.forEach { packageData -> + WooShippingSavedPackageItem(modifier, packageData) + } + } + Button( + modifier = modifier.fillMaxWidth(), + enabled = isAddPackageEnabled, + onClick = onAddPackageClick + ) { + Text(stringResource(id = R.string.woo_shipping_labels_package_creation_add_package)) } } } @@ -116,7 +133,9 @@ fun WooShippingSavedPackageScreenPreview() { height = "30", isSelected = false ) - ) + ), + isAddPackageEnabled = true, + onAddPackageClick = {} ) } } From c0a6526877867b2e85cc7b2d9e43a6b71cbdb27c Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 13:34:42 -0300 Subject: [PATCH 20/32] Fix WooShippingLabelPackageCreationViewModelTest build errors --- .../WooShippingLabelPackageCreationViewModelTest.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index 14a8fc1e407..9e6e284a1c6 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.SavedStateHandle import com.woocommerce.android.R import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreationData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageSelected +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreated import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ViewState @@ -62,7 +62,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { sut.onAddCustomPackageClick() - assertThat(lastEvent).isEqualTo(PackageSelected(customPackageData)) + assertThat(lastEvent).isEqualTo(CustomPackageCreated(customPackageData)) } @Test @@ -131,8 +131,6 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { @Test fun `onSavedPackageSelected selects only one package at a time`() = testBlocking { var lastViewState: ViewState? = null - sut.viewState.observeForever { lastViewState = it } - val package1 = PackageData( type = PackageType.BOX, name = "Package 1", @@ -153,10 +151,11 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { ) whenever(fetchSavedPackages()).thenReturn(listOf(package1, package2)) + sut = WooShippingLabelPackageCreationViewModel(SavedStateHandle(), resourceProvider, fetchSavedPackages) + sut.viewState.observeForever { lastViewState = it } sut.onSavedPackageSelected(package1) - val selectedPackages = lastViewState?.savedPackages?.filter { it.isSelected } - + val selectedPackages = lastViewState?.savedPackageSelection?.packages?.filter { it.isSelected } assertThat(selectedPackages).isNotNull assertThat(selectedPackages).size().isEqualTo(1) assertThat(selectedPackages?.first()).isEqualTo(package1.copy(isSelected = true)) From 16809893c12a7e04439fd93e819f5376c528a76f Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 6 Nov 2024 14:34:44 -0300 Subject: [PATCH 21/32] Fix lint issues --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 2 +- .../packages/forms/WooShippingSavedPackageScreen.kt | 6 +++--- .../WooShippingLabelPackageCreationViewModelTest.kt | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 2730477b21d..7dc68a0e02d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -137,7 +137,7 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( @Parcelize data class SavedPackageSelection( val packages: List - ): Parcelable { + ) : Parcelable { val hasSelection: Boolean get() = packages.find { it.isSelected } != null } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index fb500e38225..9606a785991 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -68,11 +68,11 @@ fun WooShippingSavedPackageItem( modifier: Modifier, packageData: PackageData ) { - Column ( + Column( modifier = modifier.padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(16.dp) ) { - Row ( + Row( horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically ) { @@ -80,7 +80,7 @@ fun WooShippingSavedPackageItem( isSelected = packageData.isSelected, onSelectionChange = {} ) - Column (verticalArrangement = Arrangement.spacedBy(4.dp)) { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( text = packageData.description, style = MaterialTheme.typography.caption, diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index 9e6e284a1c6..756549c6023 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -2,9 +2,9 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages import androidx.lifecycle.SavedStateHandle import com.woocommerce.android.R +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreated import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreationData import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.CustomPackageCreated import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ShowPackageTypeDialog import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.ViewState From 8c5c08f6f239daf555ce815d77cfa99a08728b9d Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 10:10:53 -0300 Subject: [PATCH 22/32] Add container for the Add Package button --- .../forms/WooShippingSavedPackageScreen.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 9606a785991..fedc01f0311 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -46,19 +46,26 @@ fun WooShippingSavedPackageScreen( Column( modifier = modifier .fillMaxSize() - .padding(16.dp) ) { - Column(modifier = modifier.weight(1f)) { + Column(modifier = modifier + .weight(1f) + .padding(16.dp) + ) { savedPackages.forEach { packageData -> WooShippingSavedPackageItem(modifier, packageData) } } - Button( - modifier = modifier.fillMaxWidth(), - enabled = isAddPackageEnabled, - onClick = onAddPackageClick - ) { - Text(stringResource(id = R.string.woo_shipping_labels_package_creation_add_package)) + Column { + Divider() + Button( + modifier = modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + enabled = isAddPackageEnabled, + onClick = onAddPackageClick + ) { + Text(stringResource(id = R.string.woo_shipping_labels_package_creation_add_package)) + } } } } From 8b192d338905c7953f6cf6b7f56b8176c604e1c4 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 11:34:49 -0300 Subject: [PATCH 23/32] Fix incorrect vertical scroll placement --- .../WooShippingLabelPackageCreationScreen.kt | 43 ++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 5950b56e1bc..9828f08a7fc 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -6,8 +6,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll import androidx.compose.material.MaterialTheme import androidx.compose.material.Scaffold import androidx.compose.material.Tab @@ -23,6 +21,8 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageTab import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CARRIER import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PageType.CUSTOM @@ -83,7 +83,6 @@ fun WooShippingLabelPackageCreationScreen( .background(MaterialTheme.colors.surface) .padding(paddingValues) .fillMaxSize() - .verticalScroll(rememberScrollState()) ) { currentPageIndex -> when (tabs[currentPageIndex].type) { CUSTOM -> createCustomPackageScreen() @@ -120,8 +119,42 @@ fun WooShippingLabelsPackageCreationScreenPreview() { onSavePackageChanged = { } ) }, - createCarrierPackageScreen = { }, - createSavedPackageScreen = { } + createSavedPackageScreen = { + WooShippingSavedPackageScreen( + savedPackages = listOf( + PackageData( + type = PackageType.ENVELOPE, + name = "Small Flat Rate Box", + description = "USPS Priority Mail Flat Rate Boxes", + length = "10", + width = "10", + height = "10", + isSelected = true + ), + PackageData( + type = PackageType.BOX, + name = "Small Flat Rate Box", + description = "Custom package", + length = "20", + width = "20", + height = "20", + isSelected = false + ), + PackageData( + type = PackageType.BOX, + name = "Small Flat Rate Box", + description = "DHL Express", + length = "30", + width = "30", + height = "30", + isSelected = false + ) + ), + isAddPackageEnabled = true, + onAddPackageClick = { } + ) + }, + createCarrierPackageScreen = { } ) } } From 80f35d3e48c1622c93f02c8d85ef4893e0ec9f2a Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 11:36:08 -0300 Subject: [PATCH 24/32] Move vertical scroll state control to subscreens --- .../packages/forms/WooShippingCustomPackageScreen.kt | 3 +++ .../packages/forms/WooShippingSavedPackageScreen.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt index f00cd17f81f..83bcb39f439 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingCustomPackageScreen.kt @@ -6,7 +6,9 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Button import androidx.compose.material.Checkbox import androidx.compose.material.Text @@ -65,6 +67,7 @@ fun WooShippingCustomPackageCreationScreen( modifier = modifier .fillMaxSize() .padding(16.dp) + .verticalScroll(rememberScrollState()) ) { Column( modifier = modifier.weight(1f), diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index fedc01f0311..ae6bd3a7429 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Button import androidx.compose.material.Divider import androidx.compose.material.MaterialTheme @@ -50,6 +52,7 @@ fun WooShippingSavedPackageScreen( Column(modifier = modifier .weight(1f) .padding(16.dp) + .verticalScroll(rememberScrollState()) ) { savedPackages.forEach { packageData -> WooShippingSavedPackageItem(modifier, packageData) From 23ff3d1dee0827b4fcb80433f6f52f021f22b806 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 11:48:14 -0300 Subject: [PATCH 25/32] Add mocked response to FetchSavedPackagesFromStore --- .../packages/FetchSavedPackagesFromStore.kt | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt index 7ef26503a29..454cf74a63c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/FetchSavedPackagesFromStore.kt @@ -1,10 +1,41 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageData +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationViewModel.PackageType import javax.inject.Inject class FetchSavedPackagesFromStore @Inject constructor() { operator fun invoke(): List { - return emptyList() + // This is a mocked response. + // When fully implemented, this will be sorted from the Shipping plugin API. + return listOf( + PackageData( + type = PackageType.ENVELOPE, + name = "Small Flat Rate Box", + description = "USPS Priority Mail Flat Rate Boxes", + length = "10", + width = "10", + height = "10", + isSelected = true + ), + PackageData( + type = PackageType.BOX, + name = "Small Flat Rate Box", + description = "Custom package", + length = "20", + width = "20", + height = "20", + isSelected = false + ), + PackageData( + type = PackageType.BOX, + name = "Small Flat Rate Box", + description = "DHL Express", + length = "30", + width = "30", + height = "30", + isSelected = false + ) + ) } } From 7bc1aba62145844dccb4d78cb3ae908d7a03f005 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 12:13:08 -0300 Subject: [PATCH 26/32] Wire the selection event to the respective Package Data --- .../WooShippingLabelPackageCreationScreen.kt | 3 ++- ...ooShippingLabelPackageCreationViewModel.kt | 4 +-- .../forms/WooShippingSavedPackageScreen.kt | 25 +++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 9828f08a7fc..07ba7072373 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -151,7 +151,8 @@ fun WooShippingLabelsPackageCreationScreenPreview() { ) ), isAddPackageEnabled = true, - onAddPackageClick = { } + onAddPackageClick = { }, + onSavedPackageSelected = { _, _ -> } ) }, createCarrierPackageScreen = { } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 7dc68a0e02d..88e7793e2bf 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -49,12 +49,12 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( } } - fun onSavedPackageSelected(packageData: PackageData) { + fun onSavedPackageSelected(packageData: PackageData, isSelected: Boolean) { _viewState.update { viewState -> viewState.savedPackageSelection.packages .filter { it != packageData } .map { it.copy(isSelected = false) } - .let { SavedPackageSelection(it + packageData.copy(isSelected = true)) } + .let { SavedPackageSelection(it + packageData.copy(isSelected = isSelected)) } .let { viewState.copy(savedPackageSelection = it) } } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index ae6bd3a7429..383af2e70eb 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.packages.forms +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -33,7 +34,8 @@ fun WooShippingSavedPackageScreen(viewModel: WooShippingLabelPackageCreationView WooShippingSavedPackageScreen( savedPackages = viewState.value?.savedPackageSelection?.packages.orEmpty(), isAddPackageEnabled = viewState.value?.savedPackageSelection?.hasSelection ?: false, - onAddPackageClick = viewModel::onAddSavedPackageClick + onAddPackageClick = viewModel::onAddSavedPackageClick, + onSavedPackageSelected = viewModel::onSavedPackageSelected ) } @@ -43,7 +45,8 @@ fun WooShippingSavedPackageScreen( modifier: Modifier = Modifier, savedPackages: List, isAddPackageEnabled: Boolean, - onAddPackageClick: () -> Unit + onAddPackageClick: () -> Unit, + onSavedPackageSelected: (PackageData, Boolean) -> Unit ) { Column( modifier = modifier @@ -55,7 +58,11 @@ fun WooShippingSavedPackageScreen( .verticalScroll(rememberScrollState()) ) { savedPackages.forEach { packageData -> - WooShippingSavedPackageItem(modifier, packageData) + WooShippingSavedPackageItem( + modifier, + packageData, + onSavedPackageSelected + ) } } Column { @@ -76,10 +83,13 @@ fun WooShippingSavedPackageScreen( @Composable fun WooShippingSavedPackageItem( modifier: Modifier, - packageData: PackageData + packageData: PackageData, + onPackageSelected: (PackageData, Boolean) -> Unit ) { Column( - modifier = modifier.padding(top = 8.dp), + modifier = modifier + .padding(top = 8.dp) + .clickable { onPackageSelected(packageData, packageData.isSelected.not()) }, verticalArrangement = Arrangement.spacedBy(16.dp) ) { Row( @@ -88,7 +98,7 @@ fun WooShippingSavedPackageItem( ) { SelectionCheck( isSelected = packageData.isSelected, - onSelectionChange = {} + onSelectionChange = { onPackageSelected(packageData, it) } ) Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( @@ -145,7 +155,8 @@ fun WooShippingSavedPackageScreenPreview() { ) ), isAddPackageEnabled = true, - onAddPackageClick = {} + onAddPackageClick = {}, + onSavedPackageSelected = { _, _ -> } ) } } From 9191a51c24b72bed097bf92303dff5f56c696498 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 12:23:36 -0300 Subject: [PATCH 27/32] Fix how the Saved package selection logic works --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 88e7793e2bf..89b5d3118da 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -52,9 +52,10 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( fun onSavedPackageSelected(packageData: PackageData, isSelected: Boolean) { _viewState.update { viewState -> viewState.savedPackageSelection.packages - .filter { it != packageData } .map { it.copy(isSelected = false) } - .let { SavedPackageSelection(it + packageData.copy(isSelected = isSelected)) } + .toMutableList() + .apply { set(indexOf(packageData), packageData.copy(isSelected = isSelected)) } + .let { SavedPackageSelection(it) } .let { viewState.copy(savedPackageSelection = it) } } } From 6402826056f1298dff7c453dbb32527f3e90bd9d Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 14:12:44 -0300 Subject: [PATCH 28/32] Fix missing adjustment to WooShippingLabelPackageCreationViewModelTest --- .../packages/WooShippingLabelPackageCreationViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt index 756549c6023..91aead53f3b 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModelTest.kt @@ -153,7 +153,7 @@ class WooShippingLabelPackageCreationViewModelTest : BaseUnitTest() { sut = WooShippingLabelPackageCreationViewModel(SavedStateHandle(), resourceProvider, fetchSavedPackages) sut.viewState.observeForever { lastViewState = it } - sut.onSavedPackageSelected(package1) + sut.onSavedPackageSelected(package1, true) val selectedPackages = lastViewState?.savedPackageSelection?.packages?.filter { it.isSelected } assertThat(selectedPackages).isNotNull From ead5c073140c76d9e7c5519b9437166d0fc9240f Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 14:13:07 -0300 Subject: [PATCH 29/32] Fix incorrect padding for selection hover effect in the Saved packages list --- .../packages/forms/WooShippingSavedPackageScreen.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 383af2e70eb..6b6a010796d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -88,8 +88,8 @@ fun WooShippingSavedPackageItem( ) { Column( modifier = modifier - .padding(top = 8.dp) - .clickable { onPackageSelected(packageData, packageData.isSelected.not()) }, + .clickable { onPackageSelected(packageData, packageData.isSelected.not()) } + .padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(16.dp) ) { Row( From 15178065665ae72641dff8c670fb68554c8f90f3 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 14:13:22 -0300 Subject: [PATCH 30/32] Add dimensionUnit parameter to the PackageData model --- .../packages/WooShippingLabelPackageCreationViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt index 89b5d3118da..2f35f8cd020 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationViewModel.kt @@ -129,10 +129,11 @@ class WooShippingLabelPackageCreationViewModel @Inject constructor( val length: String, val width: String, val height: String, - val isSelected: Boolean + val isSelected: Boolean, + val dimensionUnit: String = "cm" ) : Parcelable { val dimensionsForDisplay: String - get() = "$length x $width x $height cm" + get() = "$length x $width x $height $dimensionUnit" } @Parcelize From 6e0e65bafe0fcc55eef64c6da4803d3db56aee47 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 14:48:23 -0300 Subject: [PATCH 31/32] Fix lint issues --- .../packages/forms/WooShippingSavedPackageScreen.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt index 6b6a010796d..4204fa4109f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/forms/WooShippingSavedPackageScreen.kt @@ -52,10 +52,11 @@ fun WooShippingSavedPackageScreen( modifier = modifier .fillMaxSize() ) { - Column(modifier = modifier - .weight(1f) - .padding(16.dp) - .verticalScroll(rememberScrollState()) + Column( + modifier = modifier + .weight(1f) + .padding(16.dp) + .verticalScroll(rememberScrollState()) ) { savedPackages.forEach { packageData -> WooShippingSavedPackageItem( From 52110f8acc1e6238d5212b9d89769a48f11ca64a Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 7 Nov 2024 15:05:05 -0300 Subject: [PATCH 32/32] Update main Shipping Label screen tabs coloring --- .../packages/WooShippingLabelPackageCreationScreen.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt index 07ba7072373..b130a7ccd9a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationScreen.kt @@ -66,9 +66,13 @@ fun WooShippingLabelPackageCreationScreen( Scaffold( topBar = { - TabRow(selectedTabIndex = tabIndex) { + TabRow( + selectedTabIndex = tabIndex, + backgroundColor = MaterialTheme.colors.surface, + ) { tabs.forEachIndexed { index, pageTab -> Tab( + selectedContentColor = MaterialTheme.colors.onSurface, text = { Text(text = pageTab.title) }, selected = tabIndex == index, onClick = { tabIndex = index }