Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into issue/12281-creating…
Browse files Browse the repository at this point in the history
…-shipping-label-add-products-cards
  • Loading branch information
Alejo committed Oct 25, 2024
2 parents 930ffb7 + bfc9236 commit 6ba0df7
Show file tree
Hide file tree
Showing 33 changed files with 1,660 additions and 1,497 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*** PLEASE FOLLOW THIS FORMAT: [<priority indicator, more stars = higher priority>] <description> [<PR URL>]
*** Use [*****] to indicate smoke tests of all critical flows should be run on the final APK before release (e.g. major library or targetSdk updates).
*** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too.
21.0
-----


20.9
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ProductSelectorScreenTest {
selectedItemsCount = 0,
filterState = ProductSelectorViewModel.FilterState(emptyMap(), null),
searchState = ProductSelectorViewModel.SearchState.EMPTY,
selectionMode = ProductSelectorViewModel.SelectionMode.MULTIPLE
selectionMode = ProductSelectorViewModel.SelectionMode.MULTIPLE,
productFlow = ProductSelectorViewModel.ProductSelectorFlow.Undefined
),
onDoneButtonClick = {},
onClearButtonClick = {},
Expand Down Expand Up @@ -61,7 +62,8 @@ class ProductSelectorScreenTest {
selectedItemsCount = 0,
filterState = ProductSelectorViewModel.FilterState(emptyMap(), null),
searchState = ProductSelectorViewModel.SearchState.EMPTY,
selectionMode = ProductSelectorViewModel.SelectionMode.MULTIPLE
selectionMode = ProductSelectorViewModel.SelectionMode.MULTIPLE,
productFlow = ProductSelectorViewModel.ProductSelectorFlow.Undefined
),
onDoneButtonClick = {},
onClearButtonClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,17 @@ class MainActivity :
restart()
}

override fun showProductDetail(remoteProductId: Long, enableTrash: Boolean) {
val action = NavGraphMainDirections.actionGlobalProductDetailFragment(
mode = ProductDetailFragment.Mode.ShowProduct(remoteProductId),
isTrashEnabled = enableTrash
)
override fun showProductDetail(remoteProductId: Long, enableTrash: Boolean, popUpToProductList: Boolean) {
val action = when (popUpToProductList) {
true -> NavGraphMainDirections.actionGlobalProductDetailFragmentPopUpToProductList(
mode = ProductDetailFragment.Mode.ShowProduct(remoteProductId),
isTrashEnabled = enableTrash
)
else -> NavGraphMainDirections.actionGlobalProductDetailFragment(
mode = ProductDetailFragment.Mode.ShowProduct(remoteProductId),
isTrashEnabled = enableTrash
)
}
navController.navigateSafely(action)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface MainNavigationRouter {
fun isAtNavigationRoot(): Boolean
fun isChildFragmentShowing(): Boolean

fun showProductDetail(remoteProductId: Long, enableTrash: Boolean = false)
fun showProductDetail(remoteProductId: Long, enableTrash: Boolean = false, popUpToProductList: Boolean = false)
fun showProductDetailWithSharedTransition(
remoteProductId: Long,
sharedView: View,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.woocommerce.android.ui.orders.filters.model.OrderFilterEvent.OnShowOr
import com.woocommerce.android.ui.orders.filters.model.OrderFilterEvent.ShowFilterOptionsForCategory
import com.woocommerce.android.ui.orders.list.OrderListFragment
import com.woocommerce.android.ui.products.selector.ProductSelectorFragment
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.Undefined
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.OrderListFilter
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectedItem
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectionHandling.SIMPLE
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectionMode.SINGLE
Expand Down Expand Up @@ -176,7 +176,7 @@ class OrderFilterCategoriesFragment :
ctaButtonTextOverride = getString(R.string.done),
selectedItems = category.orderFilterOptions.firstOrNull { it.isSelected }
?.let { arrayOf(SelectedItem.Product(it.key.toLong())) },
productSelectorFlow = Undefined
productSelectorFlow = OrderListFilter
)
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,11 @@ class ProductDetailFragment :

private fun openProductDetails(productRemoteId: Long) {
hideProgressDialog()
(activity as? MainNavigationRouter)?.showProductDetail(productRemoteId, enableTrash = true)
(activity as? MainNavigationRouter)?.showProductDetail(
remoteProductId = productRemoteId,
enableTrash = true,
popUpToProductList = true
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.Lis
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.APPENDING
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.IDLE
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.LOADING
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.Undefined
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectionMode
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ViewState
import com.woocommerce.android.ui.products.selector.SelectionState.PARTIALLY_SELECTED
Expand Down Expand Up @@ -366,7 +367,7 @@ private fun ProductList(
modifier = Modifier.align(Alignment.CenterStart)
)
}
if (state.searchState.searchQuery.isEmpty()) {
if (state.shouldDisplayFilterButton) {
WCTextButton(
onClick = onFilterButtonClick,
text = StringUtils.getQuantityString(
Expand All @@ -375,7 +376,8 @@ private fun ProductList(
zero = string.product_selector_filter_button_title_zero
),
allCaps = false,
modifier = Modifier.align(Alignment.CenterEnd)
modifier = Modifier
.align(Alignment.CenterEnd)
)
}
}
Expand Down Expand Up @@ -599,7 +601,8 @@ fun PopularProductsListPreview() {
searchState = ProductSelectorViewModel.SearchState(),
popularProducts = products,
recentProducts = emptyList(),
selectionMode = SelectionMode.MULTIPLE
selectionMode = SelectionMode.MULTIPLE,
productFlow = Undefined
),
onDoneButtonClick = {},
onClearButtonClick = {},
Expand Down Expand Up @@ -669,7 +672,8 @@ fun RecentProductsListPreview() {
searchState = ProductSelectorViewModel.SearchState(),
popularProducts = emptyList(),
recentProducts = products,
selectionMode = SelectionMode.MULTIPLE
selectionMode = SelectionMode.MULTIPLE,
productFlow = Undefined
),
onDoneButtonClick = {},
onClearButtonClick = {},
Expand Down Expand Up @@ -747,7 +751,8 @@ fun ProductListPreview() {
searchState = ProductSelectorViewModel.SearchState(),
popularProducts = products,
recentProducts = products,
selectionMode = SelectionMode.MULTIPLE
selectionMode = SelectionMode.MULTIPLE,
productFlow = Undefined
),
onDoneButtonClick = {},
onClearButtonClick = {},
Expand All @@ -771,7 +776,8 @@ fun ProductListEmptyPreview() {
searchState = ProductSelectorViewModel.SearchState(),
popularProducts = emptyList(),
recentProducts = emptyList(),
selectionMode = SelectionMode.MULTIPLE
selectionMode = SelectionMode.MULTIPLE,
productFlow = Undefined
),
onClearFiltersButtonClick = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ProductSelectorTracker @Inject constructor(private val tracker: AnalyticsT
)
}
ProductSelectorFlow.CouponEdition -> {}
ProductSelectorFlow.OrderListFilter -> {}
ProductSelectorFlow.Undefined -> {}
}
}
Expand All @@ -34,6 +35,7 @@ class ProductSelectorTracker @Inject constructor(private val tracker: AnalyticsT
)
}
ProductSelectorFlow.CouponEdition -> {}
ProductSelectorFlow.OrderListFilter -> {}
ProductSelectorFlow.Undefined -> {}
}
}
Expand All @@ -46,6 +48,7 @@ class ProductSelectorTracker @Inject constructor(private val tracker: AnalyticsT
)
}
ProductSelectorFlow.CouponEdition -> {}
ProductSelectorFlow.OrderListFilter -> {}
ProductSelectorFlow.Undefined -> {}
}
}
Expand All @@ -68,6 +71,7 @@ class ProductSelectorTracker @Inject constructor(private val tracker: AnalyticsT
)
}
ProductSelectorFlow.CouponEdition -> {}
ProductSelectorFlow.OrderListFilter -> {}
ProductSelectorFlow.Undefined -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.woocommerce.android.ui.products.selector.ProductListHandler.SearchTyp
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.APPENDING
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.IDLE
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.LoadingState.LOADING
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.OrderListFilter
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectionHandling.NORMAL
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.SelectionHandling.SIMPLE
import com.woocommerce.android.ui.products.selector.SelectionState.PARTIALLY_SELECTED
Expand Down Expand Up @@ -144,21 +145,16 @@ class ProductSelectorViewModel @Inject constructor(
filterState = filterState,
searchState = searchState,
selectionMode = navArgs.selectionMode,
productFlow = navArgs.productSelectorFlow,
screenTitleOverride = navArgs.screenTitleOverride,
ctaButtonTextOverride = navArgs.ctaButtonTextOverride,
selectionEnabled = enabled,
)
}.asLiveData()

private fun mapProductsToUiModel(
it: Product,
selectedIds: List<SelectedItem>
) = when (navArgs.selectionHandling) {
NORMAL -> it.toUiModel(selectedIds)
SIMPLE -> it.toSimpleUiModel(selectedIds)
}

val selectionMode = navArgs.selectionMode
private val selectionHandling: SelectionHandling = navArgs.selectionHandling
val selectionMode: SelectionMode = navArgs.selectionMode
val shouldDisplayFilterButton: Boolean = navArgs.productSelectorFlow != OrderListFilter

init {
if (navArgs.selectionMode == SelectionMode.SINGLE && (navArgs.selectedItems?.size ?: 0) > 1) {
Expand All @@ -173,6 +169,14 @@ class ProductSelectorViewModel @Inject constructor(
}
}

private fun mapProductsToUiModel(
it: Product,
selectedIds: List<SelectedItem>
) = when (selectionHandling) {
NORMAL -> it.toUiModel(selectedIds)
SIMPLE -> it.toSimpleUiModel(selectedIds)
}

private fun getPopularProductsToDisplay(
popularProducts: List<Product>,
selectedIds: List<SelectedItem>
Expand Down Expand Up @@ -392,7 +396,7 @@ class ProductSelectorViewModel @Inject constructor(
isVariable() && numVariations > 0

if (item.hasVariations()) {
val variationSelectorScreenMode = when (navArgs.selectionMode) {
val variationSelectorScreenMode = when (selectionMode) {
SelectionMode.SINGLE, SelectionMode.MULTIPLE -> VariationSelectorViewModel.ScreenMode.FULLSCREEN
SelectionMode.LIVE -> VariationSelectorViewModel.ScreenMode.DIALOG
}
Expand All @@ -402,7 +406,7 @@ class ProductSelectorViewModel @Inject constructor(
selectedVariationIds = item.selectedVariationIds,
productSelectorFlow = productSelectorFlow,
productSourceForTracking = productSource,
selectionMode = navArgs.selectionMode,
selectionMode = selectionMode,
screenMode = variationSelectorScreenMode
)
)
Expand All @@ -419,7 +423,7 @@ class ProductSelectorViewModel @Inject constructor(
}

private fun handleConfigurableItemTap(item: ListItem.ConfigurableListItem) {
if (selectedItems.value.containsItemWith(item.id) && navArgs.selectionMode == SelectionMode.MULTIPLE) {
if (selectedItems.value.containsItemWith(item.id) && selectionMode == SelectionMode.MULTIPLE) {
tracker.trackItemUnselected(productSelectorFlow)
selectedItemsSource.remove(item.id)
_selectedItems.update { items -> items.filter { it.id != item.id } }
Expand All @@ -432,7 +436,7 @@ class ProductSelectorViewModel @Inject constructor(
}

private fun updateItemSelection(item: SelectedItem, productSource: ProductSourceForTracking) {
when (navArgs.selectionMode) {
when (selectionMode) {
SelectionMode.SINGLE -> {
tracker.trackItemSelected(productSelectorFlow)
selectedItemsSource[item.id] = productSource
Expand Down Expand Up @@ -627,7 +631,7 @@ class ProductSelectorViewModel @Inject constructor(
tracker.trackItemSelected(productSelectorFlow)
_selectedItems.update { items ->
val newItem = SelectedItem.ConfigurableProduct(productId, productConfiguration)
when (navArgs.selectionMode) {
when (selectionMode) {
SelectionMode.SINGLE -> listOf(newItem)
SelectionMode.MULTIPLE, SelectionMode.LIVE -> items + newItem
}
Expand Down Expand Up @@ -666,11 +670,13 @@ class ProductSelectorViewModel @Inject constructor(
val filterState: FilterState,
val searchState: SearchState,
val selectionMode: SelectionMode,
val productFlow: ProductSelectorFlow,
val screenTitleOverride: String? = null,
val ctaButtonTextOverride: String? = null,
val selectionEnabled: Boolean = true,
val selectionEnabled: Boolean = true
) {
val isDoneButtonEnabled: Boolean = selectionMode == SelectionMode.MULTIPLE || selectedItemsCount > 0
val shouldDisplayFilterButton = searchState.searchQuery.isEmpty() && productFlow != OrderListFilter
}

@Parcelize
Expand Down Expand Up @@ -787,7 +793,7 @@ class ProductSelectorViewModel @Inject constructor(
}

enum class ProductSelectorFlow {
OrderCreation, OrderEditing, CouponEdition, Undefined
OrderCreation, OrderEditing, CouponEdition, OrderListFilter, Undefined
}

enum class SelectionMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import com.woocommerce.android.ui.products.ProductStockStatus.Custom
import com.woocommerce.android.ui.products.ProductStockStatus.InStock
import com.woocommerce.android.ui.products.ProductStockStatus.NotAvailable
import com.woocommerce.android.ui.products.selector.ProductSelectorTracker
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.CouponEdition
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.OrderCreation
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.OrderEditing
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.OrderListFilter
import com.woocommerce.android.ui.products.selector.ProductSelectorViewModel.ProductSelectorFlow.Undefined
import com.woocommerce.android.ui.products.selector.ProductSourceForTracking
import com.woocommerce.android.ui.products.selector.SelectionState
import com.woocommerce.android.ui.products.selector.SelectionState.SELECTED
Expand Down Expand Up @@ -64,7 +69,7 @@ class VariationSelectorViewModel @Inject constructor(
}

private val navArgs: VariationSelectorFragmentArgs by savedState.navArgs()
private val productSelectorFlow = navArgs.productSelectorFlow
private val productSelectorFlow: ProductSelectorFlow = navArgs.productSelectorFlow

private val loadingState = MutableStateFlow(IDLE)
private val selectedVariationIds = savedState.getStateFlow(viewModelScope, navArgs.variationIds.toSet())
Expand Down Expand Up @@ -140,16 +145,17 @@ class VariationSelectorViewModel @Inject constructor(
}

private fun trackClearSelectionButtonClicked() {
when (navArgs.productSelectorFlow) {
ProductSelectorViewModel.ProductSelectorFlow.OrderCreation,
ProductSelectorViewModel.ProductSelectorFlow.OrderEditing -> {
when (productSelectorFlow) {
OrderCreation,
OrderEditing -> {
tracker.trackClearSelectionButtonClicked(
productSelectorFlow,
ProductSelectorTracker.ProductSelectorSource.VariationSelector
)
}
ProductSelectorViewModel.ProductSelectorFlow.CouponEdition -> {}
ProductSelectorViewModel.ProductSelectorFlow.Undefined -> {}
CouponEdition -> {}
OrderListFilter -> {}
Undefined -> {}
}
}

Expand All @@ -164,24 +170,26 @@ class VariationSelectorViewModel @Inject constructor(
}

private fun trackVariationSelected() {
when (navArgs.productSelectorFlow) {
ProductSelectorViewModel.ProductSelectorFlow.OrderCreation,
ProductSelectorViewModel.ProductSelectorFlow.OrderEditing -> {
when (productSelectorFlow) {
OrderCreation,
OrderEditing -> {
tracker.trackItemSelected(productSelectorFlow)
}
ProductSelectorViewModel.ProductSelectorFlow.CouponEdition -> {}
ProductSelectorViewModel.ProductSelectorFlow.Undefined -> {}
CouponEdition -> {}
OrderListFilter -> {}
Undefined -> {}
}
}

private fun trackVariationUnselected() {
when (navArgs.productSelectorFlow) {
ProductSelectorViewModel.ProductSelectorFlow.OrderCreation,
ProductSelectorViewModel.ProductSelectorFlow.OrderEditing -> {
when (productSelectorFlow) {
OrderCreation,
OrderEditing -> {
tracker.trackItemUnselected(productSelectorFlow)
}
ProductSelectorViewModel.ProductSelectorFlow.CouponEdition -> {}
ProductSelectorViewModel.ProductSelectorFlow.Undefined -> {}
CouponEdition -> {}
OrderListFilter -> {}
Undefined -> {}
}
}

Expand Down
Loading

0 comments on commit 6ba0df7

Please sign in to comment.