From c3e55ee2ce7ddce1b44c0bf2c0d99c7cc9c1e99b Mon Sep 17 00:00:00 2001 From: Alejo <alejandro.torres.veiga@automattic.com> Date: Wed, 8 Jan 2025 17:41:24 -0300 Subject: [PATCH 1/4] add string resources --- WooCommerce/src/main/res/values/strings.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 8cc104203e8..76ca64ea2d4 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -1309,6 +1309,8 @@ <string name="shipping_label_purchased_tracking_error">We currently do not support Tracking for this carrier</string> <string name="shipping_label_purchased_print_error">Something went wrong with this Shipping Label, try again later</string> <string name="shipping_label_purchased_purchase_failed_error">We can\'t confirm the Shipping Label purchase right now, try again later</string> + <string name="shipping_label_select_origin_default_address">%s (default)</string> + <string name="shipping_label_select_origin_address">Address</string> <!-- From ce1307e850720343436487ab92356bf05564801d Mon Sep 17 00:00:00 2001 From: Alejo <alejandro.torres.veiga@automattic.com> Date: Wed, 8 Jan 2025 17:42:14 -0300 Subject: [PATCH 2/4] use formatted name in origin address --- .../address/AddressSection.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt index 5bbd956ecce..c1a98e7cbdd 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt @@ -1,5 +1,6 @@ package com.woocommerce.android.ui.orders.wooshippinglabels.address +import android.content.Context import androidx.compose.animation.animateColorAsState import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box @@ -26,6 +27,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.painterResource @@ -36,6 +38,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.Dimension import com.woocommerce.android.R +import com.woocommerce.android.extensions.isNotNullOrEmpty import com.woocommerce.android.model.Address import com.woocommerce.android.model.AmbiguousLocation import com.woocommerce.android.model.Location @@ -422,7 +425,7 @@ fun AddressSelectionItem( Row { Column(modifier = Modifier.weight(1f)) { Text( - text = "Address Name", + text = address.getFormatedName(LocalContext.current), fontWeight = FontWeight.Bold, modifier = Modifier ) @@ -492,3 +495,17 @@ internal fun getShipTo() = Address( country = Location("US", "USA"), state = AmbiguousLocation.Defined(Location("CA", "California", "USA")) ) + +fun OriginShippingAddress.getFormatedName(context: Context): String { + val name = if (firstName.isNotNullOrEmpty() || lastName.isNotNullOrEmpty()) { + "$firstName $lastName" + } else { + company + ?: context.getString(R.string.shipping_label_select_origin_address) + } + return if (this.isDefault) { + context.getString(R.string.shipping_label_select_origin_default_address, name) + } else { + name + } +} From b3c19f0120180a05fb53146746c64aa4a510c17c Mon Sep 17 00:00:00 2001 From: Alejo <alejandro.torres.veiga@automattic.com> Date: Wed, 8 Jan 2025 18:43:08 -0300 Subject: [PATCH 3/4] make the list scrollable --- .../address/AddressSection.kt | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt index c1a98e7cbdd..f898233afd2 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt @@ -11,6 +11,8 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Divider import androidx.compose.material.Icon @@ -367,20 +369,22 @@ fun AddressSelection( bottom = dimensionResource(id = R.dimen.minor_100) ) ) - originAddresses.forEach { option -> - val isSelected = option == shipFrom - AddressSelectionItem( - address = option, - isSelected = isSelected, - onClick = { - onShippingFromAddressChange(option) - }, - modifier = Modifier.padding( - top = dimensionResource(id = R.dimen.minor_100), - start = dimensionResource(id = R.dimen.major_100), - end = dimensionResource(id = R.dimen.major_100) + LazyColumn { + items(originAddresses) { option -> + val isSelected = option == shipFrom + AddressSelectionItem( + address = option, + isSelected = isSelected, + onClick = { + onShippingFromAddressChange(option) + }, + modifier = Modifier.padding( + top = dimensionResource(id = R.dimen.minor_100), + start = dimensionResource(id = R.dimen.major_100), + end = dimensionResource(id = R.dimen.major_100) + ) ) - ) + } } Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.major_100))) }, @@ -425,7 +429,7 @@ fun AddressSelectionItem( Row { Column(modifier = Modifier.weight(1f)) { Text( - text = address.getFormatedName(LocalContext.current), + text = address.getFormattedName(LocalContext.current), fontWeight = FontWeight.Bold, modifier = Modifier ) @@ -496,12 +500,13 @@ internal fun getShipTo() = Address( state = AmbiguousLocation.Defined(Location("CA", "California", "USA")) ) -fun OriginShippingAddress.getFormatedName(context: Context): String { - val name = if (firstName.isNotNullOrEmpty() || lastName.isNotNullOrEmpty()) { - "$firstName $lastName" - } else { - company - ?: context.getString(R.string.shipping_label_select_origin_address) +fun OriginShippingAddress.getFormattedName(context: Context): String { + val name = when { + !firstName.isNullOrEmpty() && !lastName.isNullOrEmpty() -> "$firstName $lastName" + !firstName.isNullOrEmpty() -> firstName + !lastName.isNullOrEmpty() -> lastName + !company.isNullOrEmpty() -> company + else -> context.getString(R.string.shipping_label_select_origin_address) } return if (this.isDefault) { context.getString(R.string.shipping_label_select_origin_default_address, name) From 8482f319a5fc6dc9bfe5a52c3860e7bb60a48bb7 Mon Sep 17 00:00:00 2001 From: Alejo <alejandro.torres.veiga@automattic.com> Date: Thu, 9 Jan 2025 09:32:17 -0300 Subject: [PATCH 4/4] remove unused imports --- .../ui/orders/wooshippinglabels/address/AddressSection.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt index f898233afd2..f84c0d5ac0f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/AddressSection.kt @@ -40,7 +40,6 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.Dimension import com.woocommerce.android.R -import com.woocommerce.android.extensions.isNotNullOrEmpty import com.woocommerce.android.model.Address import com.woocommerce.android.model.AmbiguousLocation import com.woocommerce.android.model.Location