Skip to content

Commit

Permalink
Fix AddCardFragment NPE on Configuration Change (#430)
Browse files Browse the repository at this point in the history
* Fix issue that caused a NPE when accessing bundle arguments in AddCardFragment.

* Update bundle args to remove prefill card extra once it's applied.

* Update CHANGELOG.
  • Loading branch information
sshropshire committed Aug 18, 2023
1 parent 5831c63 commit 6234956
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Braintree Android Drop-In Release Notes

## unreleased

* Reset bundle arguments for AddCardFragment after prefill card text is applied to Card Form (fixes #429)

## 6.11.0

* Add California Privacy Laws notice of collection to credit card form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
public class AddCardFragment extends DropInFragment implements OnCardFormSubmitListener,
CardEditText.OnCardTypeChangedListener {

private static final String EXTRA_DROP_IN_REQUEST = "EXTRA_DROP_IN_REQUEST";
private static final String EXTRA_CARD_NUMBER = "EXTRA_CARD_NUMBER";

@VisibleForTesting
CardForm cardForm;

Expand All @@ -38,9 +41,9 @@ public class AddCardFragment extends DropInFragment implements OnCardFormSubmitL

static AddCardFragment from(DropInRequest dropInRequest, @Nullable String cardNumber) {
Bundle args = new Bundle();
args.putParcelable("EXTRA_DROP_IN_REQUEST", dropInRequest);
args.putParcelable(EXTRA_DROP_IN_REQUEST, dropInRequest);
if (cardNumber != null) {
args.putString("EXTRA_CARD_NUMBER", cardNumber);
args.putString(EXTRA_CARD_NUMBER, cardNumber);
}

AddCardFragment instance = new AddCardFragment();
Expand Down Expand Up @@ -119,9 +122,13 @@ public void onResume() {
cardForm.getCardEditText().setText(cardNumber);
CardType cardType = cardForm.getCardEditText().getCardType();
onCardTypeChanged(cardType);

// reset bundle args to prevent existing input from being overriden
// when the fragment is re-created (e.g. on configuration change)
Bundle newArgs = new Bundle();
newArgs.putString(EXTRA_DROP_IN_REQUEST, args.getString(EXTRA_DROP_IN_REQUEST));
setArguments(newArgs);
}
// prevent card number from overriding existing input
setArguments(null);
}
}

Expand Down

0 comments on commit 6234956

Please sign in to comment.