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

Unified Diff: ios/showcase/payments/sc_payments_selector_coordinator.mm

Issue 2805273002: [Payment Request] Selector view controller (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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..68416223baf8d3e4559e446d84de0a420660a95e
--- /dev/null
+++ b/ios/showcase/payments/sc_payments_selector_coordinator.mm
@@ -0,0 +1,113 @@
+// 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/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/cells/collection_view_text_item.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 TestCollectionViewTextItem : CollectionViewTextItem
+
+- (instancetype)initWithType:(NSInteger)type text:(NSString*)text;
+
+@end
+
+@implementation TestCollectionViewTextItem
+
+- (instancetype)initWithType:(NSInteger)type text:(NSString*)text {
+ self = [super initWithType:type];
+ if (self) {
+ self.text = text;
+ }
+ return self;
+}
+
+@end
+
+@interface SCPaymentsSelectorCoordinator ()<
+ PaymentRequestSelectorViewControllerDataSource>
+
+@property(nonatomic, strong)
+ PaymentRequestSelectorViewController* selectorViewController;
+@property(nonatomic, strong) NSArray<CollectionViewItem*>* 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 {
+ _items = [self createItems];
+ _selectedItemIndex = NSUIntegerMax;
+
+ _alerter = [[ProtocolAlerter alloc] initWithProtocols:@[
+ @protocol(PaymentRequestSelectorViewControllerDelegate)
+ ]];
+ _alerter.baseViewController = _baseViewController;
+
+ _selectorViewController = [[PaymentRequestSelectorViewController alloc]
+ initWithStyle:CollectionViewControllerStyleAppBar];
+ [_selectorViewController setTitle:@"Select an item"];
+ [_selectorViewController setDataSource:self];
+ [_selectorViewController loadModel];
+ [_selectorViewController
+ setDelegate:reinterpret_cast<
+ id<PaymentRequestSelectorViewControllerDelegate>>(
+ _alerter)];
+ [self.baseViewController pushViewController:_selectorViewController
+ animated:YES];
+}
+
+#pragma mark - PaymentRequestSelectorViewControllerDataSource
+
+- (CollectionViewItem*)headerItem {
+ return [[TestCollectionViewTextItem alloc] initWithType:kItemTypeHeaderItem
+ text:@"Header item"];
+}
+
+- (NSArray<CollectionViewItem*>*)selectableItems {
+ return _items;
+}
+
+- (CollectionViewItem*)selectableItemAtIndex:(NSUInteger)index {
+ DCHECK(index < _items.count);
+ return [_items objectAtIndex:index];
+}
+
+- (NSString*)addButtonTitle {
+ return @"Add an item";
+}
+
+#pragma mark - Helper methods
+
+- (NSArray<CollectionViewItem*>*)createItems {
+ return @[
+ [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
+ text:@"First selectable item"],
+ [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
+ text:@"Second selectable item"],
+ [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
+ text:@"Third selectable item"],
+ [[TestCollectionViewTextItem alloc]
+ initWithType:kItemTypeSelectableItem
+ text:@"Fourth selectable item"]
+ ];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698