From b22eb6877aa5eb4adacd7cf9b31077c0cd23fea2 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 11 Dec 2024 19:41:19 -0300 Subject: [PATCH 01/36] Fix WooShippingCarrierPackageScreen scrolling --- .../packages/ui/WooShippingCarrierPackageScreen.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt index d39f544cbbf..b4307b531e5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCarrierPackageScreen.kt @@ -210,7 +210,11 @@ private fun PackageList( packageGroups: List, onPackageSelected: (PackageData, Boolean) -> Unit ) { - Column(modifier = Modifier.fillMaxSize()) { + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .fillMaxSize() + ) { packageGroups.forEach { group -> Spacer(modifier = Modifier.height(8.dp)) PackageListSection( From 7ae716c84e823e77221849886601992d90d58a4b Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 11 Dec 2024 20:00:05 -0300 Subject: [PATCH 02/36] Update result handling in WooShippingLabelPackageCreationFragment to also trigger back navigation --- .../packages/WooShippingLabelPackageCreationFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt index 790675534ab..fdcf573f4e8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt @@ -6,11 +6,11 @@ import android.view.View import android.view.ViewGroup import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed -import androidx.fragment.app.setFragmentResult import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import com.woocommerce.android.R import com.woocommerce.android.extensions.handleDialogResult +import com.woocommerce.android.extensions.navigateBackWithResult import com.woocommerce.android.extensions.navigateSafely import com.woocommerce.android.ui.base.BaseFragment import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground @@ -74,7 +74,7 @@ class WooShippingLabelPackageCreationFragment : BaseFragment() { } private fun handlePackageDataAsResult(packageData: PackageData) { - setFragmentResult( + navigateBackWithResult( PACKAGE_SELECTION_RESULT, Bundle().apply { putParcelable(PACKAGE_SELECTION_RESULT, packageData) } ) From 7108277637b10202487e1aef8d8863e8fe813073 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 11 Dec 2024 20:03:06 -0300 Subject: [PATCH 03/36] Intercept PackageData result from Package selection fragment --- .../WooShippingLabelCreationFragment.kt | 10 ++++++++++ .../WooShippingLabelCreationViewModel.kt | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt index 8c5b6ea2ac8..657f857d646 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt @@ -9,11 +9,14 @@ import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController +import com.woocommerce.android.extensions.handleResult import com.woocommerce.android.extensions.navigateSafely import com.woocommerce.android.ui.base.BaseFragment import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.main.AppBarStatus import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.StartPackageSelection +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.WooShippingLabelPackageCreationFragment.Companion.PACKAGE_SELECTION_RESULT +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -36,6 +39,7 @@ class WooShippingLabelCreationFragment : BaseFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupObservers() + setupResultHandlers() } override val activityAppBarStatus: AppBarStatus = AppBarStatus.Hidden @@ -59,4 +63,10 @@ class WooShippingLabelCreationFragment : BaseFragment() { } } } + + private fun setupResultHandlers() { + handleResult(PACKAGE_SELECTION_RESULT) { + viewModel.onPackageSelected(it) + } + } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index aaa6614c2dd..46b8b4928b6 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -7,6 +7,7 @@ import com.woocommerce.android.model.Order import com.woocommerce.android.ui.orders.details.OrderDetailRepository import com.woocommerce.android.ui.orders.wooshippinglabels.models.ShippableItemModel import com.woocommerce.android.ui.orders.wooshippinglabels.models.StoreOptionsModel +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.util.CurrencyFormatter import com.woocommerce.android.viewmodel.MultiLiveEvent.Event import com.woocommerce.android.viewmodel.ScopedViewModel @@ -88,6 +89,10 @@ class WooShippingLabelCreationViewModel @Inject constructor( triggerEvent(LabelPurchased) } + fun onPackageSelected(packageData: PackageData) { + + } + data object StartPackageSelection : Event() data object LabelPurchased : Event() From b03f5313d88ef6de24ab092891b2a2f25993c654 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Wed, 11 Dec 2024 20:07:17 -0300 Subject: [PATCH 04/36] Remove incorrect Bundle creation from WooShippingLabelPackageCreationFragment --- .../packages/WooShippingLabelPackageCreationFragment.kt | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt index fdcf573f4e8..6e3751ea82f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt @@ -45,7 +45,7 @@ class WooShippingLabelPackageCreationFragment : BaseFragment() { viewModel.event.observe(viewLifecycleOwner) { event -> when (event) { is ShowPackageTypeDialog -> handlePackageTypeSelection(event.currentSelection) - is PackageSelected -> handlePackageDataAsResult(event.packageData) + is PackageSelected -> navigateBackWithResult(PACKAGE_SELECTION_RESULT, event.packageData) } } } @@ -73,13 +73,6 @@ class WooShippingLabelPackageCreationFragment : BaseFragment() { ).let { findNavController().navigateSafely(it) } } - private fun handlePackageDataAsResult(packageData: PackageData) { - navigateBackWithResult( - PACKAGE_SELECTION_RESULT, - Bundle().apply { putParcelable(PACKAGE_SELECTION_RESULT, packageData) } - ) - } - companion object { const val SELECTOR_REQUEST_KEY = "package_type" const val PACKAGE_SELECTION_RESULT = "package_selection" From 036e3d8010ce9771b62bbee845b6fb34a94ad01e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 13:27:26 -0300 Subject: [PATCH 05/36] Introduce PackageData.EMPTY field --- .../orders/wooshippinglabels/packages/ui/UIModels.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 3975be27171..b5b0eb7cb73 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -44,6 +44,16 @@ data class PackageData( val weightForDisplay get() = "$weight $weightUnit" + + companion object { + val EMPTY = PackageData( + name = "", + dimensions = "", + weight = "", + isSelected = false, + isLetter = false + ) + } } @Parcelize From bdfe5452946541379d77960a93a8c12125e494a1 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 13:36:20 -0300 Subject: [PATCH 06/36] Refactor WooShippingLabelCreationViewModel to support PackageData handling with Shipping Rates --- .../WooShippingLabelCreationViewModel.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index 905ad65464e..76189c2b66c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -6,10 +6,10 @@ import com.woocommerce.android.extensions.sumByFloat import com.woocommerce.android.model.Address import com.woocommerce.android.model.Order import com.woocommerce.android.ui.orders.details.OrderDetailRepository +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotAvailable import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.models.ShippableItemModel import com.woocommerce.android.ui.orders.wooshippinglabels.models.StoreOptionsModel -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.PackageDAO import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.util.CurrencyFormatter import com.woocommerce.android.viewmodel.MultiLiveEvent.Event @@ -44,18 +44,8 @@ class WooShippingLabelCreationViewModel @Inject constructor( originCountry = "US" ) - private val mockSelectedPackage = PackageDAO( - id = "small_flat_box", - name = "Small Flat Rate Box", - dimensions = "21.91 x 13.65 x 4.13", - isLetter = false, - weight = "0.5", - dimensionUnit = "cm", - weightUnit = "kg" - ) - private val shippableItems = MutableStateFlow>(emptyList()) - private val selectedPackage = MutableStateFlow(mockSelectedPackage) + private val selectedPackage = MutableStateFlow(NotAvailable) private val storeOptions = MutableStateFlow(mockStoreOptions) private val selectedRatesSortOrder = MutableStateFlow(ShippingSortOption.FASTEST) private val refreshShippingRates = MutableSharedFlow() @@ -67,7 +57,10 @@ class WooShippingLabelCreationViewModel @Inject constructor( selectedRatesSortOrder, refreshShippingRates.onStart { emit(Unit) } ) { selectedPackage, sortOrder, _ -> - Pair(selectedPackage, sortOrder) + when (selectedPackage) { + is NotAvailable -> PackageData.EMPTY + is PackageSelectionState.Data -> selectedPackage.selectedPackage + }.let { Pair(it, sortOrder) } }.flatMapLatest { val (selectedPackage, sortOrder) = it refreshShippingRates(selectedPackage, sortOrder) @@ -79,7 +72,10 @@ class WooShippingLabelCreationViewModel @Inject constructor( launch { observeShippingLabelInformation() } } - private fun refreshShippingRates(selectedPackage: PackageDAO, sortOrder: ShippingSortOption) = flow { + private fun refreshShippingRates( + selectedPackage: PackageData, + sortOrder: ShippingSortOption + ) = flow { emit(ShippingRatesState.Loading(sortOrder)) val shippingRatesResult = getShippingRates(selectedPackage, sortOrder) if (shippingRatesResult.isSuccess) { @@ -225,6 +221,14 @@ class WooShippingLabelCreationViewModel @Inject constructor( val shippingRates: Map> ) : ShippingRatesState() } + + sealed class PackageSelectionState { + data object NotAvailable : PackageSelectionState() + data class Data( + val selectedPackage: PackageData, + val totalWeight: String + ) : PackageSelectionState() + } } data class WooShippingAddresses( From 2ed22bce29923850af806bf214ad810a58ef4609 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 13:36:34 -0300 Subject: [PATCH 07/36] Update GetShippingRates with PackageData --- .../android/ui/orders/wooshippinglabels/GetShippingRates.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt index 6195b736449..43a0a3e1b14 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/GetShippingRates.kt @@ -1,7 +1,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels import com.woocommerce.android.R -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.PackageDAO +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import kotlinx.coroutines.delay import javax.inject.Inject import kotlin.random.Random @@ -16,7 +16,7 @@ class GetShippingRates @Inject constructor() { } suspend operator fun invoke( - selectedPackage: PackageDAO, + selectedPackage: PackageData, sortOrder: ShippingSortOption ): Result>> { delay(1_000) From 48746adafed09a8a8711753ae1a58eec31e23a7d Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 13:39:02 -0300 Subject: [PATCH 08/36] Implement WooShippingLabelCreationViewModel.onPackageSelected --- .../WooShippingLabelCreationViewModel.kt | 11 ++++++++++- .../WooShippingLabelPackageCreationFragment.kt | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index 76189c2b66c..db60e627df1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.flow.update @HiltViewModel class WooShippingLabelCreationViewModel @Inject constructor( @@ -191,7 +192,15 @@ class WooShippingLabelCreationViewModel @Inject constructor( } fun onPackageSelected(packageData: PackageData) { - + selectedPackage.update { content -> + when (content) { + is NotAvailable -> PackageSelectionState.Data( + selectedPackage = packageData, + totalWeight = packageData.weight + ) + is PackageSelectionState.Data -> content.copy(selectedPackage = packageData) + } + } } data object StartPackageSelection : Event() diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt index 6e3751ea82f..fcdffb3796d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/WooShippingLabelPackageCreationFragment.kt @@ -17,7 +17,6 @@ import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground 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 -import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint From 85477d20a464bbede1ba8cdfad876b4e2fa5b797 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 15:24:24 -0300 Subject: [PATCH 09/36] Connect PackageSelection state with ViewState --- .../WooShippingLabelCreationViewModel.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index db60e627df1..60342c0faed 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -6,7 +6,7 @@ import com.woocommerce.android.extensions.sumByFloat import com.woocommerce.android.model.Address import com.woocommerce.android.model.Order import com.woocommerce.android.ui.orders.details.OrderDetailRepository -import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotAvailable +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotSelected import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.models.ShippableItemModel import com.woocommerce.android.ui.orders.wooshippinglabels.models.StoreOptionsModel @@ -46,11 +46,11 @@ class WooShippingLabelCreationViewModel @Inject constructor( ) private val shippableItems = MutableStateFlow>(emptyList()) - private val selectedPackage = MutableStateFlow(NotAvailable) private val storeOptions = MutableStateFlow(mockStoreOptions) private val selectedRatesSortOrder = MutableStateFlow(ShippingSortOption.FASTEST) private val refreshShippingRates = MutableSharedFlow() + private val selectedPackage = MutableStateFlow(NotSelected) @OptIn(ExperimentalCoroutinesApi::class) private val shippingRates = combine( @@ -59,7 +59,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( refreshShippingRates.onStart { emit(Unit) } ) { selectedPackage, sortOrder, _ -> when (selectedPackage) { - is NotAvailable -> PackageData.EMPTY + is NotSelected -> PackageData.EMPTY is PackageSelectionState.Data -> selectedPackage.selectedPackage }.let { Pair(it, sortOrder) } }.flatMapLatest { @@ -91,8 +91,9 @@ class WooShippingLabelCreationViewModel @Inject constructor( storeOptions, flowOf(orderDetailRepository.getOrderById(navArgs.orderId)), observeOriginAddresses(), - shippingRates - ) { storeOptions, order, originAddresses, shippingRates -> + shippingRates, + selectedPackage + ) { storeOptions, order, originAddresses, shippingRates, packageSelection -> val selectedOriginAddress = getSelectedOriginAddress(originAddresses) if (order == null || selectedOriginAddress == null) { return@combine WooShippingViewState.Error @@ -118,7 +119,8 @@ class WooShippingLabelCreationViewModel @Inject constructor( originAddresses = originAddresses, shipTo = order.shippingAddress ), - shippingRates = shippingRates + shippingRates = shippingRates, + packageSelection = packageSelection ) }.collect { viewState.value = it @@ -194,7 +196,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( fun onPackageSelected(packageData: PackageData) { selectedPackage.update { content -> when (content) { - is NotAvailable -> PackageSelectionState.Data( + is NotSelected -> PackageSelectionState.Data( selectedPackage = packageData, totalWeight = packageData.weight ) @@ -214,6 +216,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( val shippingLines: List, val shippingAddresses: WooShippingAddresses, val shippingRates: ShippingRatesState, + val packageSelection: PackageSelectionState ) : WooShippingViewState() } @@ -232,7 +235,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( } sealed class PackageSelectionState { - data object NotAvailable : PackageSelectionState() + data object NotSelected : PackageSelectionState() data class Data( val selectedPackage: PackageData, val totalWeight: String From c8a8eba3f202b0a37e568000bd30a1f17b1cfa23 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 15:31:59 -0300 Subject: [PATCH 10/36] Fix lint issues --- .../wooshippinglabels/WooShippingLabelCreationViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index 60342c0faed..36f4e05ccd5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -24,9 +24,9 @@ import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.onStart +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import javax.inject.Inject -import kotlinx.coroutines.flow.update @HiltViewModel class WooShippingLabelCreationViewModel @Inject constructor( @@ -51,6 +51,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( private val refreshShippingRates = MutableSharedFlow() private val selectedPackage = MutableStateFlow(NotSelected) + @OptIn(ExperimentalCoroutinesApi::class) private val shippingRates = combine( From 2d25059b85b72dd381d5360b21ba1cb2cd6fff94 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 15:41:17 -0300 Subject: [PATCH 11/36] Rename PackageSelectionState property --- .../WooShippingLabelCreationViewModel.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index 36f4e05ccd5..ee45e37e31a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -50,12 +50,12 @@ class WooShippingLabelCreationViewModel @Inject constructor( private val selectedRatesSortOrder = MutableStateFlow(ShippingSortOption.FASTEST) private val refreshShippingRates = MutableSharedFlow() - private val selectedPackage = MutableStateFlow(NotSelected) + private val packageSelection = MutableStateFlow(NotSelected) @OptIn(ExperimentalCoroutinesApi::class) private val shippingRates = combine( - selectedPackage, + packageSelection, selectedRatesSortOrder, refreshShippingRates.onStart { emit(Unit) } ) { selectedPackage, sortOrder, _ -> @@ -93,7 +93,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( flowOf(orderDetailRepository.getOrderById(navArgs.orderId)), observeOriginAddresses(), shippingRates, - selectedPackage + packageSelection ) { storeOptions, order, originAddresses, shippingRates, packageSelection -> val selectedOriginAddress = getSelectedOriginAddress(originAddresses) if (order == null || selectedOriginAddress == null) { @@ -195,7 +195,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( } fun onPackageSelected(packageData: PackageData) { - selectedPackage.update { content -> + packageSelection.update { content -> when (content) { is NotSelected -> PackageSelectionState.Data( selectedPackage = packageData, From c2e3455127eee291b89b002c660f55f896282fb3 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 15:55:30 -0300 Subject: [PATCH 12/36] Wire PackageSelectionState into WooShippingLabelCreationScreen --- .../wooshippinglabels/WooShippingLabelCreationScreen.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 108190d6a12..ee2e7e8da29 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -48,6 +48,7 @@ import com.woocommerce.android.model.Address import com.woocommerce.android.ui.compose.component.WCColoredButton import com.woocommerce.android.ui.compose.modifiers.dashedBorder import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress @Composable @@ -67,6 +68,7 @@ fun WooShippingLabelCreationScreen(viewModel: WooShippingLabelCreationViewModel) shippingLines = viewState.shippingLines, shippingAddresses = viewState.shippingAddresses, shippingRatesState = viewState.shippingRates, + packageSelectionState = viewState.packageSelection, onShippingFromAddressChange = viewModel::onShippingFromAddressChange, onShippingToAddressChange = viewModel::onShippingToAddressChange, onSelectedRateSortOrderChanged = viewModel::onSelectedRateSortOrderChanged, @@ -87,6 +89,7 @@ fun WooShippingLabelCreationScreen( shippableItems: ShippableItemsUI, shippingLines: List, shippingRatesState: WooShippingLabelCreationViewModel.ShippingRatesState, + packageSelectionState: PackageSelectionState, shippingAddresses: WooShippingAddresses, onShippingFromAddressChange: (OriginShippingAddress) -> Unit, onShippingToAddressChange: (Address) -> Unit, @@ -293,6 +296,7 @@ private fun WooShippingLabelCreationScreenPreview() { originAddresses = listOf(getShipFrom()) ), shippingRatesState = WooShippingLabelCreationViewModel.ShippingRatesState.NoAvailable, + packageSelectionState = PackageSelectionState.NotSelected, onShippingFromAddressChange = {}, onShippingToAddressChange = {}, onRefreshShippingRates = {}, From 5acc0081dba1e0a3a32b447bb186dbec77056780 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 16:10:12 -0300 Subject: [PATCH 13/36] Set basic WooShippingLabelCreationScreen structure for Package control based on the Selection State --- .../WooShippingLabelCreationScreen.kt | 121 +++++++++++------- 1 file changed, 78 insertions(+), 43 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index ee2e7e8da29..193ac0828c8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -50,6 +50,7 @@ import com.woocommerce.android.ui.compose.modifiers.dashedBorder import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData @Composable fun WooShippingLabelCreationScreen(viewModel: WooShippingLabelCreationViewModel) { @@ -109,6 +110,7 @@ fun WooShippingLabelCreationScreen( shippingLines = shippingLines, shippingAddresses = shippingAddresses, shippingRatesState = shippingRatesState, + packageSelectionState = packageSelectionState, onShippingFromAddressChange = onShippingFromAddressChange, onShippingToAddressChange = onShippingToAddressChange, onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged, @@ -148,6 +150,7 @@ private fun LabelCreationScreenWithBottomSheet( shippableItems: ShippableItemsUI, shippingLines: List, shippingRatesState: WooShippingLabelCreationViewModel.ShippingRatesState, + packageSelectionState: PackageSelectionState, onSelectPackageClick: () -> Unit, shippingAddresses: WooShippingAddresses, onShippingFromAddressChange: (OriginShippingAddress) -> Unit, @@ -212,6 +215,7 @@ private fun LabelCreationScreenWithBottomSheet( ) PackageCard( modifier = Modifier.padding(16.dp), + packageSelectionState = packageSelectionState, onSelectPackageClick = onSelectPackageClick ) WooShippingShippingRatesSection( @@ -275,36 +279,6 @@ private fun WooShippingShippingRatesSection( } } -@Preview(name = "dark", uiMode = Configuration.UI_MODE_NIGHT_YES, device = Devices.PIXEL) -@Preview(name = "light", uiMode = Configuration.UI_MODE_NIGHT_NO, device = Devices.PIXEL) -@Composable -private fun WooShippingLabelCreationScreenPreview() { - WooThemeWithBackground { - WooShippingLabelCreationScreen( - shippableItems = ShippableItemsUI( - shippableItems = generateItems(6), - formattedTotalWeight = "8.5kg", - formattedTotalPrice = "$92.78" - ), - shippingLines = getShippingLines(), - modifier = Modifier.fillMaxSize(), - onSelectPackageClick = {}, - onPurchaseShippingLabel = {}, - shippingAddresses = WooShippingAddresses( - shipFrom = getShipFrom(), - shipTo = getShipTo(), - originAddresses = listOf(getShipFrom()) - ), - shippingRatesState = WooShippingLabelCreationViewModel.ShippingRatesState.NoAvailable, - packageSelectionState = PackageSelectionState.NotSelected, - onShippingFromAddressChange = {}, - onShippingToAddressChange = {}, - onRefreshShippingRates = {}, - onSelectedRateSortOrderChanged = {} - ) - } -} - @Composable internal fun HazmatCard( modifier: Modifier = Modifier, @@ -341,16 +315,30 @@ internal fun HazmatCard( } } -@Preview @Composable -private fun HazmatCardPreview() { - WooThemeWithBackground { - HazmatCard(modifier = Modifier.padding(16.dp)) +private fun PackageCard( + modifier: Modifier = Modifier, + packageSelectionState: PackageSelectionState, + onSelectPackageClick: () -> Unit +) { + when (packageSelectionState) { + PackageSelectionState.NotSelected -> { + SelectPackageCard( + modifier = modifier, + onSelectPackageClick = onSelectPackageClick + ) + } + is PackageSelectionState.Data -> { + PackageSelectionAvailableCard( + modifier = modifier, + packageData = packageSelectionState.selectedPackage + ) + } } } @Composable -private fun PackageCard( +private fun SelectPackageCard( modifier: Modifier = Modifier, onSelectPackageClick: () -> Unit ) { @@ -399,15 +387,12 @@ private fun PackageCard( } } -@Preview @Composable -private fun PackageCardPreview() { - WooThemeWithBackground { - PackageCard( - modifier = Modifier.padding(16.dp), - onSelectPackageClick = {} - ) - } +private fun PackageSelectionAvailableCard( + modifier: Modifier, + packageData: PackageData +) { + } data class ShippableItemUI( @@ -426,3 +411,53 @@ data class ShippableItemsUI( val formattedTotalWeight: String, val formattedTotalPrice: String ) + +@Preview(name = "dark", uiMode = Configuration.UI_MODE_NIGHT_YES, device = Devices.PIXEL) +@Preview(name = "light", uiMode = Configuration.UI_MODE_NIGHT_NO, device = Devices.PIXEL) +@Composable +private fun WooShippingLabelCreationScreenPreview() { + WooThemeWithBackground { + WooShippingLabelCreationScreen( + shippableItems = ShippableItemsUI( + shippableItems = generateItems(6), + formattedTotalWeight = "8.5kg", + formattedTotalPrice = "$92.78" + ), + shippingLines = getShippingLines(), + modifier = Modifier.fillMaxSize(), + onSelectPackageClick = {}, + onPurchaseShippingLabel = {}, + shippingAddresses = WooShippingAddresses( + shipFrom = getShipFrom(), + shipTo = getShipTo(), + originAddresses = listOf(getShipFrom()) + ), + shippingRatesState = WooShippingLabelCreationViewModel.ShippingRatesState.NoAvailable, + packageSelectionState = PackageSelectionState.NotSelected, + onShippingFromAddressChange = {}, + onShippingToAddressChange = {}, + onRefreshShippingRates = {}, + onSelectedRateSortOrderChanged = {} + ) + } +} + +@Preview +@Composable +private fun HazmatCardPreview() { + WooThemeWithBackground { + HazmatCard(modifier = Modifier.padding(16.dp)) + } +} + +@Preview +@Composable +private fun PackageCardPreview() { + WooThemeWithBackground { + PackageCard( + modifier = Modifier.padding(16.dp), + packageSelectionState = PackageSelectionState.NotSelected, + onSelectPackageClick = {} + ) + } +} From ec5e6beecc998bab2d51d4d709508d216fd2c9ad Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 16:12:37 -0300 Subject: [PATCH 14/36] Introduce initial package selection UI --- .../WooShippingLabelCreationScreen.kt | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 193ac0828c8..e015d8bf7b3 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.BottomSheetScaffold import androidx.compose.material.BottomSheetScaffoldState import androidx.compose.material.CircularProgressIndicator +import androidx.compose.material.Divider import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.MaterialTheme @@ -392,7 +393,36 @@ private fun PackageSelectionAvailableCard( modifier: Modifier, packageData: PackageData ) { - + Column( + modifier = modifier + .padding(top = 8.dp), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text( + text = stringResource(id = packageData.descriptionResId), + style = MaterialTheme.typography.caption, + color = colorResource(id = R.color.color_on_surface_disabled) + ) + Text( + text = packageData.name, + style = MaterialTheme.typography.body1 + ) + Text( + text = packageData.weight + .takeIf { it.isNotEmpty() } + ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } + ?: packageData.dimensionForDisplay, + style = MaterialTheme.typography.body2 + ) + } + } + Divider() + } } data class ShippableItemUI( From dfe329dd6459f5a8ad82d583e550b35714e7993b Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 16:26:46 -0300 Subject: [PATCH 15/36] Add dedicated Preview for Package selection --- .../WooShippingLabelCreationScreen.kt | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index e015d8bf7b3..6f8259624fe 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -395,7 +395,11 @@ private fun PackageSelectionAvailableCard( ) { Column( modifier = modifier - .padding(top = 8.dp), + .background( + color = MaterialTheme.colors.surface, + shape = RoundedCornerShape(dimensionResource(R.dimen.corner_radius_large)) + ) + .padding(dimensionResource(id = R.dimen.major_200)), verticalArrangement = Arrangement.spacedBy(16.dp) ) { Row( @@ -482,7 +486,7 @@ private fun HazmatCardPreview() { @Preview @Composable -private fun PackageCardPreview() { +private fun PackageNotSelectedPreview() { WooThemeWithBackground { PackageCard( modifier = Modifier.padding(16.dp), @@ -491,3 +495,24 @@ private fun PackageCardPreview() { ) } } + +@Preview +@Composable +private fun PackageSelectedPreview() { + WooThemeWithBackground { + PackageCard( + modifier = Modifier.padding(16.dp), + packageSelectionState = PackageSelectionState.Data( + selectedPackage = PackageData( + name = "Package 1", + dimensions = "10 x 10 x 10 cm", + weight = "1.5 kg", + isSelected = true, + isLetter = false + ), + totalWeight = "1.5 kg" + ), + onSelectPackageClick = {} + ) + } +} From fb244ab154ce76f9340cd5fc2695701933abc13f Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 16:30:14 -0300 Subject: [PATCH 16/36] Add Border outline to Package Selection card --- .../WooShippingLabelCreationScreen.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 6f8259624fe..cd9868ad5dd 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -2,6 +2,7 @@ package com.woocommerce.android.ui.orders.wooshippinglabels import android.content.res.Configuration import androidx.compose.foundation.background +import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Arrangement @@ -395,11 +396,13 @@ private fun PackageSelectionAvailableCard( ) { Column( modifier = modifier - .background( - color = MaterialTheme.colors.surface, - shape = RoundedCornerShape(dimensionResource(R.dimen.corner_radius_large)) - ) - .padding(dimensionResource(id = R.dimen.major_200)), + .background(color = MaterialTheme.colors.surface,) + .fillMaxWidth() + .border( + width = 1.dp, + color = colorResource(id = R.color.divider_color), + shape = RoundedCornerShape(8.dp) + ).padding(dimensionResource(id = R.dimen.major_200)), verticalArrangement = Arrangement.spacedBy(16.dp) ) { Row( @@ -425,7 +428,6 @@ private fun PackageSelectionAvailableCard( ) } } - Divider() } } From e143ed64a4bdf06e3ce262786adb62f6e86439c9 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:01:09 -0300 Subject: [PATCH 17/36] Configure Selected Package header --- .../WooShippingLabelCreationScreen.kt | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index cd9868ad5dd..dea1a72ad4d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -19,7 +19,6 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.material.BottomSheetScaffold import androidx.compose.material.BottomSheetScaffoldState import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.Divider import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.MaterialTheme @@ -333,7 +332,8 @@ private fun PackageCard( is PackageSelectionState.Data -> { PackageSelectionAvailableCard( modifier = modifier, - packageData = packageSelectionState.selectedPackage + packageData = packageSelectionState.selectedPackage, + onSelectPackageClick = onSelectPackageClick ) } } @@ -392,40 +392,63 @@ private fun SelectPackageCard( @Composable private fun PackageSelectionAvailableCard( modifier: Modifier, - packageData: PackageData + packageData: PackageData, + onSelectPackageClick: () -> Unit ) { - Column( - modifier = modifier - .background(color = MaterialTheme.colors.surface,) - .fillMaxWidth() - .border( - width = 1.dp, - color = colorResource(id = R.color.divider_color), - shape = RoundedCornerShape(8.dp) - ).padding(dimensionResource(id = R.dimen.major_200)), - verticalArrangement = Arrangement.spacedBy(16.dp) - ) { + Column(modifier = modifier.background(color = MaterialTheme.colors.surface)) { Row( - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = dimensionResource(id = R.dimen.major_100)) ) { - Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { - Text( - text = stringResource(id = packageData.descriptionResId), - style = MaterialTheme.typography.caption, - color = colorResource(id = R.color.color_on_surface_disabled) - ) - Text( - text = packageData.name, - style = MaterialTheme.typography.body1 + Text( + text = "Package", + style = MaterialTheme.typography.subtitle1, + ) + IconButton( + onClick = onSelectPackageClick + ) { + Icon( + painter = painterResource(id = R.drawable.ic_edit), + contentDescription = "Edit package" ) - Text( - text = packageData.weight - .takeIf { it.isNotEmpty() } - ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } - ?: packageData.dimensionForDisplay, - style = MaterialTheme.typography.body2 + } + } + Column( + modifier = modifier + .fillMaxWidth() + .border( + width = 1.dp, + color = colorResource(id = R.color.divider_color), + shape = RoundedCornerShape(8.dp) ) + .padding(dimensionResource(id = R.dimen.major_200)), + verticalArrangement = Arrangement.spacedBy(16.dp) + ) { + Row( + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text( + text = stringResource(id = packageData.descriptionResId), + style = MaterialTheme.typography.caption, + color = colorResource(id = R.color.color_on_surface_disabled) + ) + Text( + text = packageData.name, + style = MaterialTheme.typography.body1 + ) + Text( + text = packageData.weight + .takeIf { it.isNotEmpty() } + ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } + ?: packageData.dimensionForDisplay, + style = MaterialTheme.typography.body2 + ) + } } } } From 672981b8560583217212e77f46318fa6f0c50bc4 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:15:07 -0300 Subject: [PATCH 18/36] Simplify WooShippingLabelCreationScreen Package sections --- .../WooShippingLabelCreationScreen.kt | 90 ++++++++----------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index dea1a72ad4d..1f446cf0273 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -50,6 +50,7 @@ import com.woocommerce.android.ui.compose.component.WCColoredButton import com.woocommerce.android.ui.compose.modifiers.dashedBorder import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotSelected import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData @@ -323,29 +324,20 @@ private fun PackageCard( onSelectPackageClick: () -> Unit ) { when (packageSelectionState) { - PackageSelectionState.NotSelected -> { - SelectPackageCard( - modifier = modifier, - onSelectPackageClick = onSelectPackageClick - ) - } - is PackageSelectionState.Data -> { - PackageSelectionAvailableCard( - modifier = modifier, - packageData = packageSelectionState.selectedPackage, - onSelectPackageClick = onSelectPackageClick - ) - } + is NotSelected -> SelectPackageCard( + onSelectPackageClick = onSelectPackageClick + ) + is PackageSelectionState.Data -> PackageSelectionAvailableCard( + packageData = packageSelectionState.selectedPackage, + onSelectPackageClick = onSelectPackageClick + ) } } @Composable -private fun SelectPackageCard( - modifier: Modifier = Modifier, - onSelectPackageClick: () -> Unit -) { +private fun SelectPackageCard(onSelectPackageClick: () -> Unit) { Column( - modifier = modifier + modifier = Modifier .background( color = MaterialTheme.colors.surface, shape = RoundedCornerShape(dimensionResource(R.dimen.corner_radius_large)) @@ -391,17 +383,14 @@ private fun SelectPackageCard( @Composable private fun PackageSelectionAvailableCard( - modifier: Modifier, packageData: PackageData, onSelectPackageClick: () -> Unit ) { - Column(modifier = modifier.background(color = MaterialTheme.colors.surface)) { + Column(modifier = Modifier.background(color = MaterialTheme.colors.surface)) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = dimensionResource(id = R.dimen.major_100)) + modifier = Modifier.fillMaxWidth() ) { Text( text = "Package", @@ -417,38 +406,31 @@ private fun PackageSelectionAvailableCard( } } Column( - modifier = modifier + modifier = Modifier .fillMaxWidth() .border( width = 1.dp, color = colorResource(id = R.color.divider_color), shape = RoundedCornerShape(8.dp) - ) - .padding(dimensionResource(id = R.dimen.major_200)), - verticalArrangement = Arrangement.spacedBy(16.dp) + ).padding(dimensionResource(id = R.dimen.major_200)), ) { - Row( - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { - Text( - text = stringResource(id = packageData.descriptionResId), - style = MaterialTheme.typography.caption, - color = colorResource(id = R.color.color_on_surface_disabled) - ) - Text( - text = packageData.name, - style = MaterialTheme.typography.body1 - ) - Text( - text = packageData.weight - .takeIf { it.isNotEmpty() } - ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } - ?: packageData.dimensionForDisplay, - style = MaterialTheme.typography.body2 - ) - } + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text( + text = stringResource(id = packageData.descriptionResId), + style = MaterialTheme.typography.caption, + color = colorResource(id = R.color.color_on_surface_disabled) + ) + Text( + text = packageData.name, + style = MaterialTheme.typography.body1 + ) + Text( + text = packageData.weight + .takeIf { it.isNotEmpty() } + ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } + ?: packageData.dimensionForDisplay, + style = MaterialTheme.typography.body2 + ) } } } @@ -492,7 +474,7 @@ private fun WooShippingLabelCreationScreenPreview() { originAddresses = listOf(getShipFrom()) ), shippingRatesState = WooShippingLabelCreationViewModel.ShippingRatesState.NoAvailable, - packageSelectionState = PackageSelectionState.NotSelected, + packageSelectionState = NotSelected, onShippingFromAddressChange = {}, onShippingToAddressChange = {}, onRefreshShippingRates = {}, @@ -515,7 +497,7 @@ private fun PackageNotSelectedPreview() { WooThemeWithBackground { PackageCard( modifier = Modifier.padding(16.dp), - packageSelectionState = PackageSelectionState.NotSelected, + packageSelectionState = NotSelected, onSelectPackageClick = {} ) } @@ -530,12 +512,12 @@ private fun PackageSelectedPreview() { packageSelectionState = PackageSelectionState.Data( selectedPackage = PackageData( name = "Package 1", - dimensions = "10 x 10 x 10 cm", - weight = "1.5 kg", + dimensions = "10 x 10 x 10", + weight = "1.5", isSelected = true, isLetter = false ), - totalWeight = "1.5 kg" + totalWeight = "1.5" ), onSelectPackageClick = {} ) From a1372b247e94b56752cbd560425c113e09407d55 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:16:26 -0300 Subject: [PATCH 19/36] Rename PackageSelectionState.Data to DataAvailable --- .../wooshippinglabels/WooShippingLabelCreationScreen.kt | 5 +++-- .../WooShippingLabelCreationViewModel.kt | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 1f446cf0273..459b44f2406 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -50,6 +50,7 @@ import com.woocommerce.android.ui.compose.component.WCColoredButton import com.woocommerce.android.ui.compose.modifiers.dashedBorder import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.DataAvailable import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotSelected import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData @@ -327,7 +328,7 @@ private fun PackageCard( is NotSelected -> SelectPackageCard( onSelectPackageClick = onSelectPackageClick ) - is PackageSelectionState.Data -> PackageSelectionAvailableCard( + is DataAvailable -> PackageSelectionAvailableCard( packageData = packageSelectionState.selectedPackage, onSelectPackageClick = onSelectPackageClick ) @@ -509,7 +510,7 @@ private fun PackageSelectedPreview() { WooThemeWithBackground { PackageCard( modifier = Modifier.padding(16.dp), - packageSelectionState = PackageSelectionState.Data( + packageSelectionState = DataAvailable( selectedPackage = PackageData( name = "Package 1", dimensions = "10 x 10 x 10", diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index ee45e37e31a..ce116ce55a1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -6,6 +6,7 @@ import com.woocommerce.android.extensions.sumByFloat import com.woocommerce.android.model.Address import com.woocommerce.android.model.Order import com.woocommerce.android.ui.orders.details.OrderDetailRepository +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.DataAvailable import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.NotSelected import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.models.ShippableItemModel @@ -61,7 +62,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( ) { selectedPackage, sortOrder, _ -> when (selectedPackage) { is NotSelected -> PackageData.EMPTY - is PackageSelectionState.Data -> selectedPackage.selectedPackage + is DataAvailable -> selectedPackage.selectedPackage }.let { Pair(it, sortOrder) } }.flatMapLatest { val (selectedPackage, sortOrder) = it @@ -197,11 +198,11 @@ class WooShippingLabelCreationViewModel @Inject constructor( fun onPackageSelected(packageData: PackageData) { packageSelection.update { content -> when (content) { - is NotSelected -> PackageSelectionState.Data( + is NotSelected -> DataAvailable( selectedPackage = packageData, totalWeight = packageData.weight ) - is PackageSelectionState.Data -> content.copy(selectedPackage = packageData) + is DataAvailable -> content.copy(selectedPackage = packageData) } } } @@ -237,7 +238,7 @@ class WooShippingLabelCreationViewModel @Inject constructor( sealed class PackageSelectionState { data object NotSelected : PackageSelectionState() - data class Data( + data class DataAvailable( val selectedPackage: PackageData, val totalWeight: String ) : PackageSelectionState() From a3b1fd8b5c5749daf7e3a179233c2925ad6e30dd Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:18:19 -0300 Subject: [PATCH 20/36] Remove unwanted modifier placement from PackageCard --- .../wooshippinglabels/WooShippingLabelCreationScreen.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 459b44f2406..2a9eab18777 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -217,7 +217,6 @@ private fun LabelCreationScreenWithBottomSheet( .padding(start = 4.dp, end = 8.dp) ) PackageCard( - modifier = Modifier.padding(16.dp), packageSelectionState = packageSelectionState, onSelectPackageClick = onSelectPackageClick ) @@ -320,7 +319,6 @@ internal fun HazmatCard( @Composable private fun PackageCard( - modifier: Modifier = Modifier, packageSelectionState: PackageSelectionState, onSelectPackageClick: () -> Unit ) { @@ -497,7 +495,6 @@ private fun HazmatCardPreview() { private fun PackageNotSelectedPreview() { WooThemeWithBackground { PackageCard( - modifier = Modifier.padding(16.dp), packageSelectionState = NotSelected, onSelectPackageClick = {} ) @@ -509,7 +506,6 @@ private fun PackageNotSelectedPreview() { private fun PackageSelectedPreview() { WooThemeWithBackground { PackageCard( - modifier = Modifier.padding(16.dp), packageSelectionState = DataAvailable( selectedPackage = PackageData( name = "Package 1", From a1a5ad95aed9bed0b72c84ef2522a736dc388239 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:25:45 -0300 Subject: [PATCH 21/36] Adjust color and string resources from Package card --- .../WooShippingLabelCreationScreen.kt | 10 ++++++---- WooCommerce/src/main/res/values/strings.xml | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 2a9eab18777..1d871e9be83 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -392,15 +392,16 @@ private fun PackageSelectionAvailableCard( modifier = Modifier.fillMaxWidth() ) { Text( - text = "Package", - style = MaterialTheme.typography.subtitle1, + text = stringResource(id = R.string.shipping_label_package_selected_title), + style = MaterialTheme.typography.h6, ) IconButton( onClick = onSelectPackageClick ) { Icon( + tint = colorResource(id = R.color.woo_purple_90), painter = painterResource(id = R.drawable.ic_edit), - contentDescription = "Edit package" + contentDescription = stringResource(id = R.string.shipping_label_package_selected_description) ) } } @@ -411,7 +412,8 @@ private fun PackageSelectionAvailableCard( width = 1.dp, color = colorResource(id = R.color.divider_color), shape = RoundedCornerShape(8.dp) - ).padding(dimensionResource(id = R.dimen.major_200)), + ) + .padding(dimensionResource(id = R.dimen.major_200)), ) { Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 8103794b8ca..eb580c761a6 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -1263,6 +1263,8 @@ Are you shipping dangerous goods or hazardous materials? Select a Package Select a package to get shipping rates + Package + Change package selection Enter your package\'s dimensions or pick a carrier package option to see the available shipping rates. Shipment details Order details @@ -1281,6 +1283,7 @@ Schedule pickup Request refund + From 377d34223b0d428adcf64a351e132dd887d6d177 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:32:52 -0300 Subject: [PATCH 22/36] Revert modifier placement and adjust Package selected title --- .../WooShippingLabelCreationScreen.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 1d871e9be83..430a2496d46 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -217,6 +217,7 @@ private fun LabelCreationScreenWithBottomSheet( .padding(start = 4.dp, end = 8.dp) ) PackageCard( + modifier = Modifier.padding(16.dp), packageSelectionState = packageSelectionState, onSelectPackageClick = onSelectPackageClick ) @@ -319,14 +320,17 @@ internal fun HazmatCard( @Composable private fun PackageCard( + modifier: Modifier = Modifier, packageSelectionState: PackageSelectionState, onSelectPackageClick: () -> Unit ) { when (packageSelectionState) { is NotSelected -> SelectPackageCard( + modifier = modifier, onSelectPackageClick = onSelectPackageClick ) is DataAvailable -> PackageSelectionAvailableCard( + modifier = modifier, packageData = packageSelectionState.selectedPackage, onSelectPackageClick = onSelectPackageClick ) @@ -334,9 +338,12 @@ private fun PackageCard( } @Composable -private fun SelectPackageCard(onSelectPackageClick: () -> Unit) { +private fun SelectPackageCard( + modifier: Modifier = Modifier, + onSelectPackageClick: () -> Unit +) { Column( - modifier = Modifier + modifier = modifier .background( color = MaterialTheme.colors.surface, shape = RoundedCornerShape(dimensionResource(R.dimen.corner_radius_large)) @@ -382,10 +389,11 @@ private fun SelectPackageCard(onSelectPackageClick: () -> Unit) { @Composable private fun PackageSelectionAvailableCard( + modifier: Modifier = Modifier, packageData: PackageData, onSelectPackageClick: () -> Unit ) { - Column(modifier = Modifier.background(color = MaterialTheme.colors.surface)) { + Column(modifier = modifier.background(color = MaterialTheme.colors.surface)) { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, @@ -393,7 +401,8 @@ private fun PackageSelectionAvailableCard( ) { Text( text = stringResource(id = R.string.shipping_label_package_selected_title), - style = MaterialTheme.typography.h6, + style = MaterialTheme.typography.subtitle1, + fontWeight = FontWeight.SemiBold ) IconButton( onClick = onSelectPackageClick @@ -413,7 +422,7 @@ private fun PackageSelectionAvailableCard( color = colorResource(id = R.color.divider_color), shape = RoundedCornerShape(8.dp) ) - .padding(dimensionResource(id = R.dimen.major_200)), + .padding(dimensionResource(id = R.dimen.major_125)), ) { Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( @@ -497,6 +506,7 @@ private fun HazmatCardPreview() { private fun PackageNotSelectedPreview() { WooThemeWithBackground { PackageCard( + modifier = Modifier.padding(16.dp), packageSelectionState = NotSelected, onSelectPackageClick = {} ) @@ -508,6 +518,7 @@ private fun PackageNotSelectedPreview() { private fun PackageSelectedPreview() { WooThemeWithBackground { PackageCard( + modifier = Modifier.padding(16.dp), packageSelectionState = DataAvailable( selectedPackage = PackageData( name = "Package 1", From d5803216dcb827979e3324a014be8e313ec00c6c Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 17:54:45 -0300 Subject: [PATCH 23/36] Update Package edit button tint --- .../orders/wooshippinglabels/WooShippingLabelCreationScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 430a2496d46..d9388c543ed 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -408,8 +408,8 @@ private fun PackageSelectionAvailableCard( onClick = onSelectPackageClick ) { Icon( - tint = colorResource(id = R.color.woo_purple_90), painter = painterResource(id = R.drawable.ic_edit), + tint = colorResource(id = R.color.color_icon_menu), contentDescription = stringResource(id = R.string.shipping_label_package_selected_description) ) } From b7931882af56e81eada7471242f5fff562cd98c0 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:00:19 -0300 Subject: [PATCH 24/36] Handle PackageData name when it's not available --- .../wooshippinglabels/WooShippingLabelCreationScreen.kt | 4 +++- WooCommerce/src/main/res/values/strings.xml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index d9388c543ed..e2a1f78d120 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -431,7 +431,9 @@ private fun PackageSelectionAvailableCard( color = colorResource(id = R.color.color_on_surface_disabled) ) Text( - text = packageData.name, + text = packageData.name + .takeIf { it.isNotEmpty() } + ?: stringResource(id = R.string.shipping_label_package_default_name), style = MaterialTheme.typography.body1 ) Text( diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index eb580c761a6..ce30b82b398 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -1263,6 +1263,7 @@ Are you shipping dangerous goods or hazardous materials? Select a Package Select a package to get shipping rates + Custom Package Package Change package selection Enter your package\'s dimensions or pick a carrier package option to see the available shipping rates. From d6428df9ae3fcf1d74f8b5973f0ae4aaebf4c05d Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:02:19 -0300 Subject: [PATCH 25/36] Adjust Custom Package unit parameter --- .../ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index b5b0eb7cb73..d4f50f550a8 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -81,10 +81,11 @@ data class CustomPackageCreationData( fun toPackageData(dimensionUnit: String = "cm") = PackageData( name = "", - dimensions = "$length x $width x $height $dimensionUnit", + dimensions = "$length x $width x $height", weight = weight.orEmpty(), isSelected = true, - isLetter = type == PackageType.ENVELOPE + isLetter = type == PackageType.ENVELOPE, + dimensionUnit = dimensionUnit ) companion object { From 7b851f99f9871bbfbce5e64c1b56c2534700757e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:13:43 -0300 Subject: [PATCH 26/36] Map Carrier group name into PackageData when available --- .../packages/datasource/FetchPredefinedPackagesFromStore.kt | 6 ++++-- .../wooshippinglabels/packages/datasource/PackageDAOs.kt | 3 ++- .../packages/datasource/WooShippingLabelPackageMapper.kt | 3 ++- .../ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 25927bf1ddf..549b2fefe4a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -33,7 +33,8 @@ class FetchPredefinedPackagesFromStore @Inject constructor( isSelected = false, isLetter = packageDAO.isLetter, dimensionUnit = packageDAO.dimensionUnit, - weightUnit = packageDAO.weightUnit + weightUnit = packageDAO.weightUnit, + groupName = packageDAO.groupName ) } @@ -61,7 +62,8 @@ class FetchPredefinedPackagesFromStore @Inject constructor( isSelected = false, isLetter = packageItem.isLetter, dimensionUnit = packageItem.dimensionUnit, - weightUnit = packageItem.weightUnit + weightUnit = packageItem.weightUnit, + groupName = packageItem.groupName ) } ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt index 828d0753b82..8dac306da6d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/PackageDAOs.kt @@ -12,7 +12,8 @@ data class PackageDAO( val weight: String, val isLetter: Boolean, val dimensionUnit: String, - val weightUnit: String + val weightUnit: String, + val groupName: String? = null ) data class CarrierDAO( diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt index a491240f716..14d6b23ac0b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/WooShippingLabelPackageMapper.kt @@ -90,7 +90,8 @@ class WooShippingLabelPackageMapper @Inject constructor() { weight = it.boxWeight?.toString().orEmpty(), isLetter = it.isLetter ?: false, dimensionUnit = storeOptions?.dimensionUnit.orEmpty(), - weightUnit = storeOptions?.weightUnit.orEmpty() + weightUnit = storeOptions?.weightUnit.orEmpty(), + groupName = title ) } ?: emptyList() ) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index d4f50f550a8..71f0d55d8f5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -15,7 +15,8 @@ data class PackageData( val isSelected: Boolean, val isLetter: Boolean, val dimensionUnit: String = "cm", - val weightUnit: String = "kg" + val weightUnit: String = "kg", + val groupName: String? = null ) : Parcelable { @IgnoredOnParcel val length: String @@ -51,7 +52,8 @@ data class PackageData( dimensions = "", weight = "", isSelected = false, - isLetter = false + isLetter = false, + groupName = null ) } } From 8b3ca4b2d52c5743f5443789ef423ca2ded21d40 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:14:00 -0300 Subject: [PATCH 27/36] Display Carrier Group name as the Package caption when available --- .../wooshippinglabels/WooShippingLabelCreationScreen.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index e2a1f78d120..bc752608e3f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -426,7 +426,9 @@ private fun PackageSelectionAvailableCard( ) { Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { Text( - text = stringResource(id = packageData.descriptionResId), + text = packageData.groupName + ?.takeIf { it.isNotEmpty() } + ?: stringResource(id = packageData.descriptionResId), style = MaterialTheme.typography.caption, color = colorResource(id = R.color.color_on_surface_disabled) ) From 446b31e076c1102d6dbd08267fe1ea0747423dab Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:26:22 -0300 Subject: [PATCH 28/36] Configure PackageData to flag if it's a predefined package or not --- .../packages/datasource/FetchPredefinedPackagesFromStore.kt | 2 ++ .../ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt index 549b2fefe4a..d9cc1cea51f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStore.kt @@ -31,6 +31,7 @@ class FetchPredefinedPackagesFromStore @Inject constructor( dimensions = packageDAO.dimensions, weight = packageDAO.weight, isSelected = false, + isPredefined = true, isLetter = packageDAO.isLetter, dimensionUnit = packageDAO.dimensionUnit, weightUnit = packageDAO.weightUnit, @@ -60,6 +61,7 @@ class FetchPredefinedPackagesFromStore @Inject constructor( dimensions = packageItem.dimensions, weight = packageItem.weight, isSelected = false, + isPredefined = true, isLetter = packageItem.isLetter, dimensionUnit = packageItem.dimensionUnit, weightUnit = packageItem.weightUnit, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 71f0d55d8f5..9464e6f0b69 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -14,6 +14,7 @@ data class PackageData( val weight: String, val isSelected: Boolean, val isLetter: Boolean, + val isPredefined: Boolean = false, val dimensionUnit: String = "cm", val weightUnit: String = "kg", val groupName: String? = null @@ -87,7 +88,8 @@ data class CustomPackageCreationData( weight = weight.orEmpty(), isSelected = true, isLetter = type == PackageType.ENVELOPE, - dimensionUnit = dimensionUnit + dimensionUnit = dimensionUnit, + isPredefined = saveAsTemplate ) companion object { From 9edc0938b364a10d4065c21cefca7f44261d1684 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:40:27 -0300 Subject: [PATCH 29/36] Configure star icon for predefined packages --- .../WooShippingLabelCreationScreen.kt | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index bc752608e3f..6c05a52a6ea 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -27,6 +27,8 @@ import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.filled.Star +import androidx.compose.material.icons.outlined.Star import androidx.compose.material.rememberBottomSheetScaffoldState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -424,27 +426,48 @@ private fun PackageSelectionAvailableCard( ) .padding(dimensionResource(id = R.dimen.major_125)), ) { - Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { - Text( - text = packageData.groupName - ?.takeIf { it.isNotEmpty() } - ?: stringResource(id = packageData.descriptionResId), - style = MaterialTheme.typography.caption, - color = colorResource(id = R.color.color_on_surface_disabled) - ) - Text( - text = packageData.name - .takeIf { it.isNotEmpty() } - ?: stringResource(id = R.string.shipping_label_package_default_name), - style = MaterialTheme.typography.body1 - ) - Text( - text = packageData.weight - .takeIf { it.isNotEmpty() } - ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } - ?: packageData.dimensionForDisplay, - style = MaterialTheme.typography.body2 - ) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.fillMaxWidth() + ) { + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text( + text = packageData.groupName + ?.takeIf { it.isNotEmpty() } + ?: stringResource(id = packageData.descriptionResId), + style = MaterialTheme.typography.caption, + color = colorResource(id = R.color.color_on_surface_disabled) + ) + Text( + text = packageData.name + .takeIf { it.isNotEmpty() } + ?: stringResource(id = R.string.shipping_label_package_default_name), + style = MaterialTheme.typography.body1 + ) + Text( + text = packageData.weight + .takeIf { it.isNotEmpty() } + ?.let { "${packageData.dimensionForDisplay} • ${packageData.weightForDisplay}" } + ?: packageData.dimensionForDisplay, + style = MaterialTheme.typography.body2 + ) + } + + if (packageData.isPredefined) { + Icon( + tint = colorResource(id = R.color.woo_yellow_20), + imageVector = Icons.Filled.Star, + contentDescription = "Star", + ) + } else { + Icon( + tint = colorResource(id = R.color.color_on_surface_disabled), + imageVector = Icons.Outlined.Star, + contentDescription = "Star", + ) + } + } } } From b9e947e3644145240337d239c2877a90190d61b5 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 18:46:50 -0300 Subject: [PATCH 30/36] Update unit tests with new business logic --- .../datasource/FetchPredefinedPackagesFromStoreTest.kt | 9 ++++++--- .../packages/ui/CustomPackageCreationDataTest.kt | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt index 3ed7d7910ca..6e9d590ad66 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/datasource/FetchPredefinedPackagesFromStoreTest.kt @@ -42,14 +42,16 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { dimensions = "dimensions", weight = "weight", isSelected = false, - isLetter = false + isLetter = false, + isPredefined = true ), PackageData( name = "Saved Package 2", dimensions = "dimensions", weight = "weight", isSelected = false, - isLetter = false + isLetter = false, + isPredefined = true ) ) assertThat(result.carrierPackages[Carrier.USPS]).containsExactly( @@ -61,7 +63,8 @@ class FetchPredefinedPackagesFromStoreTest : BaseUnitTest() { dimensions = "dimensions", weight = "weight", isSelected = false, - isLetter = false + isLetter = false, + isPredefined = true ) ) ) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/CustomPackageCreationDataTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/CustomPackageCreationDataTest.kt index 67549d82e48..e011b4d93c3 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/CustomPackageCreationDataTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/CustomPackageCreationDataTest.kt @@ -75,7 +75,7 @@ class CustomPackageCreationDataTest { val packageData = data.toPackageData() assertThat(packageData.name).isEqualTo("") - assertThat(packageData.dimensions).isEqualTo("10 x 10 x 10 cm") + assertThat(packageData.dimensions).isEqualTo("10 x 10 x 10") assertThat(packageData.isSelected).isTrue assertThat(packageData.isLetter).isFalse } @@ -93,7 +93,7 @@ class CustomPackageCreationDataTest { val packageData = data.toPackageData() assertThat(packageData.name).isEqualTo("") - assertThat(packageData.dimensions).isEqualTo("10 x 10 x 10 cm") + assertThat(packageData.dimensions).isEqualTo("10 x 10 x 10") assertThat(packageData.isSelected).isTrue assertThat(packageData.isLetter).isTrue } From ea74dec62eb438f6b2a56324df6c5ccb5923745e Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 19:02:28 -0300 Subject: [PATCH 31/36] Add unit test coverage for WooShippingLabelCreationViewModel.onPackageSelected --- .../WooShippingLabelCreationViewModelTest.kt | 69 ++++++++++++++++--- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt index 497fc4b2b8b..7e50993991a 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt @@ -1,12 +1,16 @@ package com.woocommerce.android.ui.orders.wooshippinglabels import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.asLiveData import com.woocommerce.android.model.Order import com.woocommerce.android.ui.orders.OrderTestUtils import com.woocommerce.android.ui.orders.details.OrderDetailRepository +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.PackageSelectionState.DataAvailable import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.WooShippingViewState +import com.woocommerce.android.ui.orders.wooshippinglabels.WooShippingLabelCreationViewModel.WooShippingViewState.DataState import com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress import com.woocommerce.android.ui.orders.wooshippinglabels.models.ShippableItemModel +import com.woocommerce.android.ui.orders.wooshippinglabels.packages.ui.PackageData import com.woocommerce.android.util.CurrencyFormatter import com.woocommerce.android.viewmodel.BaseUnitTest import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -22,6 +26,7 @@ import org.mockito.kotlin.whenever import java.math.BigDecimal import kotlin.test.assertEquals import kotlin.test.assertIs +import org.assertj.core.api.Assertions.assertThat @OptIn(ExperimentalCoroutinesApi::class) class WooShippingLabelCreationViewModelTest : BaseUnitTest() { @@ -110,8 +115,8 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { createViewModel() val currentViewState = sut.viewState.value - assert(currentViewState is WooShippingViewState.DataState) - val dataState = currentViewState as WooShippingViewState.DataState + assert(currentViewState is DataState) + val dataState = currentViewState as DataState assert(dataState.shippingLines.isEmpty()) } @@ -128,8 +133,8 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { createViewModel() val currentViewState = sut.viewState.value - assert(currentViewState is WooShippingViewState.DataState) - val dataState = currentViewState as WooShippingViewState.DataState + assert(currentViewState is DataState) + val dataState = currentViewState as DataState assert(dataState.shippingLines.isNotEmpty()) assertEquals(dataState.shippingLines.size, defaultShippingLines.size) } @@ -175,8 +180,8 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { createViewModel() val currentViewState = sut.viewState.value - assert(currentViewState is WooShippingViewState.DataState) - val dataState = currentViewState as WooShippingViewState.DataState + assert(currentViewState is DataState) + val dataState = currentViewState as DataState assertEquals(dataState.shippingAddresses.originAddresses.size, defaultOriginAddresses.size) val ids = dataState.shippingAddresses.originAddresses.map { it.id } assert(ids.containsAll(defaultOriginAddresses.map { it.id })) @@ -195,8 +200,8 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { createViewModel() val currentViewState = sut.viewState.value - assert(currentViewState is WooShippingViewState.DataState) - val dataState = currentViewState as WooShippingViewState.DataState + assert(currentViewState is DataState) + val dataState = currentViewState as DataState assertIs(dataState.shippingRates) } @@ -213,8 +218,8 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { createViewModel() val currentViewState = sut.viewState.value - assert(currentViewState is WooShippingViewState.DataState) - val dataState = currentViewState as WooShippingViewState.DataState + assert(currentViewState is DataState) + val dataState = currentViewState as DataState assertIs(dataState.shippingRates) } @@ -267,4 +272,48 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { verify(getShippingRates, times(1)).invoke(any(), any()) } + + @Test + fun `onPackageSelected updates state to DataAvailable when current state is DataAvailable`() = testBlocking { + var currentViewState: WooShippingViewState? = null + val order = OrderTestUtils.generateTestOrder(orderId = orderId).copy( + shippingLines = defaultShippingLines + ) + whenever(orderDetailRepository.getOrderById(any())) doReturn order + whenever(getShippableItems(any())) doReturn defaultShippableItems + whenever(observeOriginAddresses()) doReturn flowOf(defaultOriginAddresses) + whenever(getShippingRates(any(), any())) doReturn Result.success(defaultShippingRates) + + createViewModel() + sut.viewState.asLiveData().observeForever { + currentViewState = it + } + + val initialPackageData = PackageData( + name = "Initial Package", + dimensions = "5 x 5 x 5", + weight = "0.5", + isSelected = true, + isLetter = false + ) + + sut.onPackageSelected(initialPackageData) + + val newPackageData = PackageData( + name = "New Package", + dimensions = "10 x 10 x 10", + weight = "1.5", + isSelected = true, + isLetter = false + ) + + sut.onPackageSelected(newPackageData) + + assertThat(currentViewState).isInstanceOf(DataState::class.java) + val dataState = currentViewState as DataState + + assertThat(dataState.packageSelection).isInstanceOf(DataAvailable::class.java) + val dataAvailable = dataState.packageSelection as DataAvailable + assertThat(dataAvailable.selectedPackage).isEqualTo(newPackageData) + } } From da7e9b6843f25d58291021aa04fb90b8a677c07c Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 19:03:18 -0300 Subject: [PATCH 32/36] Improve unit test coverage for WooShippingLabelCreationViewModel.onPackageSelected --- .../WooShippingLabelCreationViewModelTest.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt index 7e50993991a..65bcaf83dc1 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt @@ -273,6 +273,40 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() { verify(getShippingRates, times(1)).invoke(any(), any()) } + @Test + fun `onPackageSelected updates state to DataAvailable when current state is NotSelected`() = testBlocking { + var currentViewState: WooShippingViewState? = null + val order = OrderTestUtils.generateTestOrder(orderId = orderId).copy( + shippingLines = defaultShippingLines + ) + whenever(orderDetailRepository.getOrderById(any())) doReturn order + whenever(getShippableItems(any())) doReturn defaultShippableItems + whenever(observeOriginAddresses()) doReturn flowOf(defaultOriginAddresses) + whenever(getShippingRates(any(), any())) doReturn Result.success(defaultShippingRates) + + createViewModel() + sut.viewState.asLiveData().observeForever { + currentViewState = it + } + + val initialPackageData = PackageData( + name = "Initial Package", + dimensions = "5 x 5 x 5", + weight = "0.5", + isSelected = true, + isLetter = false + ) + + sut.onPackageSelected(initialPackageData) + + assertThat(currentViewState).isInstanceOf(DataState::class.java) + val dataState = currentViewState as DataState + + assertThat(dataState.packageSelection).isInstanceOf(DataAvailable::class.java) + val dataAvailable = dataState.packageSelection as DataAvailable + assertThat(dataAvailable.selectedPackage).isEqualTo(initialPackageData) + } + @Test fun `onPackageSelected updates state to DataAvailable when current state is DataAvailable`() = testBlocking { var currentViewState: WooShippingViewState? = null From 45f26e2a774bd560cda7fc10f9d776b4ef726108 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 19:04:03 -0300 Subject: [PATCH 33/36] Fix lint issues --- .../orders/wooshippinglabels/WooShippingLabelCreationScreen.kt | 1 - .../wooshippinglabels/WooShippingLabelCreationViewModelTest.kt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 6c05a52a6ea..6e8ad27b80d 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -467,7 +467,6 @@ private fun PackageSelectionAvailableCard( contentDescription = "Star", ) } - } } } diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt index 65bcaf83dc1..600b453ff61 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModelTest.kt @@ -15,6 +15,7 @@ import com.woocommerce.android.util.CurrencyFormatter import com.woocommerce.android.viewmodel.BaseUnitTest import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf +import org.assertj.core.api.Assertions.assertThat import org.junit.Test import org.mockito.kotlin.any import org.mockito.kotlin.doAnswer @@ -26,7 +27,6 @@ import org.mockito.kotlin.whenever import java.math.BigDecimal import kotlin.test.assertEquals import kotlin.test.assertIs -import org.assertj.core.api.Assertions.assertThat @OptIn(ExperimentalCoroutinesApi::class) class WooShippingLabelCreationViewModelTest : BaseUnitTest() { From 4d0d84a531d8e49926f89db32e478b295cf62d81 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 19:10:58 -0300 Subject: [PATCH 34/36] Fix incorrect scroll for the Custom package form --- .../packages/ui/WooShippingCustomPackageScreen.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt index d2e91b9298d..12b568b4583 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/WooShippingCustomPackageScreen.kt @@ -80,10 +80,11 @@ fun WooShippingCustomPackageCreationScreen( modifier = modifier .fillMaxSize() .padding(16.dp) - .verticalScroll(rememberScrollState()) ) { Column( - modifier = modifier.weight(1f), + modifier = modifier + .weight(1f) + .verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(16.dp) ) { Column(modifier = modifier) { From d068e033d812ae3dd3e78d83c1a2b830de0dd544 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Thu, 12 Dec 2024 19:13:06 -0300 Subject: [PATCH 35/36] Set optional name for PackageData when parsing from CustomPackageCreationData --- .../android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt index 9464e6f0b69..6708dda82af 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/packages/ui/UIModels.kt @@ -83,7 +83,7 @@ data class CustomPackageCreationData( } fun toPackageData(dimensionUnit: String = "cm") = PackageData( - name = "", + name = name.orEmpty(), dimensions = "$length x $width x $height", weight = weight.orEmpty(), isSelected = true, From 5aff9b32aff8c802950064003fff935aad6582f8 Mon Sep 17 00:00:00 2001 From: ThomazFB Date: Fri, 13 Dec 2024 01:46:50 -0300 Subject: [PATCH 36/36] Replace Package Edit Icon with the Material Edit Icon --- .../orders/wooshippinglabels/WooShippingLabelCreationScreen.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 6e8ad27b80d..d2e85affef7 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -27,6 +27,7 @@ import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Star import androidx.compose.material.icons.outlined.Star import androidx.compose.material.rememberBottomSheetScaffoldState @@ -410,7 +411,7 @@ private fun PackageSelectionAvailableCard( onClick = onSelectPackageClick ) { Icon( - painter = painterResource(id = R.drawable.ic_edit), + imageVector = Icons.Filled.Edit, tint = colorResource(id = R.color.color_icon_menu), contentDescription = stringResource(id = R.string.shipping_label_package_selected_description) )