Skip to content

Commit

Permalink
Merge pull request #13274 from woocommerce/issue/12439-update-address…
Browse files Browse the repository at this point in the history
…-name

Update address name
  • Loading branch information
atorresveiga authored Jan 9, 2025
2 parents c2c1e55 + 8482f31 commit 0350c4b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,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
Expand All @@ -26,6 +29,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
Expand Down Expand Up @@ -364,20 +368,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)))
},
Expand Down Expand Up @@ -422,7 +428,7 @@ fun AddressSelectionItem(
Row {
Column(modifier = Modifier.weight(1f)) {
Text(
text = "Address Name",
text = address.getFormattedName(LocalContext.current),
fontWeight = FontWeight.Bold,
modifier = Modifier
)
Expand Down Expand Up @@ -492,3 +498,18 @@ internal fun getShipTo() = Address(
country = Location("US", "USA"),
state = AmbiguousLocation.Defined(Location("CA", "California", "USA"))
)

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)
} else {
name
}
}
2 changes: 2 additions & 0 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>


<!--
Expand Down

0 comments on commit 0350c4b

Please sign in to comment.