| 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/chrome/browser/ui/payments/contact_info_edit_mediator.h" | 5 #import "ios/chrome/browser/ui/payments/contact_info_edit_mediator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_country.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/autofill_type.h" | 11 #include "components/autofill/core/browser/autofill_type.h" |
| 11 #include "components/autofill/core/browser/field_types.h" | 12 #include "components/autofill/core/browser/field_types.h" |
| 13 #include "components/payments/core/payment_request_data_util.h" |
| 12 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
| 13 #include "ios/chrome/browser/application_context.h" | 15 #include "ios/chrome/browser/application_context.h" |
| 14 #include "ios/chrome/browser/payments/payment_request.h" | 16 #include "ios/chrome/browser/payments/payment_request.h" |
| 15 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 17 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
| 16 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" | 18 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" |
| 17 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 19 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 19 | 21 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) | 22 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." | 23 #error "This file requires ARC support." |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #pragma mark - PaymentRequestEditViewControllerDataSource | 69 #pragma mark - PaymentRequestEditViewControllerDataSource |
| 68 | 70 |
| 69 - (CollectionViewItem*)headerItem { | 71 - (CollectionViewItem*)headerItem { |
| 70 return nil; | 72 return nil; |
| 71 } | 73 } |
| 72 | 74 |
| 73 - (BOOL)shouldHideBackgroundForHeaderItem { | 75 - (BOOL)shouldHideBackgroundForHeaderItem { |
| 74 return NO; | 76 return NO; |
| 75 } | 77 } |
| 76 | 78 |
| 79 - (void)formatValueForEditorField:(EditorField*)field { |
| 80 if (field.autofillUIType == AutofillUITypeProfileHomePhoneWholeNumber) { |
| 81 const std::string countryCode = |
| 82 autofill::AutofillCountry::CountryCodeForLocale( |
| 83 GetApplicationContext()->GetApplicationLocale()); |
| 84 field.value = |
| 85 base::SysUTF8ToNSString(payments::data_util::FormatPhoneForDisplay( |
| 86 base::SysNSStringToUTF8(field.value), countryCode)); |
| 87 } |
| 88 } |
| 89 |
| 77 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { | 90 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { |
| 78 return nil; | 91 return nil; |
| 79 } | 92 } |
| 80 | 93 |
| 81 #pragma mark - Helper methods | 94 #pragma mark - Helper methods |
| 82 | 95 |
| 83 // Creates and returns an array of editor fields. | 96 // Creates and returns an array of editor fields. |
| 84 - (NSArray<EditorField*>*)createEditorFields { | 97 - (NSArray<EditorField*>*)createEditorFields { |
| 85 self.fields = [[NSMutableArray alloc] init]; | 98 self.fields = [[NSMutableArray alloc] init]; |
| 86 | 99 |
| 87 if (_paymentRequest->request_payer_name()) { | 100 if (_paymentRequest->request_payer_name()) { |
| 88 NSString* name = | 101 NSString* name = |
| 89 [self fieldValueFromProfile:self.profile fieldType:autofill::NAME_FULL]; | 102 [self fieldValueFromProfile:self.profile fieldType:autofill::NAME_FULL]; |
| 90 EditorField* nameField = [[EditorField alloc] | 103 EditorField* nameField = [[EditorField alloc] |
| 91 initWithAutofillUIType:AutofillUITypeProfileFullName | 104 initWithAutofillUIType:AutofillUITypeProfileFullName |
| 92 fieldType:EditorFieldTypeTextField | 105 fieldType:EditorFieldTypeTextField |
| 93 label:l10n_util::GetNSString( | 106 label:l10n_util::GetNSString( |
| 94 IDS_PAYMENTS_NAME_FIELD_IN_CONTACT_DETAILS) | 107 IDS_PAYMENTS_NAME_FIELD_IN_CONTACT_DETAILS) |
| 95 value:name | 108 value:name |
| 96 required:YES]; | 109 required:YES]; |
| 97 [self.fields addObject:nameField]; | 110 [self.fields addObject:nameField]; |
| 98 } | 111 } |
| 99 | 112 |
| 100 if (_paymentRequest->request_payer_phone()) { | 113 if (_paymentRequest->request_payer_phone()) { |
| 101 NSString* phone = | 114 NSString* phone = |
| 102 [self fieldValueFromProfile:self.profile | 115 self.profile |
| 103 fieldType:autofill::PHONE_HOME_WHOLE_NUMBER]; | 116 ? base::SysUTF16ToNSString( |
| 117 payments::data_util::GetFormattedPhoneNumberForDisplay( |
| 118 *self.profile, |
| 119 GetApplicationContext()->GetApplicationLocale())) |
| 120 : nil; |
| 104 EditorField* phoneField = [[EditorField alloc] | 121 EditorField* phoneField = [[EditorField alloc] |
| 105 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber | 122 initWithAutofillUIType:AutofillUITypeProfileHomePhoneWholeNumber |
| 106 fieldType:EditorFieldTypeTextField | 123 fieldType:EditorFieldTypeTextField |
| 107 label:l10n_util::GetNSString( | 124 label:l10n_util::GetNSString( |
| 108 IDS_PAYMENTS_PHONE_FIELD_IN_CONTACT_DETAILS) | 125 IDS_PAYMENTS_PHONE_FIELD_IN_CONTACT_DETAILS) |
| 109 value:phone | 126 value:phone |
| 110 required:YES]; | 127 required:YES]; |
| 111 [self.fields addObject:phoneField]; | 128 [self.fields addObject:phoneField]; |
| 112 } | 129 } |
| 113 | 130 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 134 // corresponding field value. Returns nil if |profile| is nullptr. | 151 // corresponding field value. Returns nil if |profile| is nullptr. |
| 135 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile | 152 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile |
| 136 fieldType:(autofill::ServerFieldType)fieldType { | 153 fieldType:(autofill::ServerFieldType)fieldType { |
| 137 return profile ? base::SysUTF16ToNSString(profile->GetInfo( | 154 return profile ? base::SysUTF16ToNSString(profile->GetInfo( |
| 138 autofill::AutofillType(fieldType), | 155 autofill::AutofillType(fieldType), |
| 139 GetApplicationContext()->GetApplicationLocale())) | 156 GetApplicationContext()->GetApplicationLocale())) |
| 140 : nil; | 157 : nil; |
| 141 } | 158 } |
| 142 | 159 |
| 143 @end | 160 @end |
| OLD | NEW |