Skip to content

Commit

Permalink
Merge branch 'trunk' into issue/13114-updated-designs-retry-paginatio…
Browse files Browse the repository at this point in the history
…n-error
  • Loading branch information
AnirudhBhat authored Dec 13, 2024
2 parents e2646c4 + a58e05d commit 9b43692
Show file tree
Hide file tree
Showing 22 changed files with 936 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ enum class AnalyticsEvent(override val siteless: Boolean = false) : IAnalyticsEv
PRODUCT_QUICK_INVENTORY_VIEW_PRODUCT_DETAILS_TAPPED,
PRODUCT_QUICK_INVENTORY_UPDATE_BOTTOM_SHEET_SHOWN,

// -- Product Search Via SKU
// -- Product Search Via SKU or Global Unique Identifier
PRODUCT_SEARCH_VIA_SKU_SUCCESS,
PRODUCT_SEARCH_VIA_SKU_FAILURE,
PRODUCT_SEARCH_VIA_GLOBAL_UNIQUE_IDENTIFIER_SUCCESS,

// -- Refunds
CREATE_ORDER_REFUND_NEXT_BUTTON_TAPPED,
Expand Down Expand Up @@ -588,6 +589,7 @@ enum class AnalyticsEvent(override val siteless: Boolean = false) : IAnalyticsEv
PRODUCT_DETAIL_VIEW_DOWNLOADABLE_FILES_TAPPED,
PRODUCT_PRICE_SETTINGS_DONE_BUTTON_TAPPED,
PRODUCT_INVENTORY_SETTINGS_DONE_BUTTON_TAPPED,
PRODUCT_INVENTORY_SETTINGS_GLOBAL_UNIQUE_IDENTIFIER_FIELD_EDITED,
PRODUCT_SHIPPING_SETTINGS_DONE_BUTTON_TAPPED,
PRODUCT_IMAGE_SETTINGS_DONE_BUTTON_TAPPED,
PRODUCT_CATEGORY_SETTINGS_DONE_BUTTON_TAPPED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.woocommerce.android.ui.orders.wooshippinglabels

import com.woocommerce.android.R
import com.woocommerce.android.ui.orders.wooshippinglabels.packages.datasource.PackageDAO
import kotlinx.coroutines.delay
import javax.inject.Inject
import kotlin.random.Random
@Suppress("MagicNumber")
class GetShippingRates @Inject constructor() {
private val cheapestComparator = Comparator<ShippingRateUI> { r1, r2 ->
r1.rate.substring(1).toBigDecimal().compareTo(r2.rate.substring(1).toBigDecimal())
}

private val fastestComparator = Comparator<ShippingRateUI> { r1, r2 ->
r1.deliveryDays.compareTo(r2.deliveryDays)
}

suspend operator fun invoke(
selectedPackage: PackageDAO,
sortOrder: ShippingSortOption
): Result<Map<Carrier, List<ShippingRateUI>>> {
delay(1_000)
val comparator = when (sortOrder) {
ShippingSortOption.CHEAPEST -> {
cheapestComparator
}

ShippingSortOption.FASTEST -> {
fastestComparator
}
}
val carriers = if (selectedPackage.isLetter) {
listOf(
Carrier(
id = "dhl",
name = "DHL Express",
logoRes = R.drawable.dhl_logo
),
Carrier(
id = "usps",
name = "USPS",
logoRes = R.drawable.usps_logo
)
)
} else {
listOf(
Carrier(
id = "dhl",
name = "DHL Express",
logoRes = R.drawable.dhl_logo
),
Carrier(
id = "usps",
name = "USPS",
logoRes = R.drawable.usps_logo
),
Carrier(
id = "ups",
name = "UPS",
logoRes = R.drawable.ups_logo
)
)
}

return Result.success(
carriers.associateWith {
generateRates(
it.name,
Random(0).nextInt(from = 3, until = 10)
).sortedWith(comparator)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Colors
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
Expand Down Expand Up @@ -66,23 +67,24 @@ val Colors.selectedRateBackgroundColor: Color get() = if (isLight) Color(0xFFF2E

@Composable
internal fun ShippingRatesCard(
selected: ShippingRate?,
onSelectedChange: (ShippingRate) -> Unit = {},
shippingRates: Map<Carrier, List<ShippingRate>>,
selectedRate: ShippingRateUI?,
onSelectedChange: (ShippingRateUI) -> Unit,
shippingRates: Map<Carrier, List<ShippingRateUI>>,
signatureRequired: SignatureRequired?,
onSelectedSignatureChange: (SignatureRequired?) -> Unit,
signatureRequiredOptions: List<SignatureRequired>,
selectedSortOption: ShippingSortOption,
onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit,
modifier: Modifier = Modifier
) {
var selectedSortOption by remember { mutableStateOf(ShippingSortOption.CHEAPEST) }
Column(modifier = modifier) {
ShippingRatesHeader(
selectedSortOption = selectedSortOption,
onSortOptionSelected = { selectedSortOption = it },
onSortOptionSelected = onSelectedRateSortOrderChanged,
modifier = Modifier.padding(start = dimensionResource(R.dimen.major_100))
)
ShippingRates(
selected = selected,
selectedRate = selectedRate,
onSelectedChange = onSelectedChange,
shippingRates = shippingRates,
signatureRequired = signatureRequired,
Expand All @@ -100,15 +102,41 @@ private fun ShippingRatesCardPreview() {
val selected = rates.values.first().first()
WooThemeWithBackground {
ShippingRatesCard(
selected = selected,
selectedRate = selected,
shippingRates = generateShippingRates(),
signatureRequired = null,
onSelectedChange = {},
onSelectedSignatureChange = {},
signatureRequiredOptions = listOf(
SignatureRequired("Signature Required", "$10.00"),
SignatureRequired("Adult Signature Required", "$15.00")
)
),
selectedSortOption = ShippingSortOption.CHEAPEST,
onSelectedRateSortOrderChanged = {}
)
}
}

@Composable
internal fun ShippingRatesLoading(
selectedSortOption: ShippingSortOption,
onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
ShippingRatesHeader(
selectedSortOption = selectedSortOption,
onSortOptionSelected = onSelectedRateSortOrderChanged,
modifier = Modifier.padding(start = dimensionResource(R.dimen.major_100))
)
Box(
modifier = Modifier
.fillMaxWidth()
.sizeIn(minHeight = 300.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
}

Expand Down Expand Up @@ -200,9 +228,9 @@ private fun SortingDropdownMenu(
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ShippingRates(
selected: ShippingRate?,
onSelectedChange: (ShippingRate) -> Unit = {},
shippingRates: Map<Carrier, List<ShippingRate>>,
selectedRate: ShippingRateUI?,
onSelectedChange: (ShippingRateUI) -> Unit,
shippingRates: Map<Carrier, List<ShippingRateUI>>,
signatureRequired: SignatureRequired?,
onSelectedSignatureChange: (SignatureRequired?) -> Unit,
signatureRequiredOptions: List<SignatureRequired>,
Expand Down Expand Up @@ -259,7 +287,7 @@ fun ShippingRates(
ShippingRateItem(
carrier = carrier,
shippingRate = rate,
isSelected = selected == rate,
isSelected = selectedRate == rate,
signatureRequired = signatureRequired,
onSelectedSignatureChange = onSelectedSignatureChange,
signatureRequiredOptions = signatureRequiredOptions,
Expand Down Expand Up @@ -288,7 +316,7 @@ private fun CarrierLogo(
@Composable
private fun ShippingRateItem(
carrier: Carrier,
shippingRate: ShippingRate,
shippingRate: ShippingRateUI,
isSelected: Boolean,
signatureRequired: SignatureRequired?,
onSelectedSignatureChange: (SignatureRequired?) -> Unit,
Expand Down Expand Up @@ -363,7 +391,7 @@ private fun ShippingRateItem(

private fun getShippingRateFormattedDescription(
context: Context,
shippingRate: ShippingRate
shippingRate: ShippingRateUI
): AnnotatedString {
return buildAnnotatedString {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
Expand All @@ -383,7 +411,7 @@ private fun getShippingRateFormattedDescription(

@Composable
private fun ShippingRateItemExpandedDescription(
shippingRate: ShippingRate,
shippingRate: ShippingRateUI,
signatureRequired: SignatureRequired?,
onSelectedSignatureChange: (SignatureRequired?) -> Unit,
signatureRequiredOptions: List<SignatureRequired>,
Expand Down Expand Up @@ -455,7 +483,7 @@ private fun SelectSignatureRequired(
}
}

fun ShippingRate.getEstimatedDays(context: Context): String {
fun ShippingRateUI.getEstimatedDays(context: Context): String {
return StringUtils.getQuantityString(
context = context,
quantity = deliveryDays,
Expand All @@ -464,7 +492,7 @@ fun ShippingRate.getEstimatedDays(context: Context): String {
)
}

fun ShippingRate.getIncludedOptions(context: Context): List<String> {
fun ShippingRateUI.getIncludedOptions(context: Context): List<String> {
val options = mutableListOf<String>()
if (tracking) {
val tracking = context.getString(
Expand Down Expand Up @@ -499,7 +527,7 @@ data class Carrier(
val logoRes: Int? = null,
)

data class ShippingRate(
data class ShippingRateUI(
val name: String,
val rate: String,
val currency: String,
Expand All @@ -514,7 +542,7 @@ data class SignatureRequired(
val amount: String,
)

fun generateShippingRates(): Map<Carrier, List<ShippingRate>> {
fun generateShippingRates(): Map<Carrier, List<ShippingRateUI>> {
val carriers = listOf(
Carrier(
id = "dhl",
Expand Down Expand Up @@ -551,11 +579,11 @@ fun generateShippingRates(): Map<Carrier, List<ShippingRate>> {
}
}

fun generateRates(carrier: String, number: Int): List<ShippingRate> {
fun generateRates(carrier: String, number: Int): List<ShippingRateUI> {
return List(number) {
ShippingRate(
ShippingRateUI(
name = "$carrier - Ground Advantage Express",
rate = "$${(it + 1) * 2}.00",
rate = "$${(it + 100) / (it + 1)}.00",
currency = "USD",
deliveryDays = it,
insurance = "$100.00",
Expand Down
Loading

0 comments on commit 9b43692

Please sign in to comment.