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

Unified Diff: ios/chrome/browser/payments/shipping_address_selection_view_controller.mm

Issue 2621453002: Selected shipping option in payment summary view + shipping option selection view (Closed)
Patch Set: Addressed comments by lpromero@ and jdonnelley@ Created 3 years, 11 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/payments/shipping_address_selection_view_controller.mm
diff --git a/ios/chrome/browser/payments/shipping_address_selection_view_controller.mm b/ios/chrome/browser/payments/shipping_address_selection_view_controller.mm
index 8e16f0329bcaaabfdc455bc8b579a29ba93ff203..e3f67166296b900ce69786990c22a2c0217e2b33 100644
--- a/ios/chrome/browser/payments/shipping_address_selection_view_controller.mm
+++ b/ios/chrome/browser/payments/shipping_address_selection_view_controller.mm
@@ -140,24 +140,29 @@ typedef NS_ENUM(NSInteger, ItemType) {
CollectionViewModel* model = self.collectionViewModel;
- NSInteger itemType =
- [self.collectionViewModel itemTypeForIndexPath:indexPath];
- CollectionViewItem* item =
- [self.collectionViewModel itemAtIndexPath:indexPath];
-
+ NSInteger itemType = [model itemTypeForIndexPath:indexPath];
if (itemType == ItemTypeShippingAddress) {
- NSInteger index = [model indexInItemTypeForIndexPath:indexPath];
- DCHECK(index < (NSInteger)_shippingAddresses.size());
- self.selectedShippingAddress = _shippingAddresses[index];
-
- ShippingAddressItem* shippingAddressItem =
- base::mac::ObjCCastStrict<ShippingAddressItem>(item);
- shippingAddressItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
- _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
- [self reconfigureCellsForItems:@[ _selectedItem, shippingAddressItem ]
- inSectionWithIdentifier:SectionIdentifierShippingAddress];
- _selectedItem = shippingAddressItem;
-
+ NSIndexPath* currentlySelectedIndexPath = [self.collectionViewModel
+ indexPathForItem:_selectedItem
+ inSectionWithIdentifier:SectionIdentifierShippingAddress];
+ if (currentlySelectedIndexPath != indexPath) {
+ // Update the cells.
+ CollectionViewItem* item = [model itemAtIndexPath:indexPath];
+ ShippingAddressItem* newlySelectedItem =
+ base::mac::ObjCCastStrict<ShippingAddressItem>(item);
+ newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
+
+ _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
+
+ [self reconfigureCellsForItems:@[ _selectedItem, newlySelectedItem ]
+ inSectionWithIdentifier:SectionIdentifierShippingAddress];
+
+ // Update the selected shipping address and its respective item.
+ NSInteger index = [model indexInItemTypeForIndexPath:indexPath];
+ DCHECK(index < (NSInteger)_shippingAddresses.size());
+ self.selectedShippingAddress = _shippingAddresses[index];
+ _selectedItem = newlySelectedItem;
+ }
[_delegate
shippingAddressSelectionViewController:self
selectedShippingAddress:self.selectedShippingAddress];

Powered by Google App Engine
This is Rietveld 408576698