Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

* Fix lifecycle crashes (fixes #494, #487, #404, #403, #379, #356)

## 6.17.0

* Bump braintree_android module dependency versions to `4.50.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -38,6 +39,10 @@ public class DropInActivity extends AppCompatActivity {
@VisibleForTesting
AlertPresenter alertPresenter;

private String authorization;
private String sessionId;
private Bundle checkoutRequestBundle;

@Override
protected void onResume() {
super.onResume();
Expand Down Expand Up @@ -72,15 +77,26 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

if (savedInstanceState == null) {
checkoutRequestBundle = intent.getParcelableExtra(DropInClient.EXTRA_CHECKOUT_REQUEST_BUNDLE);
} else {
checkoutRequestBundle = savedInstanceState.getParcelable(DropInClient.EXTRA_CHECKOUT_REQUEST_BUNDLE);
}

dropInRequest = getDropInRequest(checkoutRequestBundle);

if (dropInInternalClient == null) {
String authorization = intent.getStringExtra(DropInClient.EXTRA_AUTHORIZATION);
String sessionId = intent.getStringExtra(DropInClient.EXTRA_SESSION_ID);
DropInRequest dropInRequest = getDropInRequest(intent);
if (savedInstanceState == null) {
authorization = intent.getStringExtra(DropInClient.EXTRA_AUTHORIZATION);
sessionId = intent.getStringExtra(DropInClient.EXTRA_SESSION_ID);
} else {
authorization = savedInstanceState.getString(DropInClient.EXTRA_AUTHORIZATION);
sessionId = savedInstanceState.getString(DropInClient.EXTRA_SESSION_ID);
}
dropInInternalClient = new DropInInternalClient(this, authorization, sessionId, dropInRequest);
}

alertPresenter = new AlertPresenter();
dropInRequest = getDropInRequest(getIntent());

dropInViewModel = new ViewModelProvider(this).get(DropInViewModel.class);
fragmentContainerView = findViewById(R.id.fragment_container_view);
Expand Down Expand Up @@ -119,10 +135,9 @@ void finishDropInWithError(Exception e) {
finish();
}

private DropInRequest getDropInRequest(Intent intent) {
Bundle bundle = intent.getParcelableExtra(DropInClient.EXTRA_CHECKOUT_REQUEST_BUNDLE);
bundle.setClassLoader(DropInRequest.class.getClassLoader());
return bundle.getParcelable(DropInClient.EXTRA_CHECKOUT_REQUEST);
private DropInRequest getDropInRequest(Bundle checkoutRequestBundle) {
checkoutRequestBundle.setClassLoader(DropInRequest.class.getClassLoader());
return checkoutRequestBundle.getParcelable(DropInClient.EXTRA_CHECKOUT_REQUEST);
}

@VisibleForTesting
Expand Down Expand Up @@ -448,6 +463,14 @@ private void startAddCardFlow(@Nullable String cardNumber) {
}
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString(DropInClient.EXTRA_AUTHORIZATION, authorization);
outState.putString(DropInClient.EXTRA_SESSION_ID, sessionId);
outState.putParcelable(DropInClient.EXTRA_CHECKOUT_REQUEST_BUNDLE, checkoutRequestBundle);
super.onSaveInstanceState(outState);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.SavedStateHandle;
import androidx.lifecycle.ViewModel;

import com.braintreepayments.cardform.utils.CardType;
Expand All @@ -12,14 +13,25 @@

public class DropInViewModel extends ViewModel {

private final MutableLiveData<BottomSheetState> bottomSheetState = new MutableLiveData<>(BottomSheetState.HIDDEN);
private final MutableLiveData<DropInState> dropInState = new MutableLiveData<>(DropInState.IDLE);
public DropInViewModel(SavedStateHandle savedStateHandle) {
bottomSheetState = savedStateHandle.getLiveData("bottomSheetState", BottomSheetState.HIDDEN);
dropInState = savedStateHandle.getLiveData("dropInState", DropInState.IDLE);

private final MutableLiveData<List<DropInPaymentMethod>> supportedPaymentMethods = new MutableLiveData<>();
private final MutableLiveData<List<PaymentMethodNonce>> vaultedPaymentMethods = new MutableLiveData<>();
private final MutableLiveData<List<CardType>> supportedCardTypes = new MutableLiveData<>();
private final MutableLiveData<Exception> cardTokenizationError = new MutableLiveData<>();
private final MutableLiveData<Exception> userCanceledError = new MutableLiveData<>();
supportedPaymentMethods = savedStateHandle.getLiveData("supportedPaymentMethods");
vaultedPaymentMethods = savedStateHandle.getLiveData("vaultedPaymentMethods");
supportedCardTypes = savedStateHandle.getLiveData("supportedCardTypes");
cardTokenizationError = savedStateHandle.getLiveData("cardTokenizationError");
userCanceledError = savedStateHandle.getLiveData("userCanceledError");
}

private final MutableLiveData<BottomSheetState> bottomSheetState;
private final MutableLiveData<DropInState> dropInState;

private final MutableLiveData<List<DropInPaymentMethod>> supportedPaymentMethods;
private final MutableLiveData<List<PaymentMethodNonce>> vaultedPaymentMethods;
private final MutableLiveData<List<CardType>> supportedCardTypes;
private final MutableLiveData<Exception> cardTokenizationError;
private final MutableLiveData<Exception> userCanceledError;

LiveData<BottomSheetState> getBottomSheetState() {
return bottomSheetState;
Expand Down