Skip to content

Commit

Permalink
Remove toggleSelected() in PaymentMethodsAdapter (#1462)
Browse files Browse the repository at this point in the history
This call is unnecessary - we handle updating the UI by
calling `setSelectedIndex()` and `notifyItemChanged()`
on the impacted items.

Also re-enable item animation now that this is fixed.
  • Loading branch information
mshafrir-stripe authored Aug 30, 2019
1 parent eca145b commit e86f50c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ internal class MaskedCardView @JvmOverloads constructor(
cardInformationTextView.text = createDisplayString()
}

/**
* Toggle the view from selected to unselected or vice-versa.
*/
fun toggleSelected() {
setSelected(!isSelected)
}

private fun initializeCheckMark() {
updateDrawable(R.drawable.ic_checkmark, checkMarkImageView, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -78,7 +79,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(mAdapter);
recyclerView.setItemAnimator(null);
recyclerView.setItemAnimator(new DefaultItemAnimator());

mCustomerSession = CustomerSession.getInstance();
mStartedFromPaymentSession = args.isPaymentSessionActive;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ internal class PaymentMethodsAdapter : RecyclerView.Adapter<PaymentMethodsAdapte
val currentPosition = holder.adapterPosition
if (currentPosition != selectedIndex) {
val prevSelectedIndex = selectedIndex
holder.toggleSelected()
setSelectedIndex(currentPosition)

notifyItemChanged(prevSelectedIndex)
Expand Down Expand Up @@ -132,10 +131,6 @@ internal class PaymentMethodsAdapter : RecyclerView.Adapter<PaymentMethodsAdapte
fun setSelected(selected: Boolean) {
cardView.isSelected = selected
}

fun toggleSelected() {
cardView.toggleSelected()
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,6 @@ public void setSelected_changesCheckMarkVisibility() {
assertEquals(View.VISIBLE, mSelectedImageView.getVisibility());
}

@Test
public void toggleSelected_switchesState() {
final PaymentMethod paymentMethod =
PaymentMethod.fromString(PaymentMethodTest.PM_CARD_JSON);
assertNotNull(paymentMethod);
mMaskedCardView.setPaymentMethod(paymentMethod);
assertFalse(mMaskedCardView.isSelected());

mMaskedCardView.toggleSelected();
assertTrue(mMaskedCardView.isSelected());
assertEquals(View.VISIBLE, mSelectedImageView.getVisibility());

mMaskedCardView.toggleSelected();
assertFalse(mMaskedCardView.isSelected());
assertEquals(View.INVISIBLE, mSelectedImageView.getVisibility());
}

@Test
public void whenSourceNotCard_doesNotCrash() {
final PaymentMethod paymentMethod = new PaymentMethod.Builder().build();
Expand Down

0 comments on commit e86f50c

Please sign in to comment.