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

Side by Side 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, 5 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/ui/payments/payment_request_selector_view_controller .h" 5 #import "ios/chrome/browser/ui/payments/payment_request_selector_view_controller .h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 9 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
10 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 10 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 CollectionViewModel* model = self.collectionViewModel; 242 CollectionViewModel* model = self.collectionViewModel;
243 243
244 CollectionViewItem* item = [model itemAtIndexPath:indexPath]; 244 CollectionViewItem* item = [model itemAtIndexPath:indexPath];
245 245
246 if (self.editing) { 246 if (self.editing) {
247 DCHECK(item.type == ItemTypeSelectableItem); 247 DCHECK(item.type == ItemTypeSelectableItem);
248 // Notify the delegate of the selection. 248 // Notify the delegate of the selection.
249 NSUInteger index = 249 NSUInteger index =
250 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; 250 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
251 DCHECK(index < [[self.dataSource selectableItems] count]); 251 DCHECK_LT(index, [[self.dataSource selectableItems] count]);
252 if ([self.delegate 252 if ([self.delegate
253 respondsToSelector:@selector 253 respondsToSelector:@selector
254 (paymentRequestSelectorViewController:didSelectItemAtIndexForEditing 254 (paymentRequestSelectorViewController:didSelectItemAtIndexForEditing
255 :)]) { 255 :)]) {
256 [self.delegate paymentRequestSelectorViewController:self 256 [self.delegate paymentRequestSelectorViewController:self
257 didSelectItemAtIndexForEditing:index]; 257 didSelectItemAtIndexForEditing:index];
258 } 258 }
259 return; 259 return;
260 } 260 }
261 261
262 switch (item.type) { 262 switch (item.type) {
263 case ItemTypeSelectableItem: { 263 case ItemTypeSelectableItem: {
264 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem = 264 NSUInteger currentlySelectedItemIndex = self.dataSource.selectedItemIndex;
265 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item); 265 // Notify the delegate of the selection. Update the currently selected and
266 // Update the currently selected and the newly selected cells only if the 266 // the newly selected cells only if the selection can actually be made.
267 // newly selected cell corresponds to a complete item and can be selected. 267 NSUInteger index =
268 if (newSelectedItem.isComplete) { 268 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
269 DCHECK_LT(index, [[self.dataSource selectableItems] count]);
270 if ([self.delegate paymentRequestSelectorViewController:self
271 didSelectItemAtIndex:index]) {
269 // Update the currently selected cell, if any. 272 // Update the currently selected cell, if any.
270 if (self.dataSource.selectedItemIndex != NSUIntegerMax) { 273 if (currentlySelectedItemIndex != NSUIntegerMax) {
271 DCHECK(self.dataSource.selectedItemIndex < 274 DCHECK(currentlySelectedItemIndex <
272 [[self.dataSource selectableItems] count]); 275 [[self.dataSource selectableItems] count]);
273 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem = 276 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem =
274 [[self.dataSource selectableItems] 277 [[self.dataSource selectableItems]
275 objectAtIndex:self.dataSource.selectedItemIndex]; 278 objectAtIndex:currentlySelectedItemIndex];
276 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; 279 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
277 [self reconfigureCellsForItems:@[ oldSelectedItem ]]; 280 [self reconfigureCellsForItems:@[ oldSelectedItem ]];
278 } 281 }
279 // Update the newly selected cell. 282 // Update the newly selected cell.
283 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem =
284 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item);
280 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 285 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
281 [self reconfigureCellsForItems:@[ newSelectedItem ]]; 286 [self reconfigureCellsForItems:@[ newSelectedItem ]];
282 } 287 }
283 // Notify the delegate of the selection.
284 NSUInteger index =
285 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath];
286 DCHECK(index < [[self.dataSource selectableItems] count]);
287 [self.delegate paymentRequestSelectorViewController:self
288 didSelectItemAtIndex:index];
289 break; 288 break;
290 } 289 }
291 case ItemTypeAddItem: { 290 case ItemTypeAddItem: {
292 if ([self.delegate 291 if ([self.delegate
293 respondsToSelector:@selector 292 respondsToSelector:@selector
294 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) { 293 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) {
295 [self.delegate 294 [self.delegate
296 paymentRequestSelectorViewControllerDidSelectAddItem:self]; 295 paymentRequestSelectorViewControllerDidSelectAddItem:self];
297 } 296 }
298 break; 297 break;
(...skipping 24 matching lines...) Expand all
323 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 322 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
324 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 323 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
325 if (type == ItemTypeHeader) { 324 if (type == ItemTypeHeader) {
326 return YES; 325 return YES;
327 } else { 326 } else {
328 return NO; 327 return NO;
329 } 328 }
330 } 329 }
331 330
332 @end 331 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698