Chromium Code Reviews| Index: ios/showcase/payments/sc_payments_editor_coordinator.mm |
| diff --git a/ios/showcase/payments/sc_payments_editor_coordinator.mm b/ios/showcase/payments/sc_payments_editor_coordinator.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1d2f7fd99e76e3e7da884d4da5967125325ff069 |
| --- /dev/null |
| +++ b/ios/showcase/payments/sc_payments_editor_coordinator.mm |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/showcase/payments/sc_payments_editor_coordinator.h" |
| + |
| +#import "base/mac/foundation_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#import "ios/chrome/browser/payments/cells/payments_text_item.h" |
| +#import "ios/chrome/browser/payments/payment_request_edit_view_controller.h" |
| +#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h" |
| +#import "ios/chrome/browser/ui/settings/cells/autofill_edit_item.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| + |
| +typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| + SectionIdentifierName = kSectionIdentifierEnumZero, |
| + SectionIdentifierAddress, |
|
lpromero
2017/03/16 13:01:07
How will you use PaymentRequestEditViewController
Moe
2017/03/16 15:44:23
Yes. please see my reply to your previous comment.
|
| + SectionIdentifierPostalCode, |
| +}; |
| + |
| +typedef NS_ENUM(NSInteger, ItemType) { |
| + ItemTypeName = kItemTypeEnumZero, |
| + ItemTypeAddress, |
| + ItemTypePostalCode, |
| +}; |
| + |
| +} // namespace |
| + |
| +@interface ConcreteEditViewController : PaymentRequestEditViewController |
| + |
| +- (instancetype)init; |
| + |
| +@end |
| + |
| +@implementation ConcreteEditViewController |
| + |
| +#pragma mark - Initialization |
| + |
| +- (instancetype)init { |
| + self = [super init]; |
| + if (self) { |
| + [self setTitle:@"Add info"]; |
| + } |
| + return self; |
| +} |
| + |
| +- (std::vector<EditorField>)editorFields { |
| + return std::vector<EditorField>{ |
| + {autofill::UNKNOWN_TYPE, base::UTF8ToUTF16("Name"), |
| + /* required= */ true, ItemTypeName, SectionIdentifierName}, |
| + {autofill::UNKNOWN_TYPE, base::UTF8ToUTF16("Address"), |
| + /* required= */ true, ItemTypeAddress, SectionIdentifierAddress}, |
| + {autofill::UNKNOWN_TYPE, base::UTF8ToUTF16("Postal Code"), |
| + /* required= */ false, ItemTypePostalCode, SectionIdentifierPostalCode}}; |
| +} |
| + |
| +#pragma mark MDCCollectionViewStylingDelegate |
| + |
| +- (CGFloat)collectionView:(UICollectionView*)collectionView |
| + cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
| + CollectionViewItem* item = |
| + [self.collectionViewModel itemAtIndexPath:indexPath]; |
| + switch (item.type) { |
| + case ItemTypeName: |
| + case ItemTypeAddress: |
| + case ItemTypePostalCode: |
| + return [MDCCollectionViewCell |
| + cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| + forItem:item]; |
| + default: |
| + return |
| + [super collectionView:collectionView cellHeightAtIndexPath:indexPath]; |
| + } |
| +} |
| + |
| +@end |
| + |
| +@implementation SCPaymentsEditorCoordinator |
| +@synthesize baseViewController = _baseViewController; |
| + |
| +- (void)start { |
| + ConcreteEditViewController* concreteEditViewController = |
| + [[ConcreteEditViewController alloc] init]; |
| + [concreteEditViewController loadModel]; |
| + [self.baseViewController pushViewController:concreteEditViewController |
| + animated:YES]; |
| +} |
| + |
| +@end |