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

Side by Side Diff: ios/chrome/browser/ui/payments/contact_info_edit_mediator.mm

Issue 2932703004: [Payment Request] Contact Info editor (Closed)
Patch Set: Addressed comments Created 3 years, 6 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/chrome/browser/ui/payments/contact_info_edit_mediator.h"
6
7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/autofill_type.h"
11 #include "components/autofill/core/browser/field_types.h"
12 #include "components/strings/grit/components_strings.h"
13 #include "ios/chrome/browser/application_context.h"
14 #include "ios/chrome/browser/payments/payment_request.h"
15 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
16 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h"
17 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 #if !defined(__has_feature) || !__has_feature(objc_arc)
21 #error "This file requires ARC support."
22 #endif
23
24 @interface ContactInfoEditMediator ()
25
26 // The PaymentRequest object owning an instance of web::PaymentRequest as
27 // provided by the page invoking the Payment Request API. This is a weak
28 // pointer and should outlive this class.
29 @property(nonatomic, assign) PaymentRequest* paymentRequest;
30
31 // The profile to be edited, if any. This pointer is not owned by this class and
32 // should outlive it.
33 @property(nonatomic, assign) autofill::AutofillProfile* profile;
34
35 // The list of current editor fields.
36 @property(nonatomic, strong) NSMutableArray<EditorField*>* fields;
37
38 @end
39
40 @implementation ContactInfoEditMediator
41
42 @synthesize state = _state;
43 @synthesize consumer = _consumer;
44 @synthesize paymentRequest = _paymentRequest;
45 @synthesize profile = _profile;
46 @synthesize fields = _fields;
47
48 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest
49 profile:(autofill::AutofillProfile*)profile {
50 self = [super init];
51 if (self) {
52 _paymentRequest = paymentRequest;
53 _profile = profile;
54 _state =
55 _profile ? EditViewControllerStateEdit : EditViewControllerStateCreate;
56 }
57 return self;
58 }
59
60 #pragma mark - Setters
61
62 - (void)setConsumer:(id<PaymentRequestEditConsumer>)consumer {
63 _consumer = consumer;
64 [self.consumer setEditorFields:[self createEditorFields]];
65 }
66
67 #pragma mark - PaymentRequestEditViewControllerDataSource
68
69 - (CollectionViewItem*)headerItem {
70 return nil;
71 }
72
73 - (BOOL)shouldHideBackgroundForHeaderItem {
74 return NO;
75 }
76
77 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field {
78 return nil;
79 }
80
81 #pragma mark - Helper methods
82
83 // Creates and returns an array of editor fields.
84 - (NSArray<EditorField*>*)createEditorFields {
85 self.fields = [[NSMutableArray alloc] init];
86
87 if (_paymentRequest->request_payer_name()) {
88 NSString* name = self.profile
89 ? base::SysUTF16ToNSString(self.profile->GetInfo(
90 autofill::AutofillType(autofill::NAME_FULL),
91 GetApplicationContext()->GetApplicationLocale()))
92 : nil;
93 EditorField* nameField = [[EditorField alloc]
94 initWithAutofillUIType:AutofillUITypeProfileFullName
95 fieldType:EditorFieldTypeTextField
96 label:l10n_util::GetNSString(
97 IDS_PAYMENTS_NAME_FIELD_IN_CONTACT_DETAILS)
98 value:name
99 required:YES];
100 [self.fields addObject:nameField];
101 }
102
103 if (_paymentRequest->request_payer_phone()) {
104 NSString* phone =
105 self.profile
106 ? base::SysUTF16ToNSString(self.profile->GetInfo(
107 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
108 GetApplicationContext()->GetApplicationLocale()))
109 : nil;
110 EditorField* phoneField = [[EditorField alloc]
111 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber
112 fieldType:EditorFieldTypeTextField
113 label:l10n_util::GetNSString(
114 IDS_PAYMENTS_PHONE_FIELD_IN_CONTACT_DETAILS)
115 value:phone
116 required:YES];
117 [self.fields addObject:phoneField];
118 }
119
120 if (_paymentRequest->request_payer_email()) {
121 NSString* email =
122 self.profile ? base::SysUTF16ToNSString(self.profile->GetInfo(
123 autofill::AutofillType(autofill::EMAIL_ADDRESS),
124 GetApplicationContext()->GetApplicationLocale()))
125 : nil;
126 EditorField* emailField = [[EditorField alloc]
127 initWithAutofillUIType:AutofillUITypeProfileEmailAddress
128 fieldType:EditorFieldTypeTextField
129 label:l10n_util::GetNSString(
130 IDS_PAYMENTS_EMAIL_FIELD_IN_CONTACT_DETAILS)
131 value:email
132 required:YES];
133 [self.fields addObject:emailField];
134 }
135
136 DCHECK(self.fields.count > 0) << "The contact info editor shouldn't be "
137 "reachable if no contact information is "
138 "requested.";
139 return self.fields;
140 }
141
142 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698