Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // Update the currently selected cell, if any. | |
| 265 if (self.dataSource.selectedItemIndex != NSUIntegerMax) { | |
| 266 DCHECK(self.dataSource.selectedItemIndex < | |
| 267 [[self.dataSource selectableItems] count]); | |
| 268 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem = | |
| 269 [[self.dataSource selectableItems] | |
| 270 objectAtIndex:self.dataSource.selectedItemIndex]; | |
| 271 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; | |
| 272 [self reconfigureCellsForItems:@[ oldSelectedItem ]]; | |
| 273 } | |
| 274 | |
| 275 // Update the newly selected cell. | |
| 276 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem = | 264 CollectionViewItem<PaymentsIsSelectable>* newSelectedItem = |
| 277 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item); | 265 reinterpret_cast<CollectionViewItem<PaymentsIsSelectable>*>(item); |
| 278 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 266 // Update the currently selected and the newly selected cells only if the |
| 279 [self reconfigureCellsForItems:@[ newSelectedItem ]]; | 267 // newly selected cell corresponds to a complete item and can be selected. |
| 280 | 268 if (newSelectedItem.isComplete) { |
| 269 // Update the currently selected cell, if any. | |
| 270 if (self.dataSource.selectedItemIndex != NSUIntegerMax) { | |
| 271 DCHECK(self.dataSource.selectedItemIndex < | |
| 272 [[self.dataSource selectableItems] count]); | |
| 273 CollectionViewItem<PaymentsIsSelectable>* oldSelectedItem = | |
| 274 [[self.dataSource selectableItems] | |
| 275 objectAtIndex:self.dataSource.selectedItemIndex]; | |
| 276 oldSelectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; | |
| 277 [self reconfigureCellsForItems:@[ oldSelectedItem ]]; | |
| 278 } | |
| 279 // Update the newly selected cell. | |
| 280 newSelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | |
| 281 [self reconfigureCellsForItems:@[ newSelectedItem ]]; | |
| 282 } | |
| 281 // Notify the delegate of the selection. | 283 // Notify the delegate of the selection. |
| 282 NSUInteger index = | 284 NSUInteger index = |
| 283 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; | 285 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; |
| 284 DCHECK(index < [[self.dataSource selectableItems] count]); | 286 DCHECK(index < [[self.dataSource selectableItems] count]); |
| 285 [self.delegate paymentRequestSelectorViewController:self | 287 [self.delegate paymentRequestSelectorViewController:self |
| 286 didSelectItemAtIndex:index]; | 288 didSelectItemAtIndex:index]; |
|
macourteau
2017/06/27 15:27:12
Do we still want to notify the delegate of selecti
Moe
2017/06/28 01:57:44
I see your point. I think this call is fine though
macourteau
2017/06/28 13:59:14
Ack. I still feel that the state is confusing: del
| |
| 287 break; | 289 break; |
| 288 } | 290 } |
| 289 case ItemTypeAddItem: { | 291 case ItemTypeAddItem: { |
| 290 if ([self.delegate | 292 if ([self.delegate |
| 291 respondsToSelector:@selector | 293 respondsToSelector:@selector |
| 292 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) { | 294 (paymentRequestSelectorViewControllerDidSelectAddItem:)]) { |
| 293 [self.delegate | 295 [self.delegate |
| 294 paymentRequestSelectorViewControllerDidSelectAddItem:self]; | 296 paymentRequestSelectorViewControllerDidSelectAddItem:self]; |
| 295 } | 297 } |
| 296 break; | 298 break; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 321 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 323 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 322 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 324 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 323 if (type == ItemTypeHeader) { | 325 if (type == ItemTypeHeader) { |
| 324 return YES; | 326 return YES; |
| 325 } else { | 327 } else { |
| 326 return NO; | 328 return NO; |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 | 331 |
| 330 @end | 332 @end |
| OLD | NEW |