OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/shipping_address_selection_coordinator.h
" | 5 #import "ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.h
" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_profile.h" | 8 #include "components/autofill/core/browser/autofill_profile.h" |
9 #include "components/payments/core/strings_util.h" | 9 #include "components/payments/core/strings_util.h" |
10 #include "ios/chrome/browser/payments/payment_request.h" | 10 #include "ios/chrome/browser/payments/payment_request.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 @interface ShippingAddressSelectionCoordinator () | 28 @interface ShippingAddressSelectionCoordinator () |
29 | 29 |
30 @property(nonatomic, strong) AddressEditCoordinator* addressEditCoordinator; | 30 @property(nonatomic, strong) AddressEditCoordinator* addressEditCoordinator; |
31 | 31 |
32 @property(nonatomic, strong) | 32 @property(nonatomic, strong) |
33 PaymentRequestSelectorViewController* viewController; | 33 PaymentRequestSelectorViewController* viewController; |
34 | 34 |
35 @property(nonatomic, strong) ShippingAddressSelectionMediator* mediator; | 35 @property(nonatomic, strong) ShippingAddressSelectionMediator* mediator; |
36 | 36 |
| 37 // Initializes and starts the AddressEditCoordinator. Sets |address| as the |
| 38 // address to be edited. |
| 39 - (void)startAddressEditCoordinatorWithAddress: |
| 40 (autofill::AutofillProfile*)address; |
| 41 |
37 // Called when the user selects a shipping address. The cell is checked, the | 42 // Called when the user selects a shipping address. The cell is checked, the |
38 // UI is locked so that the user can't interact with it, then the delegate is | 43 // UI is locked so that the user can't interact with it, then the delegate is |
39 // notified. The delay is here to let the user get a visual feedback of the | 44 // notified. The delay is here to let the user get a visual feedback of the |
40 // selection before this view disappears. | 45 // selection before this view disappears. |
41 - (void)delayedNotifyDelegateOfSelection: | 46 - (void)delayedNotifyDelegateOfSelection: |
42 (autofill::AutofillProfile*)shippingAddress; | 47 (autofill::AutofillProfile*)shippingAddress; |
43 | 48 |
44 @end | 49 @end |
45 | 50 |
46 @implementation ShippingAddressSelectionCoordinator | 51 @implementation ShippingAddressSelectionCoordinator |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ->shipping_profiles()[index]]; | 112 ->shipping_profiles()[index]]; |
108 } | 113 } |
109 | 114 |
110 - (void)paymentRequestSelectorViewControllerDidFinish: | 115 - (void)paymentRequestSelectorViewControllerDidFinish: |
111 (PaymentRequestSelectorViewController*)controller { | 116 (PaymentRequestSelectorViewController*)controller { |
112 [self.delegate shippingAddressSelectionCoordinatorDidReturn:self]; | 117 [self.delegate shippingAddressSelectionCoordinatorDidReturn:self]; |
113 } | 118 } |
114 | 119 |
115 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: | 120 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: |
116 (PaymentRequestSelectorViewController*)controller { | 121 (PaymentRequestSelectorViewController*)controller { |
117 self.addressEditCoordinator = [[AddressEditCoordinator alloc] | 122 [self startAddressEditCoordinatorWithAddress:nil]; |
118 initWithBaseViewController:self.viewController]; | 123 } |
119 self.addressEditCoordinator.paymentRequest = self.paymentRequest; | 124 |
120 self.addressEditCoordinator.delegate = self; | 125 - (void)paymentRequestSelectorViewControllerDidToggleEditingMode { |
121 [self.addressEditCoordinator start]; | 126 [self.viewController loadModel]; |
| 127 [self.viewController.collectionView reloadData]; |
| 128 } |
| 129 |
| 130 - (void)paymentRequestSelectorViewController: |
| 131 (PaymentRequestSelectorViewController*)controller |
| 132 didSelectItemAtIndexForEditing:(NSUInteger)index { |
| 133 DCHECK(index < self.paymentRequest->shipping_profiles().size()); |
| 134 [self |
| 135 startAddressEditCoordinatorWithAddress:self.paymentRequest |
| 136 ->shipping_profiles()[index]]; |
122 } | 137 } |
123 | 138 |
124 #pragma mark - AddressEditCoordinatorDelegate | 139 #pragma mark - AddressEditCoordinatorDelegate |
125 | 140 |
126 - (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator | 141 - (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator |
127 didFinishEditingAddress:(autofill::AutofillProfile*)address { | 142 didFinishEditingAddress:(autofill::AutofillProfile*)address { |
| 143 // Update the data source with the new data. |
| 144 [self.mediator loadItems]; |
| 145 |
| 146 [self.viewController loadModel]; |
| 147 [self.viewController.collectionView reloadData]; |
| 148 |
128 [self.addressEditCoordinator stop]; | 149 [self.addressEditCoordinator stop]; |
129 self.addressEditCoordinator = nil; | 150 self.addressEditCoordinator = nil; |
130 | 151 |
131 // Inform |self.delegate| that |address| has been selected. | 152 if (self.mediator.state != PaymentRequestSelectorStateEdit) { |
132 [self.delegate shippingAddressSelectionCoordinator:self | 153 // Inform |self.delegate| that |address| has been selected. |
133 didSelectShippingAddress:address]; | 154 [self.delegate shippingAddressSelectionCoordinator:self |
| 155 didSelectShippingAddress:address]; |
| 156 } |
134 } | 157 } |
135 | 158 |
136 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { | 159 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { |
137 [self.addressEditCoordinator stop]; | 160 [self.addressEditCoordinator stop]; |
138 self.addressEditCoordinator = nil; | 161 self.addressEditCoordinator = nil; |
139 } | 162 } |
140 | 163 |
141 #pragma mark - Helper methods | 164 #pragma mark - Helper methods |
142 | 165 |
| 166 - (void)startAddressEditCoordinatorWithAddress: |
| 167 (autofill::AutofillProfile*)address { |
| 168 self.addressEditCoordinator = [[AddressEditCoordinator alloc] |
| 169 initWithBaseViewController:self.viewController]; |
| 170 self.addressEditCoordinator.paymentRequest = self.paymentRequest; |
| 171 self.addressEditCoordinator.address = address; |
| 172 self.addressEditCoordinator.delegate = self; |
| 173 [self.addressEditCoordinator start]; |
| 174 } |
| 175 |
143 - (void)delayedNotifyDelegateOfSelection: | 176 - (void)delayedNotifyDelegateOfSelection: |
144 (autofill::AutofillProfile*)shippingAddress { | 177 (autofill::AutofillProfile*)shippingAddress { |
145 self.viewController.view.userInteractionEnabled = NO; | 178 self.viewController.view.userInteractionEnabled = NO; |
146 __weak ShippingAddressSelectionCoordinator* weakSelf = self; | 179 __weak ShippingAddressSelectionCoordinator* weakSelf = self; |
147 dispatch_after( | 180 dispatch_after( |
148 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), | 181 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), |
149 dispatch_get_main_queue(), ^{ | 182 dispatch_get_main_queue(), ^{ |
150 [weakSelf.mediator setState:PaymentRequestSelectorStatePending]; | 183 [weakSelf.mediator setState:PaymentRequestSelectorStatePending]; |
151 [weakSelf.viewController loadModel]; | 184 [weakSelf.viewController loadModel]; |
152 [weakSelf.viewController.collectionView reloadData]; | 185 [weakSelf.viewController.collectionView reloadData]; |
153 | 186 |
154 [weakSelf.delegate shippingAddressSelectionCoordinator:weakSelf | 187 [weakSelf.delegate shippingAddressSelectionCoordinator:weakSelf |
155 didSelectShippingAddress:shippingAddress]; | 188 didSelectShippingAddress:shippingAddress]; |
156 }); | 189 }); |
157 } | 190 } |
158 | 191 |
159 @end | 192 @end |
OLD | NEW |