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

Fix crash in ShippingMethodView on API 16 #678

Merged
merged 1 commit into from
Dec 21, 2018
Merged
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
1 change: 1 addition & 0 deletions stripe/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
<dimen name="shipping_widget_vertical_margin">4dp</dimen>
<dimen name="shipping_widget_horizontal_margin">16dp</dimen>
<dimen name="shipping_widget_outer_margin">12dp</dimen>
<dimen name="shipping_method_view_height">21dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class PaymentSessionData implements Parcelable {
public PaymentSessionData() { }

/**
* Get the selected payment method ID for the associated {@link PaymentSession}.
* @return
* @return the selected payment method ID for the associated {@link PaymentSession}
*/
@Nullable
public String getSelectedPaymentMethodId() {
Expand Down
2 changes: 1 addition & 1 deletion stripe/src/main/java/com/stripe/android/Stripe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class Stripe {

private SourceCreator mSourceCreator = new SourceCreator() {
private final SourceCreator mSourceCreator = new SourceCreator() {
@Override
public void create(
@NonNull final SourceParams sourceParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class ShippingMethodAdapter extends RecyclerView.Adapter<ShippingMethodAdapter.ViewHolder> {

@NonNull private List<ShippingMethod> mShippingMethods = new ArrayList<>();
@NonNull private int mSelectedIndex = 0;
private int mSelectedIndex = 0;

ShippingMethodAdapter() {}

Expand All @@ -30,14 +30,16 @@ public long getItemId(int position) {
return super.getItemId(position);
}

@NonNull
@Override
public ShippingMethodAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
public ShippingMethodAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup,
int i) {
ShippingMethodView shippingMethodView = new ShippingMethodView(viewGroup.getContext());
return new ViewHolder(shippingMethodView);
}

@Override
public void onBindViewHolder(ViewHolder holder, int i) {
public void onBindViewHolder(@NonNull ViewHolder holder, int i) {
holder.setShippingMethod(mShippingMethods.get(i));
holder.setIndex(i);
holder.setUIAsSelected(i == mSelectedIndex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.view;

import android.content.Context;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
Expand Down Expand Up @@ -71,10 +72,15 @@ private void initView() {
mUnselectedTextColorPrimaryInt = getThemeTextColorPrimary(getContext()).data;
mUnselectedTextColorSecondaryInt = getThemeTextColorSecondary(getContext()).data;
useDefaultColorsIfThemeColorsAreInvisible();
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams

final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(Gravity.CENTER_VERTICAL);
params.height = ViewUtils.getPxFromDp(getContext(), 72);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
params.addRule(Gravity.CENTER_VERTICAL);
}
final int height = getResources()
.getDimensionPixelSize(R.dimen.shipping_method_view_height);
params.height = ViewUtils.getPxFromDp(getContext(), height);
setLayoutParams(params);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.stripe.android.view;

import android.os.Build;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import androidx.test.core.app.ApplicationProvider;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = Build.VERSION_CODES.JELLY_BEAN)
public class ShippingMethodViewJellyBeanTest {

@Test
public void testConstructor() {
new ShippingMethodView(ApplicationProvider.getApplicationContext());
}
}