Skip to content

Commit

Permalink
Use non transitive R classes. (#6635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe authored May 2, 2023
1 parent 089df99 commit b5f9254
Show file tree
Hide file tree
Showing 118 changed files with 511 additions and 407 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## XX.XX.XX - 2023-XX-XX

### All SDKs
* [CHANGED][6635](https://github.com/stripe/stripe-android/pull/6635) Use non transitive R classes.

## 20.24.1 - 2023-05-01

### Payments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import com.stripe.android.R as StripeR

@RunWith(AndroidJUnit4::class)
@LargeTest
Expand All @@ -41,7 +42,7 @@ class AddFpxPaymentMethodTest {
launchBankSelector()

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
onView(withId(StripeR.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}
Expand All @@ -51,7 +52,7 @@ class AddFpxPaymentMethodTest {
launchBankSelector()

// confirm selection without selecting a bank
onView(withId(R.id.action_save)).perform(click())
onView(withId(StripeR.id.action_save)).perform(click())

// Nothing should happen as no bank was selected
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import com.stripe.android.R as StripeR

@RunWith(AndroidJUnit4::class)
@LargeTest
Expand Down Expand Up @@ -47,7 +48,7 @@ class AddNetbankingPaymentMethodTest {
launchBankSelector()

// click on first bank in the list
onView(withId(R.id.bank_list)).perform(
onView(withId(StripeR.id.bank_list)).perform(
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(0, click())
)
}
Expand All @@ -57,7 +58,7 @@ class AddNetbankingPaymentMethodTest {
launchBankSelector()

// confirm selection without selecting a bank
onView(withId(R.id.action_save)).perform(click())
onView(withId(StripeR.id.action_save)).perform(click())

// Nothing should happen as no bank was selected
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import com.stripe.android.R as StripeR

@RunWith(AndroidJUnit4::class)
@LargeTest
Expand Down Expand Up @@ -46,11 +47,11 @@ class CreateCardTokenActivityTest {
)

// fill out card details
onView(withId(R.id.card_number_edit_text))
onView(withId(StripeR.id.card_number_edit_text))
.perform(replaceText("4242424242424242"))
onView(withId(R.id.expiry_date_edit_text))
onView(withId(StripeR.id.expiry_date_edit_text))
.perform(replaceText("01/25"))
onView(withId(R.id.cvc_edit_text))
onView(withId(StripeR.id.cvc_edit_text))
.perform(replaceText("111"))

// click create card button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.stripe.android.model.PaymentMethod
import com.stripe.android.view.PaymentMethodsActivityStarter
import com.stripe.example.R
import com.stripe.example.databinding.CustomerSessionActivityBinding
import com.stripe.android.R as StripeR

/**
* An example activity that handles working with a [CustomerSession], allowing you to
Expand Down Expand Up @@ -81,7 +82,7 @@ class CustomerSessionActivity : AppCompatActivity() {
}

private fun buildCardString(data: PaymentMethod.Card): String {
return getString(R.string.stripe_card_ending_in, data.brand, data.last4)
return getString(StripeR.string.stripe_card_ending_in, data.brand, data.last4)
}

internal class ActivityViewModel : ViewModel() {
Expand Down
5 changes: 1 addition & 4 deletions financial-connections-example/detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>MaxLineLength:FinancialConnectionsPlaygroundViewModel.kt$FinancialConnectionsPlaygroundViewModel$status = current.status + "Payment Intent created ${it.intentSecret}, opening FinancialConnectionsSheet."</ID>
<ID>MaximumLineLength:com.stripe.android.financialconnections.example.FinancialConnectionsPlaygroundViewModel.kt:61</ID>
</CurrentIssues>
<CurrentIssues/>
</SmellBaseline>
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ POM_DEVELOPER_ID=stripe
POM_DEVELOPER_NAME=Stripe
POM_DEVELOPER_EMAIL=support+android@stripe.com

android.useAndroidX=true
android.enableJetifier=false
android.enableR8.fullMode=true
android.nonTransitiveRClass=true
android.useAndroidX=true

# Update StripeSdkVersion.VERSION_NAME when publishing a new release
VERSION_NAME=20.24.1
2 changes: 1 addition & 1 deletion identity-example/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ID>LongMethod:ComposeExampleUI.kt$@Composable private fun SubmitView( submissionState: IdentitySubmissionState, scaffoldState: ScaffoldState, configuration: IdentityVerificationSheet.Configuration, viewModel: IdentityExampleViewModel, )</ID>
<ID>LongMethod:ComposeExampleUI.kt$@Composable private fun TypeSelectUI( verificationType: VerificationType, integrationType: IntegrationType, onVerificationTypeChanged: (VerificationType) -> Unit )</ID>
<ID>MaxLineLength:ComposeExampleUI.kt$resultString = "Error generating verificationSessionId and ephemeralKeySecret: ${it.getException().message}"</ID>
<ID>MaximumLineLength:com.stripe.android.identity.example.ui.ComposeExampleUI.kt:631</ID>
<ID>MaximumLineLength:com.stripe.android.identity.example.ui.ComposeExampleUI.kt:632</ID>
<ID>TooGenericExceptionCaught:IdentityExampleViewModel.kt$IdentityExampleViewModel$t: Throwable</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import com.stripe.android.identity.example.ui.IntegrationType.LINK
import com.stripe.android.identity.example.ui.IntegrationType.NATIVE
import com.stripe.android.identity.example.ui.IntegrationType.WEB
import kotlinx.coroutines.launch
import com.stripe.android.identity.R as IdentityR

internal enum class VerificationType(val value: String) {
DOCUMENT("document"), ID_NUMBER("id_number"), ADDRESS("address"), PHONE("phone")
Expand Down Expand Up @@ -349,7 +350,7 @@ private fun AllowedDocumentTypes(
)

StyledClickableText(
text = AnnotatedString(stringResource(id = R.string.stripe_driver_license)),
text = AnnotatedString(stringResource(id = IdentityR.string.stripe_driver_license)),
onClick = {
onSubmissionStateChangedListener(
identitySubmissionState.copy(
Expand All @@ -372,7 +373,7 @@ private fun AllowedDocumentTypes(
)
})
StyledClickableText(
text = AnnotatedString(stringResource(id = R.string.stripe_passport)),
text = AnnotatedString(stringResource(id = IdentityR.string.stripe_passport)),
onClick = {
onSubmissionStateChangedListener(
identitySubmissionState.copy(
Expand All @@ -395,7 +396,7 @@ private fun AllowedDocumentTypes(
)
})
StyledClickableText(
text = AnnotatedString(stringResource(id = R.string.stripe_id_card)),
text = AnnotatedString(stringResource(id = IdentityR.string.stripe_id_card)),
onClick = {
onSubmissionStateChangedListener(
identitySubmissionState.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.stripe.android.core.model.Country
import com.stripe.android.identity.R
import com.stripe.android.identity.navigation.CountryNotListedDestination
import com.stripe.android.identity.navigation.navigateTo
import com.stripe.android.identity.networking.Resource
Expand All @@ -32,6 +31,7 @@ import com.stripe.android.uicore.elements.SectionElement
import com.stripe.android.uicore.elements.SectionElementUI
import com.stripe.android.uicore.elements.SectionFieldElement
import com.stripe.android.uicore.forms.FormFieldEntry
import com.stripe.android.uicore.R as UiCoreR

/**
* Section to collect User's Address.
Expand Down Expand Up @@ -69,7 +69,7 @@ internal fun AddressSection(
}
}
val sectionElement = remember(selectedCountryCode) {
SectionElement.wrap(sectionList, R.string.stripe_address_label_address)
SectionElement.wrap(sectionList, UiCoreR.string.stripe_address_label_address)
}
val formFieldValues by sectionElement.getFormFieldValueFlow()
.collectAsState(initial = emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.stripe.android.uicore.elements.SectionElementUI
import com.stripe.android.uicore.elements.SimpleTextElement
import com.stripe.android.uicore.elements.SimpleTextFieldConfig
import com.stripe.android.uicore.elements.SimpleTextFieldController
import com.stripe.android.core.R as CoreR

/**
* Section to collect User's date of birth.
Expand Down Expand Up @@ -45,7 +46,7 @@ internal fun NameSection(
controller = lastNameController
)
),
label = R.string.stripe_address_label_name
label = CoreR.string.stripe_address_label_name
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import com.stripe.android.identity.states.IdentityScanState
import com.stripe.android.identity.viewmodel.IdentityViewModel
import com.stripe.android.uicore.text.dimensionResourceSp
import kotlinx.coroutines.launch
import com.google.android.material.R as MaterialR

internal const val FRONT_ROW_TAG = "frontRow"
internal const val BACK_ROW_TAG = "backRow"
Expand Down Expand Up @@ -369,7 +370,7 @@ private fun DialogListItem(
.testTag(testTag)
.height(
dimensionResource(
com.google.android.material.R.dimen.abc_list_item_height_small_material
MaterialR.dimen.abc_list_item_height_small_material
)
)
.clickable { onSelected() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.stripe.android.identity

import android.app.Application
import com.google.android.material.R as MaterialR

// A material themed application is needed to inflate MaterialToolbar in IdentityActivity
internal class TestApplication : Application() {
override fun onCreate() {
super.onCreate()
setTheme(R.style.Theme_MaterialComponents_DayNight_NoActionBar)
setTheme(MaterialR.style.Theme_MaterialComponents_DayNight_NoActionBar)
}
}
6 changes: 3 additions & 3 deletions link/src/main/java/com/stripe/android/link/ui/ErrorMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import android.os.Parcelable
import androidx.annotation.RestrictTo
import androidx.annotation.StringRes
import com.stripe.android.core.exception.APIConnectionException
import com.stripe.android.link.R
import kotlinx.parcelize.Parcelize
import com.stripe.android.R as StripeR

internal fun Throwable.getErrorMessage() = when (this) {
is APIConnectionException ->
ErrorMessage.FromResources(R.string.stripe_failure_connection_error)
ErrorMessage.FromResources(StripeR.string.stripe_failure_connection_error)
else -> localizedMessage?.let {
ErrorMessage.Raw(it)
} ?: ErrorMessage.FromResources(R.string.stripe_internal_error)
} ?: ErrorMessage.FromResources(StripeR.string.stripe_internal_error)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion link/src/main/java/com/stripe/android/link/ui/LinkAppBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.stripe.android.link.model.AccountStatus
import com.stripe.android.link.theme.AppBarHeight
import com.stripe.android.link.theme.DefaultLinkTheme
import com.stripe.android.link.theme.linkColors
import com.stripe.android.ui.core.R as StripeUiCoreR

@Composable
internal fun LinkAppBar(
Expand All @@ -52,7 +53,7 @@ internal fun LinkAppBar(
) {
Icon(
painter = painterResource(state.navigationIcon),
contentDescription = stringResource(id = R.string.stripe_back),
contentDescription = stringResource(id = StripeUiCoreR.string.stripe_back),
tint = MaterialTheme.linkColors.closeButton
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.stripe.android.link.R
import com.stripe.android.link.theme.DefaultLinkTheme
import com.stripe.android.link.theme.linkColors
import com.stripe.android.uicore.StripeTheme
import com.stripe.android.R as StripeR

private val LinkButtonVerticalPadding = 6.dp
private val LinkButtonHorizontalPadding = 10.dp
Expand Down Expand Up @@ -99,7 +100,7 @@ fun LinkButton(
) {
Icon(
painter = painterResource(R.drawable.stripe_link_logo),
contentDescription = stringResource(R.string.stripe_link),
contentDescription = stringResource(StripeR.string.stripe_link),
modifier = Modifier
.height(22.dp)
.padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.compose.runtime.Composable
import com.stripe.android.link.R
import com.stripe.android.link.ui.menus.LinkMenu
import com.stripe.android.link.ui.menus.LinkMenuItem
import com.stripe.android.R as StripeR

internal sealed class LinkLogoutMenuItem(
override val textResId: Int,
override val isDestructive: Boolean = false
) : LinkMenuItem {
object Logout : LinkLogoutMenuItem(textResId = R.string.stripe_log_out, isDestructive = true)
object Cancel : LinkLogoutMenuItem(textResId = R.string.stripe_cancel)
object Cancel : LinkLogoutMenuItem(textResId = StripeR.string.stripe_cancel)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.SetupIntent
import com.stripe.android.model.StripeIntent
import com.stripe.android.ui.core.Amount
import com.stripe.android.ui.core.R as StripeUiCoreR

/**
* Represent the possible states for the primary button on a Link screen.
Expand Down Expand Up @@ -69,7 +70,7 @@ internal fun completePaymentButtonLabel(
requireNotNull(stripeIntent.amount),
requireNotNull(stripeIntent.currency)
).buildPayButtonLabel(resources)
is SetupIntent -> resources.getString(R.string.stripe_setup_button_label)
is SetupIntent -> resources.getString(StripeUiCoreR.string.stripe_setup_button_label)
}

@Composable
Expand All @@ -80,7 +81,7 @@ private fun PrimaryButton() {
label = "Testing",
state = PrimaryButtonState.Enabled,
onButtonClick = { },
iconEnd = R.drawable.stripe_ic_lock
iconEnd = StripeUiCoreR.drawable.stripe_ic_lock
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.stripe.android.link.ui.SecondaryButton
import com.stripe.android.link.ui.forms.Form
import com.stripe.android.link.ui.wallet.PaymentDetailsResult
import com.stripe.android.uicore.elements.CheckboxElementUI
import com.stripe.android.R as StripeR

internal const val DEFAULT_PAYMENT_METHOD_CHECKBOX_TAG = "DEFAULT_PAYMENT_METHOD_CHECKBOX"

Expand Down Expand Up @@ -164,7 +165,7 @@ internal fun CardEditBody(
)
SecondaryButton(
enabled = !isProcessing,
label = stringResource(id = R.string.stripe_cancel),
label = stringResource(id = StripeR.string.stripe_cancel),
onClick = onCancelClick
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Provider
import com.stripe.android.R as StripeR

/**
* ViewModel that controls the PaymentMethod screen, managing what payment method form to show and
Expand Down Expand Up @@ -73,7 +74,7 @@ internal class PaymentMethodViewModel @Inject constructor(
val secondaryButtonLabel = if (isRootScreen) {
R.string.stripe_wallet_pay_another_way
} else {
R.string.stripe_cancel
StripeR.string.stripe_cancel
}

val supportedTypes = args.stripeIntent.supportedPaymentMethodTypes(linkAccount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.stripe.android.model.ConsumerPaymentDetails
import com.stripe.android.model.StripeIntent
import com.stripe.android.ui.core.elements.FormItemSpec
import com.stripe.android.ui.core.forms.LinkCardForm
import com.stripe.android.ui.core.R as StripeUiCoreR

/**
* Represents the Payment Methods that are supported by Link.
Expand All @@ -33,9 +34,9 @@ internal enum class SupportedPaymentMethod(
Card(
ConsumerPaymentDetails.Card.type,
LinkCardForm.items,
R.string.stripe_paymentsheet_payment_method_card,
StripeUiCoreR.string.stripe_paymentsheet_payment_method_card,
R.drawable.stripe_link_card,
primaryButtonEndIconResourceId = R.drawable.stripe_ic_lock
primaryButtonEndIconResourceId = StripeUiCoreR.drawable.stripe_ic_lock
) {
override fun primaryButtonLabel(
stripeIntent: StripeIntent,
Expand All @@ -45,7 +46,7 @@ internal enum class SupportedPaymentMethod(
BankAccount(
ConsumerPaymentDetails.BankAccount.type,
emptyList(),
R.string.stripe_payment_method_bank,
StripeUiCoreR.string.stripe_payment_method_bank,
R.drawable.stripe_link_bank,
primaryButtonStartIconResourceId = R.drawable.stripe_link_add
) {
Expand Down
Loading

0 comments on commit b5f9254

Please sign in to comment.