OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/showcase/payments/sc_payments_editor_coordinator.h" | 5 #import "ios/showcase/payments/sc_payments_editor_coordinator.h" |
6 | 6 |
7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 9 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
10 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" | 10 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" |
11 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" | 11 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" |
12 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | 12 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" |
13 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h" | 13 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h" |
14 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" | 14 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
15 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 15 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
16 #import "ios/showcase/common/protocol_alerter.h" | |
16 | 17 |
17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
18 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
19 #endif | 20 #endif |
20 | 21 |
21 @interface SCPaymentsEditorCoordinator ()< | 22 @interface SCPaymentsEditorCoordinator ()< |
22 PaymentRequestEditViewControllerDataSource> { | 23 PaymentRequestEditViewControllerDataSource, |
23 PaymentRequestEditViewController* _paymentRequestEditViewController; | 24 PaymentRequestEditViewControllerValidator> |
24 } | 25 |
26 @property(nonatomic, strong) | |
27 PaymentRequestEditViewController* paymentRequestEditViewController; | |
28 | |
29 @property(nonatomic, strong) ProtocolAlerter* alerter; | |
30 | |
25 @end | 31 @end |
26 | 32 |
27 @implementation SCPaymentsEditorCoordinator | 33 @implementation SCPaymentsEditorCoordinator |
28 | 34 |
35 @synthesize state = _state; | |
29 @synthesize baseViewController = _baseViewController; | 36 @synthesize baseViewController = _baseViewController; |
37 @synthesize paymentRequestEditViewController = | |
38 _paymentRequestEditViewController; | |
39 @synthesize alerter = _alerter; | |
30 | 40 |
31 - (void)start { | 41 - (void)start { |
32 _paymentRequestEditViewController = [[PaymentRequestEditViewController alloc] | 42 self.alerter = [[ProtocolAlerter alloc] initWithProtocols:@[ |
33 initWithStyle:CollectionViewControllerStyleAppBar]; | 43 @protocol(PaymentRequestEditViewControllerDelegate) |
34 [_paymentRequestEditViewController setTitle:@"Add info"]; | 44 ]]; |
35 [_paymentRequestEditViewController setDataSource:self]; | 45 self.alerter.baseViewController = self.baseViewController; |
36 [_paymentRequestEditViewController loadModel]; | 46 |
37 [self.baseViewController pushViewController:_paymentRequestEditViewController | 47 self.paymentRequestEditViewController = |
38 animated:YES]; | 48 [[PaymentRequestEditViewController alloc] |
49 initWithStyle:CollectionViewControllerStyleAppBar]; | |
50 [self.paymentRequestEditViewController setTitle:@"Add info"]; | |
51 [self.paymentRequestEditViewController setDataSource:self]; | |
52 [self.paymentRequestEditViewController | |
53 setDelegate:reinterpret_cast< | |
edchin
2017/05/15 17:38:17
I think this should be a static_cast.
Moe
2017/05/15 18:36:42
Done.
| |
54 id<PaymentRequestEditViewControllerDelegate>>( | |
55 self.alerter)]; | |
56 [self.paymentRequestEditViewController setValidatorDelegate:self]; | |
57 [self.paymentRequestEditViewController loadModel]; | |
58 [self.baseViewController | |
59 pushViewController:self.paymentRequestEditViewController | |
60 animated:YES]; | |
39 } | 61 } |
40 | 62 |
41 | |
42 #pragma mark - PaymentRequestEditViewControllerDataSource | 63 #pragma mark - PaymentRequestEditViewControllerDataSource |
43 | 64 |
44 - (NSArray<EditorField*>*)editorFields { | 65 - (NSArray<EditorField*>*)editorFields { |
45 return @[ | 66 EditorField* name = |
46 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown | 67 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown |
47 label:@"Name" | 68 fieldType:EditorFieldTypeTextField |
48 value:@"John Doe" | 69 label:@"Name" |
49 required:YES], | 70 value:@"John Doe" |
50 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown | 71 required:YES]; |
51 label:@"Address" | 72 EditorField* country = |
52 value:@"" | 73 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown |
53 required:YES], | 74 fieldType:EditorFieldTypeSelector |
54 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown | 75 label:@"Country" |
55 label:@"Postal Code" | 76 value:@"CAN" |
56 value:@"" | 77 required:YES]; |
57 required:NO] | 78 [country setDisplayValue:@"Canada"]; |
58 ]; | 79 EditorField* address = |
80 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown | |
81 fieldType:EditorFieldTypeTextField | |
82 label:@"Address" | |
83 value:@"" | |
84 required:YES]; | |
85 EditorField* postalCode = | |
86 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown | |
87 fieldType:EditorFieldTypeTextField | |
88 label:@"Postal Code" | |
89 value:@"" | |
90 required:NO]; | |
91 | |
92 return @[ name, country, address, postalCode ]; | |
93 } | |
94 | |
95 - (CollectionViewItem*)headerItem { | |
96 return nil; | |
97 } | |
98 | |
99 - (BOOL)shouldHideBackgroundForHeaderItem { | |
100 return NO; | |
101 } | |
102 | |
103 #pragma mark - PaymentRequestEditViewControllerValidator | |
104 | |
105 - (NSString*)paymentRequestEditViewController: | |
106 (PaymentRequestEditViewController*)controller | |
107 validateField:(EditorField*)field { | |
108 if (field.value.length) | |
109 return nil; | |
110 else if (field.isRequired) | |
111 return @"Field is required"; | |
112 else | |
113 return nil; | |
59 } | 114 } |
60 | 115 |
61 @end | 116 @end |
OLD | NEW |