From 36b7739758282a98bf9d36c9b12356a752072585 Mon Sep 17 00:00:00 2001 From: toluo-stripe Date: Wed, 20 Nov 2024 13:45:32 -0500 Subject: [PATCH] Minor fixes --- .../link/model/ConsumerPaymentDetailsKtx.kt | 4 +- .../android/link/ui/wallet/PaymentDetails.kt | 170 ++++++++++-------- .../PaymentDetailsListItemScreenShotTest.kt | 1 + .../stripe/android/view/ExpiryDateEditText.kt | 2 +- .../android/model/ConsumerPaymentDetails.kt | 2 +- .../stripe/android/core/utils/DateUtils.kt | 1 + 6 files changed, 102 insertions(+), 78 deletions(-) diff --git a/link/src/main/java/com/stripe/android/link/model/ConsumerPaymentDetailsKtx.kt b/link/src/main/java/com/stripe/android/link/model/ConsumerPaymentDetailsKtx.kt index c7316e3f3f6..7f6b3fc9ba1 100644 --- a/link/src/main/java/com/stripe/android/link/model/ConsumerPaymentDetailsKtx.kt +++ b/link/src/main/java/com/stripe/android/link/model/ConsumerPaymentDetailsKtx.kt @@ -14,6 +14,8 @@ internal val ConsumerPaymentDetails.PaymentDetails.removeLabel internal val ConsumerPaymentDetails.PaymentDetails.removeConfirmation get() = when (this) { - is ConsumerPaymentDetails.Passthrough, is ConsumerPaymentDetails.Card -> R.string.stripe_wallet_remove_card_confirmation + is ConsumerPaymentDetails.Passthrough, is ConsumerPaymentDetails.Card -> { + R.string.stripe_wallet_remove_card_confirmation + } is ConsumerPaymentDetails.BankAccount -> R.string.stripe_wallet_remove_account_confirmation } diff --git a/link/src/main/java/com/stripe/android/link/ui/wallet/PaymentDetails.kt b/link/src/main/java/com/stripe/android/link/ui/wallet/PaymentDetails.kt index 417b510d64a..0d13e4bf85d 100644 --- a/link/src/main/java/com/stripe/android/link/ui/wallet/PaymentDetails.kt +++ b/link/src/main/java/com/stripe/android/link/ui/wallet/PaymentDetails.kt @@ -51,95 +51,115 @@ internal fun PaymentDetailsListItem( onClick: () -> Unit, onMenuButtonClick: () -> Unit ) { - Row( - modifier = Modifier - .fillMaxWidth() - .defaultMinSize(minHeight = 56.dp) - .clickable(enabled = enabled, onClick = onClick), - verticalAlignment = Alignment.CenterVertically - ) { - RadioButton( - selected = isSelected, - onClick = null, - modifier = Modifier.padding(start = 20.dp, end = 6.dp), - colors = RadioButtonDefaults.colors( - selectedColor = MaterialTheme.linkColors.actionLabelLight, - unselectedColor = MaterialTheme.linkColors.disabledText - ) - ) - Column( + Column { + Row( modifier = Modifier - .padding(vertical = 8.dp) - .weight(1f) + .fillMaxWidth() + .defaultMinSize(minHeight = 56.dp) + .clickable(enabled = enabled, onClick = onClick), + verticalAlignment = Alignment.CenterVertically ) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically + RadioButton( + selected = isSelected, + onClick = null, + modifier = Modifier.padding(start = 20.dp, end = 6.dp), + colors = RadioButtonDefaults.colors( + selectedColor = MaterialTheme.linkColors.actionLabelLight, + unselectedColor = MaterialTheme.linkColors.disabledText + ) + ) + Column( + modifier = Modifier + .padding(vertical = 8.dp) + .weight(1f) ) { - PaymentDetails(paymentDetails = paymentDetails) + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + PaymentDetails(paymentDetails = paymentDetails) - if (paymentDetails.isDefault) { - Box( - modifier = Modifier - .background( - color = MaterialTheme.colors.secondary, - shape = MaterialTheme.linkShapes.extraSmall - ), - contentAlignment = Alignment.Center - ) { - Text( - text = stringResource(id = R.string.stripe_wallet_default), - modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp), - color = MaterialTheme.linkColors.disabledText, - fontSize = 12.sp, - fontWeight = FontWeight.Medium - ) + if (paymentDetails.isDefault) { + DefaultTag() } - } - val showWarning = (paymentDetails as? Card)?.isExpired ?: false - if (showWarning && !isSelected) { - Icon( - painter = painterResource(R.drawable.stripe_link_error), - contentDescription = null, - modifier = Modifier.size(20.dp), - tint = MaterialTheme.linkColors.errorText - ) + val showWarning = (paymentDetails as? Card)?.isExpired ?: false + if (showWarning && !isSelected) { + Icon( + painter = painterResource(R.drawable.stripe_link_error), + contentDescription = null, + modifier = Modifier.size(20.dp), + tint = MaterialTheme.linkColors.errorText + ) + } } } + + MenuAndLoader( + enabled = enabled, + isUpdating = isUpdating, + onMenuButtonClick = onMenuButtonClick + ) } + TabRowDefaults.Divider( + modifier = Modifier.padding(horizontal = 20.dp), + color = MaterialTheme.linkColors.componentDivider, + thickness = 1.dp + ) + } +} - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .size(MinimumTouchTargetSize) - .padding(end = 12.dp) - ) { - if (isUpdating) { - CircularProgressIndicator( - modifier = Modifier.size(24.dp), - strokeWidth = 2.dp +@Composable +private fun MenuAndLoader( + enabled: Boolean, + isUpdating: Boolean, + onMenuButtonClick: () -> Unit +) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .size(MinimumTouchTargetSize) + .padding(end = 12.dp) + ) { + if (isUpdating) { + CircularProgressIndicator( + modifier = Modifier.size(24.dp), + strokeWidth = 2.dp + ) + } else { + IconButton( + onClick = onMenuButtonClick, + enabled = enabled + ) { + Icon( + imageVector = Icons.Filled.MoreVert, + contentDescription = stringResource(StripeR.string.stripe_edit), + tint = MaterialTheme.linkColors.actionLabelLight, + modifier = Modifier.size(24.dp) ) - } else { - IconButton( - onClick = onMenuButtonClick, - enabled = enabled - ) { - Icon( - imageVector = Icons.Filled.MoreVert, - contentDescription = stringResource(StripeR.string.stripe_edit), - tint = MaterialTheme.linkColors.actionLabelLight, - modifier = Modifier.size(24.dp) - ) - } } } } - TabRowDefaults.Divider( - modifier = Modifier.padding(horizontal = 20.dp), - color = MaterialTheme.linkColors.componentDivider, - thickness = 1.dp - ) +} + +@Composable +private fun DefaultTag() { + Box( + modifier = Modifier + .background( + color = MaterialTheme.colors.secondary, + shape = MaterialTheme.linkShapes.extraSmall + ), + contentAlignment = Alignment.Center + ) { + Text( + text = stringResource(id = R.string.stripe_wallet_default), + modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp), + color = MaterialTheme.linkColors.disabledText, + fontSize = 12.sp, + fontWeight = FontWeight.Medium + ) + } } @Composable diff --git a/link/src/test/java/com/stripe/android/link/ui/wallet/PaymentDetailsListItemScreenShotTest.kt b/link/src/test/java/com/stripe/android/link/ui/wallet/PaymentDetailsListItemScreenShotTest.kt index 2381f7e477a..c5f17594607 100644 --- a/link/src/test/java/com/stripe/android/link/ui/wallet/PaymentDetailsListItemScreenShotTest.kt +++ b/link/src/test/java/com/stripe/android/link/ui/wallet/PaymentDetailsListItemScreenShotTest.kt @@ -46,6 +46,7 @@ internal class PaymentDetailsListItemScreenShotTest( companion object { @JvmStatic @Parameterized.Parameters(name = "{0}") + @SuppressWarnings("LongMethod") fun data(): List { return listOf( TestCase( diff --git a/payments-core/src/main/java/com/stripe/android/view/ExpiryDateEditText.kt b/payments-core/src/main/java/com/stripe/android/view/ExpiryDateEditText.kt index 72a84b49aca..91f3b28ead6 100644 --- a/payments-core/src/main/java/com/stripe/android/view/ExpiryDateEditText.kt +++ b/payments-core/src/main/java/com/stripe/android/view/ExpiryDateEditText.kt @@ -9,8 +9,8 @@ import android.view.View import android.widget.EditText import androidx.annotation.RestrictTo import androidx.annotation.VisibleForTesting -import com.stripe.android.core.utils.DateUtils import com.stripe.android.R +import com.stripe.android.core.utils.DateUtils import com.stripe.android.model.ExpirationDate import kotlin.math.min import kotlin.properties.Delegates diff --git a/payments-model/src/main/java/com/stripe/android/model/ConsumerPaymentDetails.kt b/payments-model/src/main/java/com/stripe/android/model/ConsumerPaymentDetails.kt index 9afe59739be..9cfc0823015 100644 --- a/payments-model/src/main/java/com/stripe/android/model/ConsumerPaymentDetails.kt +++ b/payments-model/src/main/java/com/stripe/android/model/ConsumerPaymentDetails.kt @@ -2,9 +2,9 @@ package com.stripe.android.model import android.os.Parcelable import androidx.annotation.RestrictTo -import com.stripe.android.core.utils.DateUtils import com.stripe.android.core.model.CountryCode import com.stripe.android.core.model.StripeModel +import com.stripe.android.core.utils.DateUtils import kotlinx.parcelize.Parcelize @Parcelize diff --git a/stripe-core/src/main/java/com/stripe/android/core/utils/DateUtils.kt b/stripe-core/src/main/java/com/stripe/android/core/utils/DateUtils.kt index e95c4d966e5..0651ac9ff00 100644 --- a/stripe-core/src/main/java/com/stripe/android/core/utils/DateUtils.kt +++ b/stripe-core/src/main/java/com/stripe/android/core/utils/DateUtils.kt @@ -5,6 +5,7 @@ import androidx.annotation.RestrictTo import androidx.annotation.VisibleForTesting import java.util.Calendar +@SuppressWarnings("MagicNumber") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) object DateUtils {