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

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

Issue 2950843002: [Payment Request] Populates region field if region code/name is valid. (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>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 @property(nonatomic, strong) EditorField* regionField; 61 @property(nonatomic, strong) EditorField* regionField;
62 62
63 @end 63 @end
64 64
65 @implementation AddressEditMediator 65 @implementation AddressEditMediator
66 66
67 @synthesize state = _state; 67 @synthesize state = _state;
68 @synthesize consumer = _consumer; 68 @synthesize consumer = _consumer;
69 @synthesize countries = _countries; 69 @synthesize countries = _countries;
70 @synthesize selectedCountryCode = _selectedCountryCode; 70 @synthesize selectedCountryCode = _selectedCountryCode;
71 @synthesize regions = _regions;
72 @synthesize paymentRequest = _paymentRequest; 71 @synthesize paymentRequest = _paymentRequest;
73 @synthesize address = _address; 72 @synthesize address = _address;
74 @synthesize fieldsMap = _fieldsMap; 73 @synthesize fieldsMap = _fieldsMap;
75 @synthesize fields = _fields; 74 @synthesize fields = _fields;
76 @synthesize regionField = _regionField; 75 @synthesize regionField = _regionField;
77 76
78 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest 77 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest
79 address:(autofill::AutofillProfile*)address { 78 address:(autofill::AutofillProfile*)address {
80 self = [super init]; 79 self = [super init];
81 if (self) { 80 if (self) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return NO; 118 return NO;
120 } 119 }
121 120
122 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { 121 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field {
123 return nil; 122 return nil;
124 } 123 }
125 124
126 #pragma mark - RegionDataLoaderConsumer 125 #pragma mark - RegionDataLoaderConsumer
127 126
128 - (void)regionDataLoaderDidSucceedWithRegions: 127 - (void)regionDataLoaderDidSucceedWithRegions:
129 (NSMutableArray<NSString*>*)regions { 128 (NSDictionary<NSString*, NSString*>*)regions {
130 self.regions = regions;
131 // Enable the previously disabled field. 129 // Enable the previously disabled field.
132 self.regionField.enabled = YES; 130 self.regionField.enabled = YES;
133 131
134 // If an address is being edited and it has a valid region, the field value is 132 // If an address is being edited and it has a valid region code or name, the
135 // set to that region. Otherwise, set the field value to nil. If creating an 133 // field value is set to that respective region code. Otherwise, it is set to
136 // address, set the first available region as the field value, if possible. 134 // nil.
135 self.regionField.value = nil;
137 if (self.address) { 136 if (self.address) {
138 NSString* region = 137 NSString* region =
139 [self fieldValueFromProfile:self.address 138 [self fieldValueFromProfile:self.address
140 fieldType:autofill::ADDRESS_HOME_STATE]; 139 fieldType:autofill::ADDRESS_HOME_STATE];
141 self.regionField.value = 140 if ([regions objectForKey:region])
macourteau 2017/06/20 16:24:59 This block needs more documentation: - what are th
Moe 2017/06/20 18:28:34 Done.
142 [self.regions containsObject:region] ? region : nil; 141 self.regionField.value = region;
143 } else { 142 else if ([[regions allKeysForObject:region] count])
macourteau 2017/06/20 16:24:59 Might want to check that count returns exactly one
Moe 2017/06/20 18:28:33 There should be a one to one mapping between regio
macourteau 2017/06/20 18:31:30 Right, so then maybe add a DCHECK that count is on
144 self.regionField.value = regions.count ? regions[0] : nil; 143 self.regionField.value = [regions allKeysForObject:region][0];
please use gerrit instead 2017/06/20 15:38:31 Please get this reviewed by someone who can read O
Moe 2017/06/20 18:58:35 Done.
145 } 144 }
146 145
147 // Notify the view controller asynchronously to allow for the view to update. 146 // Notify the view controller asynchronously to allow for the view to update.
148 __weak AddressEditMediator* weakSelf = self; 147 __weak AddressEditMediator* weakSelf = self;
149 dispatch_async(dispatch_get_main_queue(), ^{ 148 dispatch_async(dispatch_get_main_queue(), ^{
150 [weakSelf.consumer setOptions:weakSelf.regions 149 [weakSelf.consumer setOptions:[regions allKeys]
151 forEditorField:weakSelf.regionField]; 150 forEditorField:weakSelf.regionField];
152 }); 151 });
153 } 152 }
154 153
155 #pragma mark - Helper methods 154 #pragma mark - Helper methods
156 155
157 // Loads the country codes and names and sets the default selected country code. 156 // Loads the country codes and names and sets the default selected country code.
158 - (void)loadCountries { 157 - (void)loadCountries {
159 autofill::CountryComboboxModel countryModel; 158 autofill::CountryComboboxModel countryModel;
160 countryModel.SetCountries(*_paymentRequest->GetPersonalDataManager(), 159 countryModel.SetCountries(*_paymentRequest->GetPersonalDataManager(),
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // corresponding field value. Returns nil if |profile| is nullptr. 313 // corresponding field value. Returns nil if |profile| is nullptr.
315 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile 314 - (NSString*)fieldValueFromProfile:(autofill::AutofillProfile*)profile
316 fieldType:(autofill::ServerFieldType)fieldType { 315 fieldType:(autofill::ServerFieldType)fieldType {
317 return profile ? base::SysUTF16ToNSString(profile->GetInfo( 316 return profile ? base::SysUTF16ToNSString(profile->GetInfo(
318 autofill::AutofillType(fieldType), 317 autofill::AutofillType(fieldType),
319 GetApplicationContext()->GetApplicationLocale())) 318 GetApplicationContext()->GetApplicationLocale()))
320 : nil; 319 : nil;
321 } 320 }
322 321
323 @end 322 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698