From f2c6fadde7e76b2a88d5d85b14a57df9fe07573c Mon Sep 17 00:00:00 2001 From: Bella Koch <160939932+amk-stripe@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:00:46 -0800 Subject: [PATCH] Replace PaymentOptionEditState type with a boolean (#9846) --- .../paymentsheet/ui/PaymentOptionEditState.kt | 6 ------ .../paymentsheet/ui/SavedPaymentMethodTab.kt | 19 ++++++++----------- .../ui/SavedPaymentMethodTabLayoutUI.kt | 11 ++++------- .../ui/PaymentOptionScreenshotTest.kt | 10 +++++----- .../paymentsheet/ui/PaymentOptionTest.kt | 2 +- 5 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PaymentOptionEditState.kt diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PaymentOptionEditState.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PaymentOptionEditState.kt deleted file mode 100644 index 07ce3854e21..00000000000 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/PaymentOptionEditState.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.stripe.android.paymentsheet.ui - -internal enum class PaymentOptionEditState { - None, - Modifiable -} diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTab.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTab.kt index 9145bdabada..1310b95fff9 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTab.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTab.kt @@ -61,7 +61,7 @@ internal val SavedPaymentMethodsTopContentPadding = 12.dp internal fun SavedPaymentMethodTab( viewWidth: Dp, isSelected: Boolean, - editState: PaymentOptionEditState, + shouldShowModifyBadge: Boolean, isEnabled: Boolean, isClickable: Boolean = isEnabled, iconRes: Int, @@ -78,7 +78,7 @@ internal fun SavedPaymentMethodTab( badge = { SavedPaymentMethodBadge( isSelected = isSelected, - editState = editState, + shouldShowModifyBadge = shouldShowModifyBadge, onModifyListener = onModifyListener, onModifyAccessibilityDescription = onModifyAccessibilityDescription ) @@ -117,20 +117,17 @@ internal fun SavedPaymentMethodTab( @Composable private fun SavedPaymentMethodBadge( isSelected: Boolean, - editState: PaymentOptionEditState, + shouldShowModifyBadge: Boolean, onModifyListener: (() -> Unit)? = null, onModifyAccessibilityDescription: String = "" ) { - when (editState) { - PaymentOptionEditState.Modifiable -> ModifyBadge( + if (shouldShowModifyBadge) { + ModifyBadge( onModifyAccessibilityDescription = onModifyAccessibilityDescription, onPressed = { onModifyListener?.invoke() }, modifier = Modifier.offset(x = (-14).dp, y = 1.dp), ) - PaymentOptionEditState.None -> Unit - } - - if (isSelected) { + } else if (isSelected) { SelectedBadge( modifier = Modifier.offset(x = (-18).dp, y = 58.dp), ) @@ -219,7 +216,7 @@ private fun SavedPaymentMethodTabUISelected() { SavedPaymentMethodTab( viewWidth = 100.dp, isSelected = true, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "MasterCard", @@ -236,7 +233,7 @@ private fun SavedPaymentMethodTabUIModifiable() { SavedPaymentMethodTab( viewWidth = 100.dp, isSelected = false, - editState = PaymentOptionEditState.Modifiable, + shouldShowModifyBadge = true, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "MasterCard", diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTabLayoutUI.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTabLayoutUI.kt index feb1f60dc2a..8752f1a2f13 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTabLayoutUI.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/SavedPaymentMethodTabLayoutUI.kt @@ -290,7 +290,7 @@ private fun AddCardTab( SavedPaymentMethodTab( viewWidth = width, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isSelected = false, labelText = stringResource(R.string.stripe_paymentsheet_add_payment_method_button_label), isEnabled = isEnabled, @@ -311,7 +311,7 @@ private fun GooglePayTab( ) { SavedPaymentMethodTab( viewWidth = width, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isSelected = isSelected, isEnabled = isEnabled, iconRes = R.drawable.stripe_google_pay_mark, @@ -332,7 +332,7 @@ private fun LinkTab( ) { SavedPaymentMethodTab( viewWidth = width, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isSelected = isSelected, isEnabled = isEnabled, iconRes = R.drawable.stripe_ic_paymentsheet_link, @@ -371,10 +371,7 @@ private fun SavedPaymentMethodTab( ) { SavedPaymentMethodTab( viewWidth = width, - editState = when { - isEnabled && isEditing -> PaymentOptionEditState.Modifiable - else -> PaymentOptionEditState.None - }, + shouldShowModifyBadge = isEnabled && isEditing, isSelected = isSelected, isEnabled = isEnabled, isClickable = !isEditing, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionScreenshotTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionScreenshotTest.kt index adfe3d91ad2..d8e7ef1766b 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionScreenshotTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionScreenshotTest.kt @@ -25,7 +25,7 @@ class PaymentOptionScreenshotTest { SavedPaymentMethodTab( viewWidth = 160.dp, isSelected = false, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "••••4242", @@ -41,7 +41,7 @@ class PaymentOptionScreenshotTest { SavedPaymentMethodTab( viewWidth = 160.dp, isSelected = false, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = false, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "••••4242", @@ -57,7 +57,7 @@ class PaymentOptionScreenshotTest { SavedPaymentMethodTab( viewWidth = 160.dp, isSelected = true, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "••••4242", @@ -73,7 +73,7 @@ class PaymentOptionScreenshotTest { SavedPaymentMethodTab( viewWidth = 160.dp, isSelected = true, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = false, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "••••4242", @@ -89,7 +89,7 @@ class PaymentOptionScreenshotTest { SavedPaymentMethodTab( viewWidth = 160.dp, isSelected = false, - editState = PaymentOptionEditState.Modifiable, + shouldShowModifyBadge = true, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = "••••4242", diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionTest.kt index d3d6600ab3d..62edd606c47 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/ui/PaymentOptionTest.kt @@ -28,7 +28,7 @@ class PaymentOptionTest { SavedPaymentMethodTab( viewWidth = 100.dp, isSelected = false, - editState = PaymentOptionEditState.None, + shouldShowModifyBadge = false, isEnabled = true, iconRes = R.drawable.stripe_ic_paymentsheet_card_visa, labelText = label,