Chromium Code Reviews| Index: ios/showcase/payments/sc_payments_selector_coordinator.mm |
| diff --git a/ios/showcase/payments/sc_payments_selector_coordinator.mm b/ios/showcase/payments/sc_payments_selector_coordinator.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7d6bbc5be8e39b947d98422cdc960b5a23205676 |
| --- /dev/null |
| +++ b/ios/showcase/payments/sc_payments_selector_coordinator.mm |
| @@ -0,0 +1,112 @@ |
| +// 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_selector_coordinator.h" |
| + |
| +#include "base/logging.h" |
| +#import "ios/chrome/browser/payments//cells/payments_text_item.h" |
| +#import "ios/chrome/browser/payments/cells/payments_has_accessory_type.h" |
| +#import "ios/chrome/browser/payments/payment_request_selector_view_controller.h" |
| +#import "ios/chrome/browser/payments/payment_request_selector_view_controller_data_source.h" |
| +#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| +#import "ios/showcase/common/protocol_alerter.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +@interface TestPaymentsTextItem : PaymentsTextItem |
|
gambard
2017/04/18 14:12:31
If this is just to have an init method on Payments
Moe
2017/04/18 16:44:11
Done.
|
| + |
| +- (instancetype)initWithText:(NSString*)text; |
| + |
| +@end |
| + |
| +@implementation TestPaymentsTextItem |
| + |
| +- (instancetype)initWithText:(NSString*)text { |
| + self = [super init]; |
| + if (self) { |
| + self.text = text; |
| + } |
| + return self; |
| +} |
| + |
| +@end |
| + |
| +@interface SCPaymentsSelectorCoordinator ()< |
| + PaymentRequestSelectorViewControllerDataSource> |
| + |
| +@property(nonatomic, readwrite) NSUInteger selectedItemIndex; |
|
gambard
2017/04/18 14:12:30
Comment for all properties
Moe
2017/04/18 16:44:11
Done.
|
| + |
| +@property(nonatomic, strong) |
| + PaymentRequestSelectorViewController* selectorViewController; |
| +@property(nonatomic, strong) |
| + NSArray<CollectionViewItem<PaymentsHasAccessoryType>*>* items; |
| +@property(nonatomic, strong) ProtocolAlerter* alerter; |
| + |
| +@end |
| + |
| +@implementation SCPaymentsSelectorCoordinator |
| + |
| +@synthesize state = _state; |
| +@synthesize selectedItemIndex = _selectedItemIndex; |
| +@synthesize baseViewController = _baseViewController; |
| +@synthesize selectorViewController = _selectorViewController; |
| +@synthesize items = _items; |
| +@synthesize alerter = _alerter; |
| + |
| +- (void)start { |
| + self.items = [self createItems]; |
| + self.selectedItemIndex = NSUIntegerMax; |
| + |
| + self.alerter = [[ProtocolAlerter alloc] initWithProtocols:@[ |
| + @protocol(PaymentRequestSelectorViewControllerDelegate) |
| + ]]; |
| + self.alerter.baseViewController = self.baseViewController; |
| + |
| + self.selectorViewController = [[PaymentRequestSelectorViewController alloc] |
| + initWithStyle:CollectionViewControllerStyleAppBar]; |
| + [self.selectorViewController setTitle:@"Select an item"]; |
| + [self.selectorViewController setDataSource:self]; |
| + [self.selectorViewController loadModel]; |
| + [self.selectorViewController |
| + setDelegate:reinterpret_cast< |
| + id<PaymentRequestSelectorViewControllerDelegate>>( |
| + self.alerter)]; |
| + [self.baseViewController pushViewController:self.selectorViewController |
| + animated:YES]; |
| +} |
| + |
| +#pragma mark - PaymentRequestSelectorViewControllerDataSource |
| + |
| +- (CollectionViewItem*)headerItem { |
| + return [[TestPaymentsTextItem alloc] initWithText:@"Header item"]; |
| +} |
| + |
| +- (NSArray<CollectionViewItem<PaymentsHasAccessoryType>*>*)selectableItems { |
| + return self.items; |
| +} |
| + |
| +- (CollectionViewItem<PaymentsHasAccessoryType>*)selectableItemAtIndex: |
| + (NSUInteger)index { |
| + DCHECK(index < self.items.count); |
| + return [self.items objectAtIndex:index]; |
| +} |
| + |
| +- (CollectionViewItem*)addButtonItem { |
| + return [[TestPaymentsTextItem alloc] initWithText:@"Add an item"]; |
| +} |
| + |
| +#pragma mark - Helper methods |
| + |
| +- (NSArray<CollectionViewItem<PaymentsHasAccessoryType>*>*)createItems { |
| + return @[ |
| + [[TestPaymentsTextItem alloc] initWithText:@"First selectable item"], |
| + [[TestPaymentsTextItem alloc] initWithText:@"Second selectable item"], |
| + [[TestPaymentsTextItem alloc] initWithText:@"Third selectable item"], |
| + [[TestPaymentsTextItem alloc] initWithText:@"Fourth selectable item"] |
| + ]; |
| +} |
| + |
| +@end |