diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt index 77e53c26961..286b05a555f 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationFragment.kt @@ -60,6 +60,13 @@ class WooShippingLabelCreationFragment : BaseFragment(), BackPressListener { purchaseData = event.purchaseData ).let { findNavController().navigateSafely(it) } } + + is WooShippingLabelCreationViewModel.StartOriginAddressEdit -> + WooShippingLabelCreationFragmentDirections + .actionWooShippingLabelCreationFragmentToWooShippingEditOriginAddressFragment( + originAddress = event.originAddress + ).let { findNavController().navigateSafely(it) } + is MultiLiveEvent.Event.Exit -> findNavController().navigateUp() } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt index 1e3bb755be8..190f561e783 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationScreen.kt @@ -94,6 +94,7 @@ fun WooShippingLabelCreationScreen(viewModel: WooShippingLabelCreationViewModel) shippingRatesState = viewState.shippingRates, packageSelectionState = viewState.packageSelection, onShippingFromAddressChange = viewModel::onShippingFromAddressChange, + onEditOriginAddress = viewModel::onEditOriginAddress, onSelectedRateSortOrderChanged = viewModel::onSelectedRateSortOrderChanged, onRefreshShippingRates = viewModel::onRefreshShippingRates, onSelectedSippingRateChanged = viewModel::onSelectedSippingRateChanged, @@ -124,6 +125,7 @@ fun WooShippingLabelCreationScreen( packageSelectionState: PackageSelectionState, shippingAddresses: WooShippingAddresses, onShippingFromAddressChange: (OriginShippingAddress) -> Unit, + onEditOriginAddress: (OriginShippingAddress) -> Unit, onSelectPackageClick: () -> Unit, onPurchaseShippingLabel: () -> Unit, onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit, @@ -185,6 +187,7 @@ fun WooShippingLabelCreationScreen( shippingRatesState = shippingRatesState, packageSelectionState = packageSelectionState, onShippingFromAddressChange = onShippingFromAddressChange, + onEditOriginAddress = onEditOriginAddress, onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged, onRefreshShippingRates = onRefreshShippingRates, customWeight = customWeight, @@ -253,6 +256,7 @@ private fun LabelCreationScreenWithBottomSheet( packageSelectionState: PackageSelectionState, onSelectPackageClick: () -> Unit, shippingAddresses: WooShippingAddresses, + onEditOriginAddress: (OriginShippingAddress) -> Unit, onShippingFromAddressChange: (OriginShippingAddress) -> Unit, onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit, onRefreshShippingRates: () -> Unit, @@ -281,6 +285,7 @@ private fun LabelCreationScreenWithBottomSheet( onShippingFromAddressChange = onShippingFromAddressChange, modalBottomSheetState = shipFromSelectionBottomSheetState, modifier = Modifier.padding(bottom = paddingBottom), + onEditOriginAddress = onEditOriginAddress ) { ShipmentDetails( shippableItems = shippableItems, @@ -638,6 +643,7 @@ private fun WooShippingLabelCreationScreenPreview() { onSelectedSippingRateChanged = {}, onMarkOrderCompleteChange = {}, onNavigateBack = {}, + onEditOriginAddress = {}, purchaseState = WooShippingLabelCreationViewModel.PurchaseState.NoStarted, uiState = WooShippingLabelCreationViewModel.UIControlsState( markOrderComplete = false, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt index 175ecf155c9..fc3854779eb 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/WooShippingLabelCreationViewModel.kt @@ -304,6 +304,10 @@ class WooShippingLabelCreationViewModel @Inject constructor( } } + fun onEditOriginAddress(address: OriginShippingAddress) { + triggerEvent(StartOriginAddressEdit(address)) + } + fun onShippingToAddressChange(address: Address) { shippingAddresses.value?.let { shippingAddresses.value = it.copy(shipTo = address) @@ -452,16 +456,19 @@ class WooShippingLabelCreationViewModel @Inject constructor( uiState.update { it.copy(isAddressSelectionExpanded = false) } false } + state.isShipmentDetailsExpanded -> { uiState.update { it.copy(isShipmentDetailsExpanded = false) } false } + else -> true } } data object StartPackageSelection : Event() data class LabelPurchased(val purchaseData: PurchasedShippingLabelData) : Event() + data class StartOriginAddressEdit(val originAddress: OriginShippingAddress) : Event() sealed class WooShippingViewState { data object Error : WooShippingViewState() 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 a12ef6afa98..f3cb4f3e766 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 @@ -348,6 +348,7 @@ fun AddressSelection( shipFrom: OriginShippingAddress, originAddresses: List, onShippingFromAddressChange: (OriginShippingAddress) -> Unit, + onEditOriginAddress: (OriginShippingAddress) -> Unit, modifier: Modifier = Modifier, content: @Composable () -> Unit = {} ) { @@ -374,6 +375,7 @@ fun AddressSelection( AddressSelectionItem( address = option, isSelected = isSelected, + onEdit = onEditOriginAddress, onClick = { onShippingFromAddressChange(option) }, @@ -400,6 +402,7 @@ fun AddressSelectionItem( address: OriginShippingAddress, isSelected: Boolean, onClick: () -> Unit, + onEdit: (OriginShippingAddress) -> Unit, modifier: Modifier = Modifier ) { val borderColor = if (isSelected) { @@ -438,7 +441,7 @@ fun AddressSelectionItem( ) } IconButton( - onClick = { } + onClick = { onEdit(address) } ) { Icon( painter = painterResource(id = R.drawable.ic_edit_pencil), diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/WooShippingEditOriginAddressFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/WooShippingEditOriginAddressFragment.kt new file mode 100644 index 00000000000..e9cc75b7ab5 --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/wooshippinglabels/address/origin/WooShippingEditOriginAddressFragment.kt @@ -0,0 +1,36 @@ +package com.woocommerce.android.ui.orders.wooshippinglabels.address.origin + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed +import com.woocommerce.android.ui.base.BaseFragment +import com.woocommerce.android.ui.compose.theme.WooThemeWithBackground +import com.woocommerce.android.ui.main.AppBarStatus +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class WooShippingEditOriginAddressFragment : BaseFragment() { + + override val activityAppBarStatus: AppBarStatus = AppBarStatus.Hidden + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { + return ComposeView(requireContext()).apply { + setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed) + setContent { + WooThemeWithBackground { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text("Edit Origin Address") + } + } + } + } + } +} diff --git a/WooCommerce/src/main/res/navigation/nav_graph_orders.xml b/WooCommerce/src/main/res/navigation/nav_graph_orders.xml index 98884c85774..533c6787a2d 100644 --- a/WooCommerce/src/main/res/navigation/nav_graph_orders.xml +++ b/WooCommerce/src/main/res/navigation/nav_graph_orders.xml @@ -745,6 +745,9 @@ android:id="@+id/action_wooShippingLabelCreationFragment_to_wooShippingLabelPurchasedFragment" app:destination="@id/wooShippingLabelPurchasedFragment" app:popUpTo="@id/orderDetailFragment" /> + + + +