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

Side by Side Diff: ios/showcase/payments/sc_payments_editor_coordinator.mm

Issue 2876603005: [Payment Request] Refactors the edit view controller (Closed)
Patch Set: Addressed comments Created 3 years, 7 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
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:static_cast<id<PaymentRequestEditViewControllerDelegate>>(
54 self.alerter)];
55 [self.paymentRequestEditViewController setValidatorDelegate:self];
56 [self.paymentRequestEditViewController loadModel];
57 [self.baseViewController
58 pushViewController:self.paymentRequestEditViewController
59 animated:YES];
39 } 60 }
40 61
41
42 #pragma mark - PaymentRequestEditViewControllerDataSource 62 #pragma mark - PaymentRequestEditViewControllerDataSource
43 63
44 - (NSArray<EditorField*>*)editorFields { 64 - (NSArray<EditorField*>*)editorFields {
45 return @[ 65 EditorField* name =
46 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown 66 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown
47 label:@"Name" 67 fieldType:EditorFieldTypeTextField
48 value:@"John Doe" 68 label:@"Name"
49 required:YES], 69 value:@"John Doe"
50 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown 70 required:YES];
51 label:@"Address" 71 EditorField* country =
52 value:@"" 72 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown
53 required:YES], 73 fieldType:EditorFieldTypeSelector
54 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown 74 label:@"Country"
55 label:@"Postal Code" 75 value:@"CAN"
56 value:@"" 76 required:YES];
57 required:NO] 77 [country setDisplayValue:@"Canada"];
58 ]; 78 EditorField* address =
79 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown
80 fieldType:EditorFieldTypeTextField
81 label:@"Address"
82 value:@""
83 required:YES];
84 EditorField* postalCode =
85 [[EditorField alloc] initWithAutofillUIType:AutofillUITypeUnknown
86 fieldType:EditorFieldTypeTextField
87 label:@"Postal Code"
88 value:@""
89 required:NO];
90
91 return @[ name, country, address, postalCode ];
92 }
93
94 - (CollectionViewItem*)headerItem {
95 return nil;
96 }
97
98 - (BOOL)shouldHideBackgroundForHeaderItem {
99 return NO;
100 }
101
102 #pragma mark - PaymentRequestEditViewControllerValidator
103
104 - (NSString*)paymentRequestEditViewController:
105 (PaymentRequestEditViewController*)controller
106 validateField:(EditorField*)field {
107 if (field.value.length)
108 return nil;
109 else if (field.isRequired)
110 return @"Field is required";
111 else
112 return nil;
59 } 113 }
60 114
61 @end 115 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/payments/payment_request_editor_field.mm ('k') | ios/showcase/payments/sc_payments_editor_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698