-
Notifications
You must be signed in to change notification settings - Fork 131
[Shipping labels] Remove shipment sheet #13924
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
45c1829
Add ic_remove_shipment icon
irfano a7b854e
Add string resources for the remove shipment sheet
irfano 3d87f88
Add RemoveBottomSheet compose
irfano f9a68ca
Add previews for RemoveShipmentBottomSheet compose
irfano 2e310a4
Rename removeShipmentSheet() function to onRemoveShipmentMenuTapped()
irfano 0e005f6
Add RemoveShipmentSheet data class
irfano 9e3a59a
Show remove shipment sheet from split shipment screen
irfano 8c9d485
Rename selectableItems to shipmentsUIMap in WooShippingSplitShipmentV…
irfano 25e194a
Remove redundant parameter from onUpdateSelection function
irfano eac6886
Use itemId instead of productId in combine() for ShippableItemModel
irfano 7a8147d
Simplify List<ShippableItemModel>.combine extension function
irfano 1c4f5e7
Merge branch 'issue/WOOMOB-282-fix-split-shipment-move-action' into f…
irfano c9783ae
Rename "ic_remove_shipment" drawable to "ic_arrow_return"
irfano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
234 changes: 234 additions & 0 deletions
234
...in/com/woocommerce/android/ui/orders/wooshippinglabels/split/RemoveShipmentBottomSheet.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
package com.woocommerce.android.ui.orders.wooshippinglabels.split | ||
|
||
import android.content.Context | ||
import android.content.res.Resources | ||
import androidx.compose.foundation.BorderStroke | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
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.rememberScrollState | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.ButtonDefaults | ||
import androidx.compose.material.ButtonDefaults.OutlinedBorderOpacity | ||
|
||
import androidx.compose.material.Icon | ||
|
||
import androidx.compose.material.MaterialTheme | ||
|
||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.rememberModalBottomSheetState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.res.vectorResource | ||
import androidx.compose.ui.text.intl.Locale | ||
import androidx.compose.ui.text.toLowerCase | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.ui.compose.component.WCModalBottomSheet | ||
import com.woocommerce.android.ui.compose.component.WCOutlinedButton | ||
import com.woocommerce.android.util.StringUtils | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun RemoveShipmentBottomSheet( | ||
removeShipmentSheet: RemoveShipmentSheet, | ||
onDismissRemoveSheet: () -> Unit, | ||
onRemoveShipment: (Int, Int) -> Unit | ||
) { | ||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) | ||
var selectedShipmentKeyState by rememberSaveable { | ||
mutableIntStateOf(removeShipmentSheet.otherShipments.keys.first()) | ||
} | ||
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the selected shipment logic is simple, I decided to use the composable as state owner. |
||
|
||
val multipleOtherShipments = removeShipmentSheet.otherShipments.size > 1 | ||
fun getDescription(context: Context) = if (multipleOtherShipments) { | ||
StringUtils.getQuantityString( | ||
context = context, | ||
quantity = removeShipmentSheet.removingShipment.totalItemQuantity, | ||
default = R.string.woo_shipping_split_shipment_bottom_sheet_desc_multiple_shipment_plural, | ||
one = R.string.woo_shipping_split_shipment_bottom_sheet_desc_multiple_shipment_one, | ||
) | ||
} else { | ||
context.getString( | ||
R.string.woo_shipping_split_shipment_bottom_sheet_desc, | ||
context.getString( | ||
R.string.woo_shipping_split_shipment_shipment_name, | ||
(removeShipmentSheet.otherShipments.keys.first() + 1).toString() | ||
).toLowerCase(Locale.current) | ||
) | ||
} | ||
|
||
fun getRemoveButtonText(resources: Resources) = if (multipleOtherShipments) { | ||
resources.getString( | ||
R.string.woo_shipping_split_shipment_shipment_remove, | ||
resources.getString( | ||
R.string.woo_shipping_split_shipment_shipment_name, | ||
(removeShipmentSheet.removingShipmentKey + 1).toString() | ||
) | ||
) | ||
} else { | ||
resources.getString(R.string.woo_shipping_split_shipment_bottom_sheet_remove_button) | ||
} | ||
|
||
WCModalBottomSheet(sheetState = sheetState, onDismissRequest = onDismissRemoveSheet) { | ||
Column( | ||
modifier = Modifier | ||
.padding(start = 16.dp, end = 16.dp, bottom = 19.dp) | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
Text( | ||
text = stringResource(R.string.woo_shipping_split_shipment_bottom_sheet_title), | ||
style = MaterialTheme.typography.h6, | ||
color = MaterialTheme.colors.onSurface | ||
) | ||
Text( | ||
modifier = Modifier.padding(top = 8.dp, bottom = 16.dp), | ||
text = getDescription(LocalContext.current), | ||
style = MaterialTheme.typography.subtitle1, | ||
color = MaterialTheme.colors.onSurface | ||
) | ||
if (multipleOtherShipments) { | ||
removeShipmentSheet.otherShipments.forEach { | ||
ShipmentCard( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 8.dp) | ||
.clickable { selectedShipmentKeyState = it.key }, | ||
shipment = it, | ||
isSelected = it.key == selectedShipmentKeyState, | ||
) | ||
} | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
} | ||
WCOutlinedButton( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 8.dp), | ||
border = BorderStroke(1.dp, MaterialTheme.colors.error), | ||
onClick = { onRemoveShipment(removeShipmentSheet.removingShipmentKey, selectedShipmentKeyState) } | ||
) { | ||
Text( | ||
text = getRemoveButtonText(LocalContext.current.resources), | ||
color = MaterialTheme.colors.error | ||
) | ||
} | ||
WCOutlinedButton( | ||
modifier = Modifier.fillMaxWidth(), | ||
text = stringResource(R.string.cancel), | ||
colors = ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colors.onSurface), | ||
onClick = onDismissRemoveSheet | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ShipmentCard( | ||
modifier: Modifier, | ||
shipment: Map.Entry<Int, SelectableShippableItemsUI>, | ||
isSelected: Boolean = false | ||
) { | ||
val borderWidth = if (isSelected) 2.dp else 0.5.dp | ||
val borderColor = if (isSelected) { | ||
MaterialTheme.colors.primary | ||
} else { | ||
MaterialTheme.colors.onSurface.copy(alpha = OutlinedBorderOpacity) | ||
} | ||
val containerColor = if (isSelected) R.color.color_item_selected else R.color.color_surface | ||
|
||
val items = StringUtils.getQuantityString( | ||
context = LocalContext.current, | ||
quantity = shipment.value.totalItemQuantity, | ||
default = R.string.shipping_label_package_details_items_count_many, | ||
one = R.string.shipping_label_package_details_items_count_one, | ||
) | ||
|
||
Card( | ||
modifier = modifier, | ||
shape = RoundedCornerShape(8.dp), | ||
colors = CardDefaults.cardColors(containerColor = colorResource(containerColor)), | ||
border = BorderStroke(borderWidth, borderColor), | ||
) { | ||
Row(modifier = Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(id = R.drawable.ic_arrow_return), | ||
contentDescription = null, | ||
tint = if (isSelected) borderColor else Color.Unspecified | ||
) | ||
Spacer(Modifier.padding(horizontal = 16.dp)) | ||
Column { | ||
Text( | ||
text = stringResource( | ||
R.string.woo_shipping_split_shipment_shipment_name, | ||
shipment.key + 1 | ||
), | ||
style = MaterialTheme.typography.subtitle1, | ||
color = MaterialTheme.colors.onSurface | ||
) | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.Absolute.SpaceBetween | ||
) { | ||
Text( | ||
text = items, | ||
style = MaterialTheme.typography.subtitle2, | ||
color = MaterialTheme.colors.onSurface | ||
) | ||
Text( | ||
text = stringResource( | ||
R.string.shipping_label_package_details_items_weight_price, | ||
shipment.value.formattedTotalWeight, | ||
shipment.value.formattedTotalPrice | ||
), | ||
style = MaterialTheme.typography.subtitle2, | ||
color = MaterialTheme.colors.onSurface | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun ShipmentCardPreview() = ShipmentCard( | ||
modifier = Modifier.fillMaxWidth(), | ||
shipment = mapOf( | ||
3 to SelectableShippableItemsUI( | ||
shippableItems = emptyList(), | ||
"550g", | ||
"$50.00" | ||
) | ||
).entries.first() | ||
) | ||
|
||
@Preview | ||
@Composable | ||
private fun ShipmentCardSelectedPreview() = ShipmentCard( | ||
modifier = Modifier.fillMaxWidth(), | ||
shipment = mapOf( | ||
2 to SelectableShippableItemsUI( | ||
shippableItems = emptyList(), | ||
"825g", | ||
"$75.00" | ||
) | ||
).entries.first(), | ||
isSelected = true | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.