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

Side by Side 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: Initial 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller. h" 5 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller. h"
6 6
7 #import "base/ios/weak_nsobject.h" 7 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/foundation_util.h" 8 #include "base/mac/foundation_util.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 134
135 #pragma mark UICollectionViewDelegate 135 #pragma mark UICollectionViewDelegate
136 136
137 - (void)collectionView:(UICollectionView*)collectionView 137 - (void)collectionView:(UICollectionView*)collectionView
138 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 138 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
139 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 139 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
140 140
141 CollectionViewModel* model = self.collectionViewModel; 141 CollectionViewModel* model = self.collectionViewModel;
142 142
143 NSInteger itemType = 143 NSInteger itemType = [model itemTypeForIndexPath:indexPath];
144 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 144 if (itemType == ItemTypeShippingAddress) {
145 CollectionViewItem* item = 145 NSIndexPath* currentlySeletedIndexPath = [self.collectionViewModel
Justin Donnelly 2017/01/10 17:11:53 s/Seleted/Selected/
Moe 2017/01/12 00:06:18 Done.
146 [self.collectionViewModel itemAtIndexPath:indexPath]; 146 indexPathForItem:_selectedItem
147 inSectionWithIdentifier:SectionIdentifierShippingAddress];
148 if (currentlySeletedIndexPath != indexPath) {
149 // Update the cells.
150 CollectionViewItem* item = [model itemAtIndexPath:indexPath];
151 ShippingAddressItem* newlySelectedItem =
152 base::mac::ObjCCastStrict<ShippingAddressItem>(item);
153 newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
147 154
148 if (itemType == ItemTypeShippingAddress) { 155 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
149 NSInteger index = [model indexInItemTypeForIndexPath:indexPath];
150 DCHECK(index < (NSInteger)_shippingAddresses.size());
151 self.selectedShippingAddress = _shippingAddresses[index];
152 156
153 ShippingAddressItem* shippingAddressItem = 157 [self reconfigureCellsForItems:@[ _selectedItem, newlySelectedItem ]
154 base::mac::ObjCCastStrict<ShippingAddressItem>(item); 158 inSectionWithIdentifier:SectionIdentifierShippingAddress];
155 shippingAddressItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
156 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
157 [self reconfigureCellsForItems:@[ _selectedItem, shippingAddressItem ]
158 inSectionWithIdentifier:SectionIdentifierShippingAddress];
159 _selectedItem = shippingAddressItem;
160 159
160 // Update the selected shipping address and its respective item.
161 NSInteger index = [model indexInItemTypeForIndexPath:indexPath];
162 DCHECK(index < (NSInteger)_shippingAddresses.size());
163 self.selectedShippingAddress = _shippingAddresses[index];
164 _selectedItem = newlySelectedItem;
165 }
161 [_delegate 166 [_delegate
162 shippingAddressSelectionViewController:self 167 shippingAddressSelectionViewController:self
163 selectedShippingAddress:self.selectedShippingAddress]; 168 selectedShippingAddress:self.selectedShippingAddress];
164 } 169 }
165 // TODO(crbug.com/602666): Present a shipping address addition UI when 170 // TODO(crbug.com/602666): Present a shipping address addition UI when
166 // itemType == ItemTypeAddShippingAddress. 171 // itemType == ItemTypeAddShippingAddress.
167 } 172 }
168 173
169 #pragma mark MDCCollectionViewStylingDelegate 174 #pragma mark MDCCollectionViewStylingDelegate
170 175
171 - (CGFloat)collectionView:(UICollectionView*)collectionView 176 - (CGFloat)collectionView:(UICollectionView*)collectionView
172 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 177 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
173 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 178 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
174 if (type == ItemTypeAddShippingAddress) { 179 if (type == ItemTypeAddShippingAddress) {
175 return MDCCellDefaultOneLineHeight; 180 return MDCCellDefaultOneLineHeight;
176 } else { 181 } else {
177 CollectionViewItem* item = 182 CollectionViewItem* item =
178 [self.collectionViewModel itemAtIndexPath:indexPath]; 183 [self.collectionViewModel itemAtIndexPath:indexPath];
179 return [MDCCollectionViewCell 184 return [MDCCollectionViewCell
180 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 185 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
181 forItem:item]; 186 forItem:item];
182 } 187 }
183 } 188 }
184 189
185 @end 190 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698