Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shipping Labels Revamp] Handle Package selection on the main form #13111

Merged
merged 38 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b22eb68
Fix WooShippingCarrierPackageScreen scrolling
ThomazFB Dec 11, 2024
7ae716c
Update result handling in WooShippingLabelPackageCreationFragment to …
ThomazFB Dec 11, 2024
7108277
Intercept PackageData result from Package selection fragment
ThomazFB Dec 11, 2024
b03f531
Remove incorrect Bundle creation from WooShippingLabelPackageCreation…
ThomazFB Dec 11, 2024
aa13f44
Merge branch 'trunk' into issue/handle-selected-package
ThomazFB Dec 12, 2024
036e3d8
Introduce PackageData.EMPTY field
ThomazFB Dec 12, 2024
bdfe545
Refactor WooShippingLabelCreationViewModel to support PackageData han…
ThomazFB Dec 12, 2024
2ed22bc
Update GetShippingRates with PackageData
ThomazFB Dec 12, 2024
48746ad
Implement WooShippingLabelCreationViewModel.onPackageSelected
ThomazFB Dec 12, 2024
85477d2
Connect PackageSelection state with ViewState
ThomazFB Dec 12, 2024
c8a8eba
Fix lint issues
ThomazFB Dec 12, 2024
680eb03
Merge branch 'trunk' into issue/handle-selected-package
ThomazFB Dec 12, 2024
2d25059
Rename PackageSelectionState property
ThomazFB Dec 12, 2024
c2e3455
Wire PackageSelectionState into WooShippingLabelCreationScreen
ThomazFB Dec 12, 2024
5acc008
Set basic WooShippingLabelCreationScreen structure for Package contro…
ThomazFB Dec 12, 2024
ec5e6be
Introduce initial package selection UI
ThomazFB Dec 12, 2024
dfe329d
Add dedicated Preview for Package selection
ThomazFB Dec 12, 2024
fb244ab
Add Border outline to Package Selection card
ThomazFB Dec 12, 2024
e143ed6
Configure Selected Package header
ThomazFB Dec 12, 2024
672981b
Simplify WooShippingLabelCreationScreen Package sections
ThomazFB Dec 12, 2024
a1372b2
Rename PackageSelectionState.Data to DataAvailable
ThomazFB Dec 12, 2024
a3b1fd8
Remove unwanted modifier placement from PackageCard
ThomazFB Dec 12, 2024
a1a5ad9
Adjust color and string resources from Package card
ThomazFB Dec 12, 2024
377d342
Revert modifier placement and adjust Package selected title
ThomazFB Dec 12, 2024
d580321
Update Package edit button tint
ThomazFB Dec 12, 2024
b793188
Handle PackageData name when it's not available
ThomazFB Dec 12, 2024
d6428df
Adjust Custom Package unit parameter
ThomazFB Dec 12, 2024
7b851f9
Map Carrier group name into PackageData when available
ThomazFB Dec 12, 2024
8b3ca4b
Display Carrier Group name as the Package caption when available
ThomazFB Dec 12, 2024
446b31e
Configure PackageData to flag if it's a predefined package or not
ThomazFB Dec 12, 2024
9edc093
Configure star icon for predefined packages
ThomazFB Dec 12, 2024
b9e947e
Update unit tests with new business logic
ThomazFB Dec 12, 2024
ea74dec
Add unit test coverage for WooShippingLabelCreationViewModel.onPackag…
ThomazFB Dec 12, 2024
da7e9b6
Improve unit test coverage for WooShippingLabelCreationViewModel.onPa…
ThomazFB Dec 12, 2024
45f26e2
Fix lint issues
ThomazFB Dec 12, 2024
4d0d84a
Fix incorrect scroll for the Custom package form
ThomazFB Dec 12, 2024
d068e03
Set optional name for PackageData when parsing from CustomPackageCrea…
ThomazFB Dec 12, 2024
5aff9b3
Replace Package Edit Icon with the Material Edit Icon
ThomazFB Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,7 @@ class GetShippingRates @Inject constructor() {
}

suspend operator fun invoke(
selectedPackage: PackageDAO,
selectedPackage: PackageData,
sortOrder: ShippingSortOption
): Result<Map<Carrier, List<ShippingRateUI>>> {
delay(1_000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -59,4 +63,10 @@ class WooShippingLabelCreationFragment : BaseFragment() {
}
}
}

private fun setupResultHandlers() {
handleResult<PackageData>(PACKAGE_SELECTION_RESULT) {
viewModel.onPackageSelected(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +27,9 @@ 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
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
Expand All @@ -48,7 +52,11 @@ 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.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

@Composable
fun WooShippingLabelCreationScreen(viewModel: WooShippingLabelCreationViewModel) {
Expand All @@ -67,6 +75,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,
Expand All @@ -87,6 +96,7 @@ fun WooShippingLabelCreationScreen(
shippableItems: ShippableItemsUI,
shippingLines: List<ShippingLineSummaryUI>,
shippingRatesState: WooShippingLabelCreationViewModel.ShippingRatesState,
packageSelectionState: PackageSelectionState,
shippingAddresses: WooShippingAddresses,
onShippingFromAddressChange: (OriginShippingAddress) -> Unit,
onShippingToAddressChange: (Address) -> Unit,
Expand All @@ -106,6 +116,7 @@ fun WooShippingLabelCreationScreen(
shippingLines = shippingLines,
shippingAddresses = shippingAddresses,
shippingRatesState = shippingRatesState,
packageSelectionState = packageSelectionState,
onShippingFromAddressChange = onShippingFromAddressChange,
onShippingToAddressChange = onShippingToAddressChange,
onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged,
Expand Down Expand Up @@ -145,6 +156,7 @@ private fun LabelCreationScreenWithBottomSheet(
shippableItems: ShippableItemsUI,
shippingLines: List<ShippingLineSummaryUI>,
shippingRatesState: WooShippingLabelCreationViewModel.ShippingRatesState,
packageSelectionState: PackageSelectionState,
onSelectPackageClick: () -> Unit,
shippingAddresses: WooShippingAddresses,
onShippingFromAddressChange: (OriginShippingAddress) -> Unit,
Expand Down Expand Up @@ -209,6 +221,7 @@ private fun LabelCreationScreenWithBottomSheet(
)
PackageCard(
modifier = Modifier.padding(16.dp),
packageSelectionState = packageSelectionState,
onSelectPackageClick = onSelectPackageClick
)
WooShippingShippingRatesSection(
Expand Down Expand Up @@ -272,35 +285,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,
onShippingFromAddressChange = {},
onShippingToAddressChange = {},
onRefreshShippingRates = {},
onSelectedRateSortOrderChanged = {}
)
}
}

@Composable
internal fun HazmatCard(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -337,16 +321,27 @@ 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) {
is NotSelected -> SelectPackageCard(
modifier = modifier,
onSelectPackageClick = onSelectPackageClick
)
is DataAvailable -> PackageSelectionAvailableCard(
modifier = modifier,
packageData = packageSelectionState.selectedPackage,
onSelectPackageClick = onSelectPackageClick
)
}
}

@Composable
private fun PackageCard(
private fun SelectPackageCard(
modifier: Modifier = Modifier,
onSelectPackageClick: () -> Unit
) {
Expand Down Expand Up @@ -395,14 +390,86 @@ private fun PackageCard(
}
}

@Preview
@Composable
private fun PackageCardPreview() {
WooThemeWithBackground {
PackageCard(
modifier = Modifier.padding(16.dp),
onSelectPackageClick = {}
)
private fun PackageSelectionAvailableCard(
modifier: Modifier = Modifier,
packageData: PackageData,
onSelectPackageClick: () -> Unit
) {
Column(modifier = modifier.background(color = MaterialTheme.colors.surface)) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = stringResource(id = R.string.shipping_label_package_selected_title),
style = MaterialTheme.typography.subtitle1,
fontWeight = FontWeight.SemiBold
)
IconButton(
onClick = onSelectPackageClick
) {
Icon(
imageVector = Icons.Filled.Edit,
tint = colorResource(id = R.color.color_icon_menu),
contentDescription = stringResource(id = R.string.shipping_label_package_selected_description)
)
}
}
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_125)),
) {
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",
)
}
}
}
}
}

Expand All @@ -422,3 +489,74 @@ 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 = NotSelected,
onShippingFromAddressChange = {},
onShippingToAddressChange = {},
onRefreshShippingRates = {},
onSelectedRateSortOrderChanged = {}
)
}
}

@Preview
@Composable
private fun HazmatCardPreview() {
WooThemeWithBackground {
HazmatCard(modifier = Modifier.padding(16.dp))
}
}

@Preview
@Composable
private fun PackageNotSelectedPreview() {
WooThemeWithBackground {
PackageCard(
modifier = Modifier.padding(16.dp),
packageSelectionState = NotSelected,
onSelectPackageClick = {}
)
}
}

@Preview
@Composable
private fun PackageSelectedPreview() {
WooThemeWithBackground {
PackageCard(
modifier = Modifier.padding(16.dp),
packageSelectionState = DataAvailable(
selectedPackage = PackageData(
name = "Package 1",
dimensions = "10 x 10 x 10",
weight = "1.5",
isSelected = true,
isLetter = false
),
totalWeight = "1.5"
),
onSelectPackageClick = {}
)
}
}
Loading
Loading