Chromium Code Reviews| 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 8678e55b7445a6b974e9f2c3a1bf04962df495c7..ddfbd86f7b0a0111c15ea1c9a278f60e530be63f 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 |
| @@ -68,6 +68,38 @@ typedef NS_ENUM(NSInteger, ItemType) { |
| return self; |
| } |
| +// Returns a custom edit bar button item. |
| +- (UIBarButtonItem*)editButton { |
| + UIBarButtonItem* button = [[UIBarButtonItem alloc] |
| + initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON) |
| + style:UIBarButtonItemStyleDone |
| + target:self |
| + action:@selector(editButtonPressed)]; |
| + return button; |
| +} |
| + |
| +// Returns a custom done bar button item. |
| +- (UIBarButtonItem*)doneButton { |
| + return [[UIBarButtonItem alloc] |
| + initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) |
| + style:UIBarButtonItemStyleDone |
| + target:self |
| + action:@selector(editButtonPressed)]; |
| +} |
| + |
| +- (void)editButtonPressed { |
| + PaymentRequestSelectorState newState = |
| + self.dataSource.state == PaymentRequestSelectorStateEdit |
| + ? PaymentRequestSelectorStateNormal |
| + : PaymentRequestSelectorStateEdit; |
| + if ([self.delegate |
| + respondsToSelector:@selector |
| + (paymentRequestSelectorViewController:didChangeToState:)]) { |
| + [self.delegate paymentRequestSelectorViewController:self |
| + didChangeToState:newState]; |
| + } |
| +} |
| + |
| #pragma mark - PaymentRequestSelectorViewControllerActions |
| - (void)onBack { |
| @@ -80,6 +112,14 @@ typedef NS_ENUM(NSInteger, ItemType) { |
| [super loadModel]; |
| CollectionViewModel* model = self.collectionViewModel; |
| + // Set up trailing (edit or done) button. |
| + if ([self.dataSource allowsEditMode]) { |
|
lpromero
2017/06/14 09:10:12
If !allowsEditMode, should you clear any present b
Moe
2017/06/14 14:35:05
allowsEditMode shouldn't change during the lifetim
|
| + self.navigationItem.rightBarButtonItem = |
| + self.dataSource.state == PaymentRequestSelectorStateEdit |
| + ? [self doneButton] |
| + : [self editButton]; |
| + } |
| + |
| [model addSectionWithIdentifier:SectionIdentifierItems]; |
| // If the view controller is in the pending state, only display a spinner and |
| @@ -92,10 +132,12 @@ typedef NS_ENUM(NSInteger, ItemType) { |
| return; |
| } |
| - CollectionViewItem* headerItem = [self.dataSource headerItem]; |
| - if (headerItem) { |
| - headerItem.type = ItemTypeHeader; |
| - [model addItem:headerItem toSectionWithIdentifier:SectionIdentifierItems]; |
| + if (self.dataSource.state != PaymentRequestSelectorStateEdit) { |
| + CollectionViewItem* headerItem = [self.dataSource headerItem]; |
| + if (headerItem) { |
| + headerItem.type = ItemTypeHeader; |
| + [model addItem:headerItem toSectionWithIdentifier:SectionIdentifierItems]; |
| + } |
| } |
| [[self.dataSource selectableItems] |
| @@ -105,18 +147,25 @@ typedef NS_ENUM(NSInteger, ItemType) { |
| DCHECK([item respondsToSelector:@selector(accessoryType)]); |
| item.type = ItemTypeSelectableItem; |
| item.accessibilityTraits |= UIAccessibilityTraitButton; |
| - item.accessoryType = (index == self.dataSource.selectedItemIndex) |
| - ? MDCCollectionViewCellAccessoryCheckmark |
| - : MDCCollectionViewCellAccessoryNone; |
| + if (self.dataSource.state == PaymentRequestSelectorStateEdit) { |
| + item.accessoryType = |
| + MDCCollectionViewCellAccessoryDisclosureIndicator; |
| + } else { |
| + item.accessoryType = (index == self.dataSource.selectedItemIndex) |
| + ? MDCCollectionViewCellAccessoryCheckmark |
| + : MDCCollectionViewCellAccessoryNone; |
| + } |
| [model addItem:item toSectionWithIdentifier:SectionIdentifierItems]; |
| }]; |
| - CollectionViewItem* addButtonItem = [self.dataSource addButtonItem]; |
| - if (addButtonItem) { |
| - addButtonItem.type = ItemTypeAddItem; |
| - addButtonItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| - [model addItem:addButtonItem |
| - toSectionWithIdentifier:SectionIdentifierItems]; |
| + if (self.dataSource.state != PaymentRequestSelectorStateEdit) { |
| + CollectionViewItem* addButtonItem = [self.dataSource addButtonItem]; |
| + if (addButtonItem) { |
| + addButtonItem.type = ItemTypeAddItem; |
| + addButtonItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| + [model addItem:addButtonItem |
| + toSectionWithIdentifier:SectionIdentifierItems]; |
| + } |
| } |
| } |
| @@ -189,6 +238,23 @@ typedef NS_ENUM(NSInteger, ItemType) { |
| CollectionViewModel* model = self.collectionViewModel; |
| CollectionViewItem* item = [model itemAtIndexPath:indexPath]; |
| + |
| + if (self.dataSource.state == PaymentRequestSelectorStateEdit) { |
| + DCHECK(item.type == ItemTypeSelectableItem); |
| + // Notify the delegate of the selection. |
| + NSUInteger index = |
| + [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; |
| + DCHECK(index < [[self.dataSource selectableItems] count]); |
| + if ([self.delegate |
| + respondsToSelector:@selector |
| + (paymentRequestSelectorViewController:didSelectItemAtIndexForEditing |
| + :)]) { |
|
lpromero
2017/06/14 09:10:13
No action needed: this line is awesome :p
Moe
2017/06/14 14:35:05
:)])
|
| + [self.delegate paymentRequestSelectorViewController:self |
| + didSelectItemAtIndexForEditing:index]; |
| + } |
| + return; |
| + } |
| + |
| switch (item.type) { |
| case ItemTypeSelectableItem: { |
| // Update the currently selected cell, if any. |