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

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

Issue 2949813003: [Payment Request] Formats phone number and credit card number in editors. (Closed)
Patch Set: 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
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/chrome/browser/ui/payments/address_edit_mediator.h" 5 #import "ios/chrome/browser/ui/payments/address_edit_mediator.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/autofill/core/browser/autofill_address_util.h" 16 #include "components/autofill/core/browser/autofill_address_util.h"
17 #include "components/autofill/core/browser/autofill_country.h" 17 #include "components/autofill/core/browser/autofill_country.h"
18 #include "components/autofill/core/browser/autofill_profile.h" 18 #include "components/autofill/core/browser/autofill_profile.h"
19 #include "components/autofill/core/browser/autofill_type.h" 19 #include "components/autofill/core/browser/autofill_type.h"
20 #include "components/autofill/core/browser/country_combobox_model.h" 20 #include "components/autofill/core/browser/country_combobox_model.h"
21 #include "components/autofill/core/browser/field_types.h" 21 #include "components/autofill/core/browser/field_types.h"
22 #include "components/autofill/core/browser/personal_data_manager.h" 22 #include "components/autofill/core/browser/personal_data_manager.h"
23 #include "components/payments/core/payment_request_data_util.h"
23 #include "components/strings/grit/components_strings.h" 24 #include "components/strings/grit/components_strings.h"
24 #include "ios/chrome/browser/application_context.h" 25 #include "ios/chrome/browser/application_context.h"
25 #include "ios/chrome/browser/payments/payment_request.h" 26 #include "ios/chrome/browser/payments/payment_request.h"
26 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" 27 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
27 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" 28 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h"
28 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" 29 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h"
29 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" 30 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h"
30 #include "ios/chrome/grit/ios_strings.h" 31 #include "ios/chrome/grit/ios_strings.h"
31 #include "third_party/libaddressinput/messages.h" 32 #include "third_party/libaddressinput/messages.h"
32 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #pragma mark - CreditCardEditViewControllerDataSource 113 #pragma mark - CreditCardEditViewControllerDataSource
113 114
114 - (CollectionViewItem*)headerItem { 115 - (CollectionViewItem*)headerItem {
115 return nil; 116 return nil;
116 } 117 }
117 118
118 - (BOOL)shouldHideBackgroundForHeaderItem { 119 - (BOOL)shouldHideBackgroundForHeaderItem {
119 return NO; 120 return NO;
120 } 121 }
121 122
123 - (void)formatValueForEditorField:(EditorField*)field {
124 if (field.autofillUIType == AutofillUITypeProfileHomePhoneWholeNumber) {
125 field.value =
126 base::SysUTF8ToNSString(payments::data_util::FormatPhoneForDisplay(
127 base::SysNSStringToUTF8(field.value),
128 base::SysNSStringToUTF8(self.selectedCountryCode)));
129 }
130 }
131
122 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { 132 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field {
123 return nil; 133 return nil;
124 } 134 }
125 135
126 #pragma mark - RegionDataLoaderConsumer 136 #pragma mark - RegionDataLoaderConsumer
127 137
128 - (void)regionDataLoaderDidSucceedWithRegions: 138 - (void)regionDataLoaderDidSucceedWithRegions:
129 (NSMutableArray<NSString*>*)regions { 139 (NSMutableArray<NSString*>*)regions {
130 self.regions = regions; 140 self.regions = regions;
131 // Enable the previously disabled field. 141 // Enable the previously disabled field.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 298 }
289 } 299 }
290 } 300 }
291 301
292 // Always add phone number field at the end. 302 // Always add phone number field at the end.
293 NSNumber* phoneNumberFieldKey = 303 NSNumber* phoneNumberFieldKey =
294 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber]; 304 [NSNumber numberWithInt:AutofillUITypeProfileHomePhoneWholeNumber];
295 EditorField* field = self.fieldsMap[phoneNumberFieldKey]; 305 EditorField* field = self.fieldsMap[phoneNumberFieldKey];
296 if (!field) { 306 if (!field) {
297 NSString* value = 307 NSString* value =
298 [self fieldValueFromProfile:self.address 308 self.address
299 fieldType:autofill::PHONE_HOME_WHOLE_NUMBER]; 309 ? base::SysUTF16ToNSString(
310 payments::data_util::GetFormattedPhoneNumberForDisplay(
311 *self.address,
312 GetApplicationContext()->GetApplicationLocale()))
313 : nil;
300 field = [[EditorField alloc] 314 field = [[EditorField alloc]
301 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber 315 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber
302 fieldType:EditorFieldTypeTextField 316 fieldType:EditorFieldTypeTextField
303 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE) 317 label:l10n_util::GetNSString(IDS_IOS_AUTOFILL_PHONE)
304 value:value 318 value:value
305 required:YES]; 319 required:YES];
306 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey]; 320 [self.fieldsMap setObject:field forKey:phoneNumberFieldKey];
307 } 321 }
308 [self.fields addObject:field]; 322 [self.fields addObject:field];
309 323
310 return self.fields; 324 return self.fields;
311 } 325 }
312 326
313 // Takes in an autofill profile and an autofill field type and returns the 327 // Takes in an autofill profile and an autofill field type and returns the
314 // corresponding field value. Returns nil if |profile| is nullptr. 328 // corresponding field value. Returns nil if |profile| is nullptr.
315 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile 329 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile
316 fieldType:(autofill::ServerFieldType)fieldType { 330 fieldType:(autofill::ServerFieldType)fieldType {
317 return profile ? base::SysUTF16ToNSString(profile->GetInfo( 331 return profile ? base::SysUTF16ToNSString(profile->GetInfo(
318 autofill::AutofillType(fieldType), 332 autofill::AutofillType(fieldType),
319 GetApplicationContext()->GetApplicationLocale())) 333 GetApplicationContext()->GetApplicationLocale()))
320 : nil; 334 : nil;
321 } 335 }
322 336
323 @end 337 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698