Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update Card Form UI and Dependencies #125

Draft
wants to merge 11 commits into
base: v6
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions CardForm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.8.9'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.3.1'
testImplementation 'org.robolectric:robolectric:4.7.3'
testImplementation 'androidx.test:core:1.5.0'
}

// region signing and publishing
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public AccessibleSupportedCardTypesView(Context context, AttributeSet attrs, int
*/
public void setSupportedCardTypes(@Nullable CardType... cardTypes) {
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(getContext(), FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.CENTER);
layoutManager.setJustifyContent(JustifyContent.FLEX_START);
layoutManager.setMaxLine(1);
setLayoutManager(layoutManager);

if (cardTypes == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import com.braintreepayments.cardform.utils.CardType;
import com.braintreepayments.cardform.utils.ViewUtils;
import com.braintreepayments.cardform.view.CardEditText.OnCardTypeChangedListener;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textview.MaterialTextView;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

Expand All @@ -56,6 +59,22 @@ public class CardForm extends LinearLayout implements OnCardTypeChangedListener,
* Shows the field, and require the field value to be non empty when validating the card form.
*/
public static final int FIELD_REQUIRED = 2;
private CardType[] mSupportedCardTypes;

public CardForm supportedCardTypesVisible(boolean supportedCardTypesVisible) {
if (supportedCardTypesVisible) {
mSupportedCardTypesView.setVisibility(View.VISIBLE);
} else {
mSupportedCardTypesView.setVisibility(View.GONE);
}
return this;
}

public CardForm setSupportedCardTypes(@Nullable CardType[] cardTypes) {
mSupportedCardTypes = cardTypes;
mSupportedCardTypesView.setSupportedCardTypes(cardTypes);
return this;
}

/**
* The statuses a field can be.
Expand All @@ -80,6 +99,8 @@ public class CardForm extends LinearLayout implements OnCardTypeChangedListener,
private TextView mMobileNumberExplanation;
private InitialValueCheckBox mSaveCardCheckBox;

private AccessibleSupportedCardTypesView mSupportedCardTypesView;

private boolean mCardNumberRequired;
private boolean mExpirationRequired;
private boolean mCvvRequired;
Expand Down Expand Up @@ -112,27 +133,25 @@ public CardForm(Context context, AttributeSet attrs, int defStyleAttr) {
init();
}

@TargetApi(VERSION_CODES.LOLLIPOP)
public CardForm(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}

private void init() {
setVisibility(GONE);
setOrientation(VERTICAL);

inflate(getContext(), R.layout.bt_card_form_fields, this);

mCardNumberIcon = findViewById(R.id.bt_card_form_card_number_icon);
mSupportedCardTypesView = findViewById(R.id.supported_card_types);

// mCardNumberIcon = findViewById(R.id.bt_card_form_text_input);
// TextInputLayout cardText = findViewById(R.id.bt_card_form_text_input);
// cardText.setStartIconDrawable(R.drawable.bt_ic_mobile_number);
mCardNumber = findViewById(R.id.bt_card_form_card_number);
mExpiration = findViewById(R.id.bt_card_form_expiration);
mCvv = findViewById(R.id.bt_card_form_cvv);
mCardholderName = findViewById(R.id.bt_card_form_cardholder_name);
mCardholderNameIcon = findViewById(R.id.bt_card_form_cardholder_name_icon);
mPostalCodeIcon = findViewById(R.id.bt_card_form_postal_code_icon);
// mCardholderNameIcon = findViewById(R.id.bt_card_form_cardholder_name_icon);
// mPostalCodeIcon = findViewById(R.id.bt_card_form_postal_code_icon);
mPostalCode = findViewById(R.id.bt_card_form_postal_code);
mMobileNumberIcon = findViewById(R.id.bt_card_form_mobile_number_icon);
// mMobileNumberIcon = findViewById(R.id.bt_card_form_mobile_number_icon);
mCountryCode = findViewById(R.id.bt_card_form_country_code);
mMobileNumber = findViewById(R.id.bt_card_form_mobile_number);
mMobileNumberExplanation = findViewById(R.id.bt_card_form_mobile_number_explanation);
Expand Down Expand Up @@ -284,21 +303,11 @@ public void setup(FragmentActivity activity) {
WindowManager.LayoutParams.FLAG_SECURE);

boolean cardHolderNameVisible = mCardholderNameStatus != FIELD_DISABLED;
boolean isDarkBackground = ViewUtils.isDarkBackground(activity);
mCardholderNameIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_cardholder_name_dark: R.drawable.bt_ic_cardholder_name);
mCardNumberIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_card_dark : R.drawable.bt_ic_card);
mPostalCodeIcon.setImageResource(isDarkBackground ? R.drawable.bt_ic_postal_code_dark : R.drawable.bt_ic_postal_code);
mMobileNumberIcon.setImageResource(isDarkBackground? R.drawable.bt_ic_mobile_number_dark : R.drawable.bt_ic_mobile_number);

setViewVisibility(mCardholderNameIcon, cardHolderNameVisible);
setFieldVisibility(mCardholderName, cardHolderNameVisible);
setViewVisibility(mCardNumberIcon, mCardNumberRequired);
setFieldVisibility(mCardNumber, mCardNumberRequired);
setFieldVisibility(mExpiration, mExpirationRequired);
setFieldVisibility(mCvv, mCvvRequired);
setViewVisibility(mPostalCodeIcon, mPostalCodeRequired);
setFieldVisibility(mPostalCode, mPostalCodeRequired);
setViewVisibility(mMobileNumberIcon, mMobileNumberRequired);
setFieldVisibility(mCountryCode, mMobileNumberRequired);
setFieldVisibility(mMobileNumber, mMobileNumberRequired);
setViewVisibility(mMobileNumberExplanation, mMobileNumberRequired);
Expand Down Expand Up @@ -716,6 +725,14 @@ public void onCardTypeChanged(CardType cardType) {
if (mOnCardTypeChangedListener != null) {
mOnCardTypeChangedListener.onCardTypeChanged(cardType);
}

if (mSupportedCardTypesView.getVisibility() == View.VISIBLE) {
if (cardType == CardType.EMPTY) {
mSupportedCardTypesView.setSupportedCardTypes(mSupportedCardTypes);
} else {
mSupportedCardTypesView.setSelected(cardType);
}
}
}

@Override
Expand Down

This file was deleted.

Loading