Skip to content

Commit

Permalink
Merge pull request #13338 from woocommerce/issue/12439-edit-origin-ad…
Browse files Browse the repository at this point in the history
…dress-navigation

Edit origin address navigation
  • Loading branch information
atorresveiga authored Jan 17, 2025
2 parents 9818b66 + c7342ce commit d167642
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -124,6 +125,7 @@ fun WooShippingLabelCreationScreen(
packageSelectionState: PackageSelectionState,
shippingAddresses: WooShippingAddresses,
onShippingFromAddressChange: (OriginShippingAddress) -> Unit,
onEditOriginAddress: (OriginShippingAddress) -> Unit,
onSelectPackageClick: () -> Unit,
onPurchaseShippingLabel: () -> Unit,
onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit,
Expand Down Expand Up @@ -185,6 +187,7 @@ fun WooShippingLabelCreationScreen(
shippingRatesState = shippingRatesState,
packageSelectionState = packageSelectionState,
onShippingFromAddressChange = onShippingFromAddressChange,
onEditOriginAddress = onEditOriginAddress,
onSelectedRateSortOrderChanged = onSelectedRateSortOrderChanged,
onRefreshShippingRates = onRefreshShippingRates,
customWeight = customWeight,
Expand Down Expand Up @@ -253,6 +256,7 @@ private fun LabelCreationScreenWithBottomSheet(
packageSelectionState: PackageSelectionState,
onSelectPackageClick: () -> Unit,
shippingAddresses: WooShippingAddresses,
onEditOriginAddress: (OriginShippingAddress) -> Unit,
onShippingFromAddressChange: (OriginShippingAddress) -> Unit,
onSelectedRateSortOrderChanged: (ShippingSortOption) -> Unit,
onRefreshShippingRates: () -> Unit,
Expand Down Expand Up @@ -281,6 +285,7 @@ private fun LabelCreationScreenWithBottomSheet(
onShippingFromAddressChange = onShippingFromAddressChange,
modalBottomSheetState = shipFromSelectionBottomSheetState,
modifier = Modifier.padding(bottom = paddingBottom),
onEditOriginAddress = onEditOriginAddress
) {
ShipmentDetails(
shippableItems = shippableItems,
Expand Down Expand Up @@ -638,6 +643,7 @@ private fun WooShippingLabelCreationScreenPreview() {
onSelectedSippingRateChanged = {},
onMarkOrderCompleteChange = {},
onNavigateBack = {},
onEditOriginAddress = {},
purchaseState = WooShippingLabelCreationViewModel.PurchaseState.NoStarted,
uiState = WooShippingLabelCreationViewModel.UIControlsState(
markOrderComplete = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ fun AddressSelection(
shipFrom: OriginShippingAddress,
originAddresses: List<OriginShippingAddress>,
onShippingFromAddressChange: (OriginShippingAddress) -> Unit,
onEditOriginAddress: (OriginShippingAddress) -> Unit,
modifier: Modifier = Modifier,
content: @Composable () -> Unit = {}
) {
Expand All @@ -374,6 +375,7 @@ fun AddressSelection(
AddressSelectionItem(
address = option,
isSelected = isSelected,
onEdit = onEditOriginAddress,
onClick = {
onShippingFromAddressChange(option)
},
Expand All @@ -400,6 +402,7 @@ fun AddressSelectionItem(
address: OriginShippingAddress,
isSelected: Boolean,
onClick: () -> Unit,
onEdit: (OriginShippingAddress) -> Unit,
modifier: Modifier = Modifier
) {
val borderColor = if (isSelected) {
Expand Down Expand Up @@ -438,7 +441,7 @@ fun AddressSelectionItem(
)
}
IconButton(
onClick = { }
onClick = { onEdit(address) }
) {
Icon(
painter = painterResource(id = R.drawable.ic_edit_pencil),
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions WooCommerce/src/main/res/navigation/nav_graph_orders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@
android:id="@+id/action_wooShippingLabelCreationFragment_to_wooShippingLabelPurchasedFragment"
app:destination="@id/wooShippingLabelPurchasedFragment"
app:popUpTo="@id/orderDetailFragment" />
<action
android:id="@+id/action_wooShippingLabelCreationFragment_to_wooShippingEditOriginAddressFragment"
app:destination="@id/wooShippingEditOriginAddressFragment" />
</fragment>
<fragment
android:id="@+id/wooShippingLabelPackageCreationFragment"
Expand All @@ -768,4 +771,12 @@
android:id="@+id/action_wooShippingLabelPurchasedFragment_to_printShippingLabelInfoFragment"
app:destination="@id/printShippingLabelInfoFragment" />
</fragment>
<fragment
android:id="@+id/wooShippingEditOriginAddressFragment"
android:name="com.woocommerce.android.ui.orders.wooshippinglabels.address.origin.WooShippingEditOriginAddressFragment"
android:label="WooShippingEditOriginAddressFragment" >
<argument
android:name="originAddress"
app:argType="com.woocommerce.android.ui.orders.wooshippinglabels.models.OriginShippingAddress" />
</fragment>
</navigation>

0 comments on commit d167642

Please sign in to comment.