From 5c1f6c468dc1d9f88b9c3e9f1b8b48b304a8c55c Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Jan 2024 15:57:25 +0100 Subject: [PATCH 1/5] Show locker icon in the totals bottom drawer when action is not enabled --- .../orders/creation/totals/OrderCreateEditTotalsFullView.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/totals/OrderCreateEditTotalsFullView.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/totals/OrderCreateEditTotalsFullView.kt index f18fa193d6b..c2b8fbed733 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/totals/OrderCreateEditTotalsFullView.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/totals/OrderCreateEditTotalsFullView.kt @@ -34,6 +34,7 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Lock import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -438,7 +439,7 @@ private fun TextWithIcon( ) ) { Icon( - imageVector = Icons.Default.Edit, + imageVector = if (isEnabled) Icons.Default.Edit else Icons.Default.Lock, contentDescription = null, tint = colorResource(id = R.color.color_primary), modifier = Modifier.size(20.dp) @@ -452,7 +453,7 @@ private fun TextWithIcon( color = if (isEnabled) { colorResource(id = R.color.color_primary) } else { - colorResource(id = R.color.color_on_surface_medium) + colorResource(id = R.color.color_on_surface) }, text = buildAnnotatedString { append(text) From 5b51703faa0ea36c4b23c6160d28ecfc32dfc0f5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Jan 2024 10:43:19 +0100 Subject: [PATCH 2/5] Disable custom amount buttons when locked --- .../android/ui/orders/creation/OrderCreateEditFormFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt index 443002ef609..6447df62058 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt @@ -1059,6 +1059,7 @@ class OrderCreateEditFormFragment : } customAmountsSection.apply { isLocked = false + isEachAddButtonEnabled = true } } @@ -1075,6 +1076,7 @@ class OrderCreateEditFormFragment : } customAmountsSection.apply { isLocked = true + isEachAddButtonEnabled = false } } } From 883c0c97613800c431f4ac38cfea18ca3b593df2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Jan 2024 12:44:36 +0100 Subject: [PATCH 3/5] Added lock icons to the "add info" buttons. Extracted the state change to the outer class --- ...reateEditFormAddInfoButtonsStatusHelper.kt | 54 ++++++++++ .../creation/OrderCreateEditFormFragment.kt | 101 +++++++++++++----- ...ion_additional_info_collection_section.xml | 82 ++++++++++++-- 3 files changed, 201 insertions(+), 36 deletions(-) create mode 100644 WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt new file mode 100644 index 00000000000..85cc62b99aa --- /dev/null +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt @@ -0,0 +1,54 @@ +package com.woocommerce.android.ui.orders.creation + +import androidx.core.view.isVisible +import com.woocommerce.android.databinding.FragmentOrderCreateEditFormBinding +import javax.inject.Inject + +class OrderCreateEditFormAddInfoButtonsStatusHelper @Inject constructor() { + fun changeAddInfoButtonsEnabledState( + binding: FragmentOrderCreateEditFormBinding, + addInfoButtonsStateTransition: AddInfoButtonsStateTransition, + ) { + binding.additionalInfoCollectionSection.apply { + when (addInfoButtonsStateTransition.isAddShippingButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addShippingButton.isEnabled = addInfoButtonsStateTransition.isAddShippingButtonState.enabled + addShippingButtonLockIcon.isVisible = + !addInfoButtonsStateTransition.isAddShippingButtonState.enabled + } + + AddInfoButtonsStateTransition.State.Keep -> {} + } + + when (addInfoButtonsStateTransition.isAddCouponButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addCouponButton.isEnabled = addInfoButtonsStateTransition.isAddCouponButtonState.enabled + addCouponButtonLockIcon.isVisible = !addInfoButtonsStateTransition.isAddCouponButtonState.enabled + } + + AddInfoButtonsStateTransition.State.Keep -> {} + } + + when (addInfoButtonsStateTransition.isAddGiftCardButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addGiftCardButton.isEnabled = addInfoButtonsStateTransition.isAddGiftCardButtonState.enabled + addGiftCardButtonLockIcon.isVisible = + !addInfoButtonsStateTransition.isAddGiftCardButtonState.enabled + } + + AddInfoButtonsStateTransition.State.Keep -> {} + } + } + } +} + +data class AddInfoButtonsStateTransition( + val isAddShippingButtonState: State = State.Keep, + val isAddCouponButtonState: State = State.Keep, + val isAddGiftCardButtonState: State = State.Keep +) { + sealed class State { + data class Change(val enabled: Boolean) : State() + object Keep : State() + } +} diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt index 6447df62058..19475f0dabb 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormFragment.kt @@ -105,6 +105,9 @@ class OrderCreateEditFormFragment : @Inject lateinit var uiMessageResolver: UIMessageResolver + @Inject + lateinit var uiHelper: OrderCreateEditFormAddInfoButtonsStatusHelper + private var createOrderMenuItem: MenuItem? = null private var progressDialog: CustomProgressDialog? = null private var orderUpdateFailureSnackBar: Snackbar? = null @@ -364,13 +367,22 @@ class OrderCreateEditFormFragment : new.isIdle.takeIfNotEqualTo(old?.isIdle) { idle -> updateProgressBarsVisibility(binding, !idle) if (new.isEditable) { - binding.additionalInfoCollectionSection.addCouponButton.isEnabled = - new.isCouponButtonEnabled && idle - binding.additionalInfoCollectionSection.addShippingButton.isEnabled = - new.isAddShippingButtonEnabled && idle + uiHelper.changeAddInfoButtonsEnabledState( + binding, + AddInfoButtonsStateTransition( + isAddShippingButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = new.isAddShippingButtonEnabled && idle + ), + isAddCouponButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = new.isCouponButtonEnabled && idle + ), + isAddGiftCardButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = new.isAddGiftCardButtonEnabled && idle + ) + ) + ) + binding.productsSection.isEachAddButtonEnabled = idle - binding.additionalInfoCollectionSection.addGiftCardButton.isEnabled = - new.isAddGiftCardButtonEnabled && idle } } new.showOrderUpdateSnackbar.takeIfNotEqualTo(old?.showOrderUpdateSnackbar) { show -> @@ -396,16 +408,37 @@ class OrderCreateEditFormFragment : } } new.isCouponButtonEnabled.takeIfNotEqualTo(old?.isCouponButtonEnabled) { - binding.additionalInfoCollectionSection.addCouponButton.isEnabled = it + uiHelper.changeAddInfoButtonsEnabledState( + binding, + AddInfoButtonsStateTransition( + isAddCouponButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = it + ) + ) + ) } new.isAddShippingButtonEnabled.takeIfNotEqualTo(old?.isAddShippingButtonEnabled) { - binding.additionalInfoCollectionSection.addShippingButton.isEnabled = it + uiHelper.changeAddInfoButtonsEnabledState( + binding, + AddInfoButtonsStateTransition( + isAddShippingButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = it + ) + ) + ) } new.isAddGiftCardButtonEnabled.takeIfNotEqualTo(old?.isAddGiftCardButtonEnabled) { - binding.additionalInfoCollectionSection.addGiftCardButton.isEnabled = it + uiHelper.changeAddInfoButtonsEnabledState( + binding, + AddInfoButtonsStateTransition( + isAddGiftCardButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = it + ) + ) + ) } new.shouldDisplayAddGiftCardButton.takeIfNotEqualTo(old?.shouldDisplayAddGiftCardButton) { - binding.additionalInfoCollectionSection.addGiftCardButton.isVisible = it + binding.additionalInfoCollectionSection.addGiftCardButtonGroup.isVisible = it } new.taxRateSelectorButtonState.takeIfNotEqualTo(old?.taxRateSelectorButtonState) { binding.taxRateSelectorSection.isVisible = it.isShown @@ -569,16 +602,16 @@ class OrderCreateEditFormFragment : val firstShipping = newOrderData.shippingLines.firstOrNull { it.methodId != null } if (firstShipping != null) { - additionalInfoCollectionSection.addShippingButton.hide() + additionalInfoCollectionSection.addShippingButtonGroup.hide() } else { - additionalInfoCollectionSection.addShippingButton.show() + additionalInfoCollectionSection.addShippingButtonGroup.show() } } private fun OrderCreationAdditionalInfoCollectionSectionBinding.bindGiftCardSubSection(newOrderData: Order) { when (viewModel.mode) { is Creation -> bindGiftCardForOrderCreation(newOrderData) - is Edit -> addGiftCardButton.isVisible = false + is Edit -> addGiftCardButtonGroup.isVisible = false } } @@ -587,10 +620,10 @@ class OrderCreateEditFormFragment : ) { if (FeatureFlag.ORDER_GIFT_CARD.isEnabled().not()) return if (newOrderData.selectedGiftCard.isNullOrEmpty()) { - addGiftCardButton.isVisible = viewModel.isGiftCardExtensionEnabled + addGiftCardButtonGroup.isVisible = viewModel.isGiftCardExtensionEnabled addGiftCardButton.setOnClickListener { viewModel.onAddGiftCardButtonClicked() } } else { - addGiftCardButton.isVisible = false + addGiftCardButtonGroup.isVisible = false } } @@ -1052,11 +1085,20 @@ class OrderCreateEditFormFragment : isLocked = false isEachAddButtonEnabled = true } - additionalInfoCollectionSection.apply { - addShippingButton.isEnabled = true - addCouponButton.isEnabled = state.isCouponButtonEnabled - addGiftCardButton.isEnabled = state.isAddGiftCardButtonEnabled - } + uiHelper.changeAddInfoButtonsEnabledState( + this, + AddInfoButtonsStateTransition( + isAddShippingButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = true + ), + isAddCouponButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = state.isCouponButtonEnabled + ), + isAddGiftCardButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = state.isAddGiftCardButtonEnabled + ) + ) + ) customAmountsSection.apply { isLocked = false isEachAddButtonEnabled = true @@ -1069,11 +1111,20 @@ class OrderCreateEditFormFragment : isLocked = true isEachAddButtonEnabled = false } - additionalInfoCollectionSection.apply { - addShippingButton.isEnabled = false - addCouponButton.isEnabled = false - addGiftCardButton.isEnabled = false - } + uiHelper.changeAddInfoButtonsEnabledState( + this, + AddInfoButtonsStateTransition( + isAddShippingButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = false + ), + isAddCouponButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = false + ), + isAddGiftCardButtonState = AddInfoButtonsStateTransition.State.Change( + enabled = false + ) + ) + ) customAmountsSection.apply { isLocked = true isEachAddButtonEnabled = false diff --git a/WooCommerce/src/main/res/layout/order_creation_additional_info_collection_section.xml b/WooCommerce/src/main/res/layout/order_creation_additional_info_collection_section.xml index 239c2dd9dce..e390f09a3df 100644 --- a/WooCommerce/src/main/res/layout/order_creation_additional_info_collection_section.xml +++ b/WooCommerce/src/main/res/layout/order_creation_additional_info_collection_section.xml @@ -1,25 +1,51 @@ - + android:layout_height="wrap_content"> + + + app:layout_constraintTop_toTopOf="parent" /> + + + + + app:layout_constraintEnd_toStartOf="@+id/add_coupon_button_lock_icon" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/add_shipping_button" /> + + + + - + app:layout_constraintEnd_toStartOf="@+id/add_gift_card_button_lock_icon" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/add_coupon_button" /> + + + From 6a3e1f3dd201ca394cf5b1f4b2295db273a7bf83 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Jan 2024 15:23:40 +0100 Subject: [PATCH 4/5] Change locker visibility only when the group is visible --- ...reateEditFormAddInfoButtonsStatusHelper.kt | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt index 85cc62b99aa..4fe7940e185 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/orders/creation/OrderCreateEditFormAddInfoButtonsStatusHelper.kt @@ -9,34 +9,40 @@ class OrderCreateEditFormAddInfoButtonsStatusHelper @Inject constructor() { binding: FragmentOrderCreateEditFormBinding, addInfoButtonsStateTransition: AddInfoButtonsStateTransition, ) { - binding.additionalInfoCollectionSection.apply { - when (addInfoButtonsStateTransition.isAddShippingButtonState) { - is AddInfoButtonsStateTransition.State.Change -> { - addShippingButton.isEnabled = addInfoButtonsStateTransition.isAddShippingButtonState.enabled - addShippingButtonLockIcon.isVisible = - !addInfoButtonsStateTransition.isAddShippingButtonState.enabled + binding.additionalInfoCollectionSection.run { + root.post { + when (val state = addInfoButtonsStateTransition.isAddShippingButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addShippingButton.isEnabled = state.enabled + if (addShippingButtonGroup.isVisible) { + addShippingButtonLockIcon.isVisible = !state.enabled + } + } + + AddInfoButtonsStateTransition.State.Keep -> {} } - AddInfoButtonsStateTransition.State.Keep -> {} - } + when (val state = addInfoButtonsStateTransition.isAddCouponButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addCouponButton.isEnabled = state.enabled + if (addCouponButtonGroup.isVisible) { + addCouponButtonLockIcon.isVisible = !state.enabled + } + } - when (addInfoButtonsStateTransition.isAddCouponButtonState) { - is AddInfoButtonsStateTransition.State.Change -> { - addCouponButton.isEnabled = addInfoButtonsStateTransition.isAddCouponButtonState.enabled - addCouponButtonLockIcon.isVisible = !addInfoButtonsStateTransition.isAddCouponButtonState.enabled + AddInfoButtonsStateTransition.State.Keep -> {} } - AddInfoButtonsStateTransition.State.Keep -> {} - } + when (val state = addInfoButtonsStateTransition.isAddGiftCardButtonState) { + is AddInfoButtonsStateTransition.State.Change -> { + addGiftCardButton.isEnabled = state.enabled + if (addGiftCardButtonGroup.isVisible) { + addGiftCardButtonLockIcon.isVisible = !state.enabled + } + } - when (addInfoButtonsStateTransition.isAddGiftCardButtonState) { - is AddInfoButtonsStateTransition.State.Change -> { - addGiftCardButton.isEnabled = addInfoButtonsStateTransition.isAddGiftCardButtonState.enabled - addGiftCardButtonLockIcon.isVisible = - !addInfoButtonsStateTransition.isAddGiftCardButtonState.enabled + AddInfoButtonsStateTransition.State.Keep -> {} } - - AddInfoButtonsStateTransition.State.Keep -> {} } } } From 60d2160aa6af5b627a608d13365492e117031002 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Jan 2024 15:36:19 +0100 Subject: [PATCH 5/5] Updated release notes --- RELEASE-NOTES.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 355c4f472c4..5e82e1017b7 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,4 +1,8 @@ *** PLEASE FOLLOW THIS FORMAT: [] [] +17.3 +----- +- [*] [Internal] Better displaying of the "locked" state of the buttons on the order creation screen. Fixed bug when it was possible to add "custom amount" even when the order is locked [https://github.com/woocommerce/woocommerce-android/pull/10562] + 17.2 ----- - [*] [Internal] Tracking of "country" and "currency" properties for entry and exit of the payments flows [https://github.com/woocommerce/woocommerce-android/pull/10528]