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

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

Issue 2908033002: [Payment Request] Refactors edit view controller (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
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_coordinator.h" 5 #import "ios/chrome/browser/ui/payments/address_edit_coordinator.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 13 matching lines...) Expand all
24 namespace { 24 namespace {
25 using ::AutofillUITypeFromAutofillType; 25 using ::AutofillUITypeFromAutofillType;
26 using ::AutofillTypeFromAutofillUIType; 26 using ::AutofillTypeFromAutofillUIType;
27 } // namespace 27 } // namespace
28 28
29 @interface AddressEditCoordinator () 29 @interface AddressEditCoordinator ()
30 30
31 @property(nonatomic, strong) 31 @property(nonatomic, strong)
32 CountrySelectionCoordinator* countrySelectionCoordinator; 32 CountrySelectionCoordinator* countrySelectionCoordinator;
33 33
34 @property(nonatomic, strong) AddressEditViewController* viewController; 34 @property(nonatomic, strong) PaymentRequestEditViewController* viewController;
35 35
36 @property(nonatomic, strong) AddressEditMediator* mediator; 36 @property(nonatomic, strong) AddressEditMediator* mediator;
37 37
38 @end 38 @end
39 39
40 @implementation AddressEditCoordinator 40 @implementation AddressEditCoordinator
41 41
42 @synthesize address = _address; 42 @synthesize address = _address;
43 @synthesize paymentRequest = _paymentRequest; 43 @synthesize paymentRequest = _paymentRequest;
44 @synthesize delegate = _delegate; 44 @synthesize delegate = _delegate;
45 @synthesize countrySelectionCoordinator = _countrySelectionCoordinator; 45 @synthesize countrySelectionCoordinator = _countrySelectionCoordinator;
46 @synthesize viewController = _viewController; 46 @synthesize viewController = _viewController;
47 @synthesize mediator = _mediator; 47 @synthesize mediator = _mediator;
48 48
49 - (void)start { 49 - (void)start {
50 self.viewController = [[AddressEditViewController alloc] init]; 50 self.viewController = [[PaymentRequestEditViewController alloc] init];
51 // TODO(crbug.com/602666): Title varies depending on what field is missing. 51 // TODO(crbug.com/602666): Title varies depending on what field is missing.
52 // e.g., Add Email vs. Add Phone Number. 52 // e.g., Add Email vs. Add Phone Number.
53 NSString* title = self.address 53 NSString* title = self.address
54 ? l10n_util::GetNSString(IDS_PAYMENTS_EDIT_ADDRESS) 54 ? l10n_util::GetNSString(IDS_PAYMENTS_EDIT_ADDRESS)
55 : l10n_util::GetNSString(IDS_PAYMENTS_ADD_ADDRESS); 55 : l10n_util::GetNSString(IDS_PAYMENTS_ADD_ADDRESS);
56 [self.viewController setTitle:title]; 56 [self.viewController setTitle:title];
57 [self.viewController setDelegate:self]; 57 [self.viewController setDelegate:self];
58 [self.viewController setValidatorDelegate:self]; 58 [self.viewController setValidatorDelegate:self];
59 self.mediator = 59 self.mediator =
60 [[AddressEditMediator alloc] initWithPaymentRequest:self.paymentRequest 60 [[AddressEditMediator alloc] initWithPaymentRequest:self.paymentRequest
(...skipping 20 matching lines...) Expand all
81 - (NSString*)paymentRequestEditViewController: 81 - (NSString*)paymentRequestEditViewController:
82 (PaymentRequestEditViewController*)controller 82 (PaymentRequestEditViewController*)controller
83 validateField:(EditorField*)field { 83 validateField:(EditorField*)field {
84 if (!field.value.length && field.isRequired) { 84 if (!field.value.length && field.isRequired) {
85 return l10n_util::GetNSString( 85 return l10n_util::GetNSString(
86 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 86 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
87 } 87 }
88 return nil; 88 return nil;
89 } 89 }
90 90
91 #pragma mark - AddressEditViewControllerDelegate 91 #pragma mark - PaymentRequestEditViewControllerDelegate
92 92
93 - (void)paymentRequestEditViewController: 93 - (void)paymentRequestEditViewController:
94 (PaymentRequestEditViewController*)controller 94 (PaymentRequestEditViewController*)controller
95 didSelectField:(EditorField*)field { 95 didSelectField:(EditorField*)field {
96 if (field.autofillUIType == AutofillUITypeProfileHomeAddressCountry) { 96 if (field.autofillUIType == AutofillUITypeProfileHomeAddressCountry) {
97 self.countrySelectionCoordinator = [[CountrySelectionCoordinator alloc] 97 self.countrySelectionCoordinator = [[CountrySelectionCoordinator alloc]
98 initWithBaseViewController:self.viewController]; 98 initWithBaseViewController:self.viewController];
99 [self.countrySelectionCoordinator setCountries:self.mediator.countries]; 99 [self.countrySelectionCoordinator setCountries:self.mediator.countries];
100 [self.countrySelectionCoordinator 100 [self.countrySelectionCoordinator
101 setSelectedCountryCode:self.mediator.selectedCountryCode]; 101 setSelectedCountryCode:self.mediator.selectedCountryCode];
102 [self.countrySelectionCoordinator setDelegate:self]; 102 [self.countrySelectionCoordinator setDelegate:self];
103 [self.countrySelectionCoordinator start]; 103 [self.countrySelectionCoordinator start];
104 } 104 }
105 } 105 }
106 106
107 - (void)addressEditViewController:(AddressEditViewController*)controller 107 - (void)paymentRequestEditViewController:
108 didFinishEditingFields:(NSArray<EditorField*>*)fields { 108 (PaymentRequestEditViewController*)controller
109 didFinishEditingFields:(NSArray<EditorField*>*)fields {
109 // Create an empty autofill profile. If an address is being edited, copy over 110 // Create an empty autofill profile. If an address is being edited, copy over
110 // the information. 111 // the information.
111 autofill::AutofillProfile address = 112 autofill::AutofillProfile address =
112 self.address ? *self.address 113 self.address ? *self.address
113 : autofill::AutofillProfile(base::GenerateGUID(), 114 : autofill::AutofillProfile(base::GenerateGUID(),
114 autofill::kSettingsOrigin); 115 autofill::kSettingsOrigin);
115 116
116 for (EditorField* field in fields) { 117 for (EditorField* field in fields) {
117 address.SetRawInfo(AutofillTypeFromAutofillUIType(field.autofillUIType), 118 address.SetRawInfo(AutofillTypeFromAutofillUIType(field.autofillUIType),
118 base::SysNSStringToUTF16(field.value)); 119 base::SysNSStringToUTF16(field.value));
(...skipping 10 matching lines...) Expand all
129 self.paymentRequest->GetPersonalDataManager()->UpdateProfile(address); 130 self.paymentRequest->GetPersonalDataManager()->UpdateProfile(address);
130 131
131 // Update the original profile instance that is being edited. 132 // Update the original profile instance that is being edited.
132 *self.address = address; 133 *self.address = address;
133 } 134 }
134 135
135 [self.delegate addressEditCoordinator:self 136 [self.delegate addressEditCoordinator:self
136 didFinishEditingAddress:self.address]; 137 didFinishEditingAddress:self.address];
137 } 138 }
138 139
139 - (void)addressEditViewControllerDidCancel: 140 - (void)paymentRequestEditViewControllerDidCancel:
140 (AddressEditViewController*)controller { 141 (PaymentRequestEditViewController*)controller {
141 [self.delegate addressEditCoordinatorDidCancel:self]; 142 [self.delegate addressEditCoordinatorDidCancel:self];
142 } 143 }
143 144
144 #pragma mark - CountrySelectionCoordinatorDelegate 145 #pragma mark - CountrySelectionCoordinatorDelegate
145 146
146 - (void)countrySelectionCoordinator:(CountrySelectionCoordinator*)coordinator 147 - (void)countrySelectionCoordinator:(CountrySelectionCoordinator*)coordinator
147 didSelectCountryWithCode:(NSString*)countryCode { 148 didSelectCountryWithCode:(NSString*)countryCode {
148 if (self.mediator.selectedCountryCode != countryCode) { 149 if (self.mediator.selectedCountryCode != countryCode) {
149 [self.mediator setSelectedCountryCode:countryCode]; 150 [self.mediator setSelectedCountryCode:countryCode];
150 [self.viewController loadModel]; 151 [self.viewController loadModel];
151 [self.viewController.collectionView reloadData]; 152 [self.viewController.collectionView reloadData];
152 } 153 }
153 [self.countrySelectionCoordinator stop]; 154 [self.countrySelectionCoordinator stop];
154 self.countrySelectionCoordinator = nil; 155 self.countrySelectionCoordinator = nil;
155 } 156 }
156 157
157 @end 158 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698