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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/showcase/payments/sc_payments_selector_coordinator.h"
6
7 #include "base/logging.h"
8 #import "ios/chrome/browser/payments/payment_request_selector_view_controller.h"
9 #import "ios/chrome/browser/payments/payment_request_selector_view_controller_da ta_source.h"
10 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
11 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
12 #import "ios/showcase/common/protocol_alerter.h"
13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
18 @interface TestCollectionViewTextItem : CollectionViewTextItem
19
20 - (instancetype)initWithType:(NSInteger)type text:(NSString*)text;
21
22 @end
23
24 @implementation TestCollectionViewTextItem
25
26 - (instancetype)initWithType:(NSInteger)type text:(NSString*)text {
27 self = [super initWithType:type];
28 if (self) {
29 self.text = text;
30 }
31 return self;
32 }
33
34 @end
35
36 @interface SCPaymentsSelectorCoordinator ()<
37 PaymentRequestSelectorViewControllerDataSource>
38
39 @property(nonatomic, strong)
40 PaymentRequestSelectorViewController* selectorViewController;
41 @property(nonatomic, strong) NSArray<CollectionViewItem*>* items;
42 @property(nonatomic, strong) ProtocolAlerter* alerter;
43
44 @end
45
46 @implementation SCPaymentsSelectorCoordinator
47
48 @synthesize state = _state;
49 @synthesize selectedItemIndex = _selectedItemIndex;
50 @synthesize baseViewController = _baseViewController;
51 @synthesize selectorViewController = _selectorViewController;
52 @synthesize items = _items;
53 @synthesize alerter = _alerter;
54
55 - (void)start {
56 _items = [self createItems];
57 _selectedItemIndex = NSUIntegerMax;
58
59 _alerter = [[ProtocolAlerter alloc] initWithProtocols:@[
60 @protocol(PaymentRequestSelectorViewControllerDelegate)
61 ]];
62 _alerter.baseViewController = _baseViewController;
63
64 _selectorViewController = [[PaymentRequestSelectorViewController alloc]
65 initWithStyle:CollectionViewControllerStyleAppBar];
66 [_selectorViewController setTitle:@"Select an item"];
67 [_selectorViewController setDataSource:self];
68 [_selectorViewController loadModel];
69 [_selectorViewController
70 setDelegate:reinterpret_cast<
71 id<PaymentRequestSelectorViewControllerDelegate>>(
72 _alerter)];
73 [self.baseViewController pushViewController:_selectorViewController
74 animated:YES];
75 }
76
77 #pragma mark - PaymentRequestSelectorViewControllerDataSource
78
79 - (CollectionViewItem*)headerItem {
80 return [[TestCollectionViewTextItem alloc] initWithType:kItemTypeHeaderItem
81 text:@"Header item"];
82 }
83
84 - (NSArray<CollectionViewItem*>*)selectableItems {
85 return _items;
86 }
87
88 - (CollectionViewItem*)selectableItemAtIndex:(NSUInteger)index {
89 DCHECK(index < _items.count);
90 return [_items objectAtIndex:index];
91 }
92
93 - (NSString*)addButtonTitle {
94 return @"Add an item";
95 }
96
97 #pragma mark - Helper methods
98
99 - (NSArray<CollectionViewItem*>*)createItems {
100 return @[
101 [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
102 text:@"First selectable item"],
103 [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
104 text:@"Second selectable item"],
105 [[TestCollectionViewTextItem alloc] initWithType:kItemTypeSelectableItem
106 text:@"Third selectable item"],
107 [[TestCollectionViewTextItem alloc]
108 initWithType:kItemTypeSelectableItem
109 text:@"Fourth selectable item"]
110 ];
111 }
112
113 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698