Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm

Issue 2956323002: [Payment Request] Simplifies VC's logic to decide if an item is selectable (Closed)
Patch Set: Addressed comment Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm
diff --git a/ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm b/ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm
index 339f5b5f84a193cd0f69325f62b1cae1148896f9..0db52516f3883d544fd4f17b446ecaa3b11af71d 100644
--- a/ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm
+++ b/ios/chrome/browser/ui/payments/payment_request_selector_view_controller.mm
@@ -248,7 +248,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Notify the delegate of the selection.
NSUInteger index =
[self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
- DCHECK(index < [[self.dataSource selectableItems] count]);
+ DCHECK_LT(index, [[self.dataSource selectableItems] count]);
if ([self.delegate
respondsToSelector:@selector
(paymentRequestSelectorViewController:didSelectItemAtIndexForEditing
@@ -261,31 +261,30 @@ typedef NS_ENUM(NSInteger, ItemType) {
switch (item.type) {
case ItemTypeSelectableItem: {
- CollectionViewItem<PaymentsIsSelectable>* newSelectedItem =
- reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item);
- // Update the currently selected and the newly selected cells only if the
- // newly selected cell corresponds to a complete item and can be selected.
- if (newSelectedItem.isComplete) {
+ NSUInteger currentlySelectedItemIndex = self.dataSource.selectedItemIndex;
+ // Notify the delegate of the selection. Update the currently selected and
+ // the newly selected cells only if the selection can actually be made.
+ NSUInteger index =
+ [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
+ DCHECK_LT(index, [[self.dataSource selectableItems] count]);
+ if ([self.delegate paymentRequestSelectorViewController:self
+ didSelectItemAtIndex:index]) {
// Update the currently selected cell, if any.
- if (self.dataSource.selectedItemIndex != NSUIntegerMax) {
- DCHECK(self.dataSource.selectedItemIndex <
+ if (currentlySelectedItemIndex != NSUIntegerMax) {
+ DCHECK(currentlySelectedItemIndex <
[[self.dataSource selectableItems] count]);
CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem =
[[self.dataSource selectableItems]
- objectAtIndex:self.dataSource.selectedItemIndex];
+ objectAtIndex:currentlySelectedItemIndex];
oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
[self reconfigureCellsForItems:@[ oldSelectedItem ]];
}
// Update the newly selected cell.
+ CollectionViewItem<PaymentsIsSelectable>* newSelectedItem =
+ reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item);
newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
[self reconfigureCellsForItems:@[ newSelectedItem ]];
}
- // Notify the delegate of the selection.
- NSUInteger index =
- [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
- DCHECK(index < [[self.dataSource selectableItems] count]);
- [self.delegate paymentRequestSelectorViewController:self
- didSelectItemAtIndex:index];
break;
}
case ItemTypeAddItem: {

Powered by Google App Engine
This is Rietveld 408576698