From eed6a59792d4c4470a2c40286cf25d6bac6ecb35 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Thu, 28 Nov 2024 13:12:32 +0700 Subject: [PATCH 1/7] Update logic to show "One time shipping" on detail card depending on whether it is currently supported. --- .../android/ui/products/details/ProductDetailCardBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index 783eb50732c..f4836190478 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -483,7 +483,7 @@ class ProductDetailCardBuilder( ), Pair( resources.getString(string.subscription_one_time_shipping), - if (subscription?.oneTimeShipping == true) { + if (subscription?.supportsOneTimeShipping == true) { resources.getString(string.subscription_one_time_shipping_enabled) } else { "" From 46c4ae7e3d04903f5d0220b57a9ff5221199e633 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Thu, 28 Nov 2024 13:33:03 +0700 Subject: [PATCH 2/7] Improve one time shipping description logic to deal with its toggle state as well. --- .../details/ProductDetailCardBuilder.kt | 23 +++++++++++++++---- WooCommerce/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index f4836190478..74a107a4d61 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -483,11 +483,7 @@ class ProductDetailCardBuilder( ), Pair( resources.getString(string.subscription_one_time_shipping), - if (subscription?.supportsOneTimeShipping == true) { - resources.getString(string.subscription_one_time_shipping_enabled) - } else { - "" - } + buildOneTimeShippingDescription(subscription) ) ) @@ -533,6 +529,23 @@ class ProductDetailCardBuilder( } } + // Builds "One time shipping" description label. This label is affected by: + // - Free trial state: + // Checked with `supportsOneTimeShipping`. If free trial is set, one time shipping is automatically disabled. + // In this case we show nothing. + // - One time shipping toggle state: + // This is checked with `.oneTimeShipping`. If one time shipping is allowed, it can still be toggled on/off. + // In this case we either show "One time shipping: Enabled" or "One time shipping: Disabled" + private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?): String { + if (subscription == null) return "" + + return when { + !subscription.supportsOneTimeShipping -> "" + subscription.oneTimeShipping -> resources.getString(string.subscription_one_time_shipping_enabled) + else -> resources.getString(string.subscription_one_time_shipping_disabled) + } + } + // enable editing external product link private fun Product.externalLink(): ProductProperty? { return if (this.productType == EXTERNAL) { diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index c951fb10530..b03849231b9 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -3718,6 +3718,7 @@ Free trial One time shipping Enabled + Disabled Enable this to only charge shipping once on the initial order. Note: for this setting to be enabled the subscription must not have a free trial or a synced renewal date. From 6482d8efcf00d11305a4b752cba92fd5cdcf5148 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Thu, 28 Nov 2024 15:37:10 +0700 Subject: [PATCH 3/7] Update one time shipping label logic to match iOS behavior. --- .../details/ProductDetailCardBuilder.kt | 19 +++++++++---------- WooCommerce/src/main/res/values/strings.xml | 1 - 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index 74a107a4d61..6da5174cb53 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -530,22 +530,21 @@ class ProductDetailCardBuilder( } // Builds "One time shipping" description label. This label is affected by: - // - Free trial state: - // Checked with `supportsOneTimeShipping`. If free trial is set, one time shipping is automatically disabled. - // In this case we show nothing. - // - One time shipping toggle state: - // This is checked with `.oneTimeShipping`. If one time shipping is allowed, it can still be toggled on/off. - // In this case we either show "One time shipping: Enabled" or "One time shipping: Disabled" + // - Support state: Checked with `supportsOneTimeShipping`. One time shipping may not be supported, + // for example during free trials. + // - Toggle state: Checked with `oneTimeShipping`. When shipping is supported, it can be toggled on/off. + // + // We only show "Enabled" when shipping is both supported AND enabled. + // In all other cases (not supported, or supported but disabled), we show nothing. private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?): String { if (subscription == null) return "" return when { - !subscription.supportsOneTimeShipping -> "" - subscription.oneTimeShipping -> resources.getString(string.subscription_one_time_shipping_enabled) - else -> resources.getString(string.subscription_one_time_shipping_disabled) + subscription.supportsOneTimeShipping && subscription.oneTimeShipping -> + resources.getString(string.subscription_one_time_shipping_enabled) + else -> "" } } - // enable editing external product link private fun Product.externalLink(): ProductProperty? { return if (this.productType == EXTERNAL) { diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index b03849231b9..c951fb10530 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -3718,7 +3718,6 @@ Free trial One time shipping Enabled - Disabled Enable this to only charge shipping once on the initial order. Note: for this setting to be enabled the subscription must not have a free trial or a synced renewal date. From b7fcda44e5bb8655595e3b9dfd4b82954af253f2 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Thu, 28 Nov 2024 15:40:16 +0700 Subject: [PATCH 4/7] Update release notes. --- RELEASE-NOTES.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 5243f22653f..25532d56d1e 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -3,6 +3,7 @@ *** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too. 21.3 ----- +- [*] "One time shipping" label in Product Subscriptions now matches its availability state correctly. [https://github.com/woocommerce/woocommerce-android/pull/13021] ----- 21.2 From 20a5af9507deba26c5e6580aa93d3e22116ffbbd Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Thu, 28 Nov 2024 15:48:56 +0700 Subject: [PATCH 5/7] detekt fix --- .../android/ui/products/details/ProductDetailCardBuilder.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index 6da5174cb53..7645357de04 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -545,6 +545,7 @@ class ProductDetailCardBuilder( else -> "" } } + // enable editing external product link private fun Product.externalLink(): ProductProperty? { return if (this.productType == EXTERNAL) { From 05bca4cd51a97588f1ae2a42d5f7eb5d2cf9ea42 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Fri, 29 Nov 2024 10:32:19 +0700 Subject: [PATCH 6/7] Simplify logic for building description label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Irfan Ömür --- .../ui/products/details/ProductDetailCardBuilder.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index 7645357de04..11dd5dce61c 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -536,15 +536,12 @@ class ProductDetailCardBuilder( // // We only show "Enabled" when shipping is both supported AND enabled. // In all other cases (not supported, or supported but disabled), we show nothing. - private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?): String { - if (subscription == null) return "" - - return when { - subscription.supportsOneTimeShipping && subscription.oneTimeShipping -> - resources.getString(string.subscription_one_time_shipping_enabled) - else -> "" +private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?) = + if (subscription != null && subscription.supportsOneTimeShipping && subscription.oneTimeShipping) { + resources.getString(string.subscription_one_time_shipping_enabled) + } else { + "" } - } // enable editing external product link private fun Product.externalLink(): ProductProperty? { From f109bb97208fcf1eb8f4636215a1f259323f6d96 Mon Sep 17 00:00:00 2001 From: Hafiz Rahman Date: Fri, 29 Nov 2024 12:17:49 +0700 Subject: [PATCH 7/7] detekt fix --- .../android/ui/products/details/ProductDetailCardBuilder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt index 11dd5dce61c..2f00df7c080 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/details/ProductDetailCardBuilder.kt @@ -536,7 +536,7 @@ class ProductDetailCardBuilder( // // We only show "Enabled" when shipping is both supported AND enabled. // In all other cases (not supported, or supported but disabled), we show nothing. -private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?) = + private fun buildOneTimeShippingDescription(subscription: SubscriptionDetails?) = if (subscription != null && subscription.supportsOneTimeShipping && subscription.oneTimeShipping) { resources.getString(string.subscription_one_time_shipping_enabled) } else {