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_selection_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/contact_info_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 "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 @interface ContactInfoSelectionCoordinator () | 28 @interface ContactInfoSelectionCoordinator () |
29 | 29 |
30 @property(nonatomic, strong) | 30 @property(nonatomic, strong) |
31 ContactInfoEditCoordinator* contactInfoEditCoordinator; | 31 ContactInfoEditCoordinator* contactInfoEditCoordinator; |
32 | 32 |
33 @property(nonatomic, strong) | 33 @property(nonatomic, strong) |
34 PaymentRequestSelectorViewController* viewController; | 34 PaymentRequestSelectorViewController* viewController; |
35 | 35 |
36 @property(nonatomic, strong) ContactInfoSelectionMediator* mediator; | 36 @property(nonatomic, strong) ContactInfoSelectionMediator* mediator; |
37 | 37 |
| 38 // Initializes and starts the ContactInfoEditCoordinator. Sets |profile| as the |
| 39 // profile to be edited. |
| 40 - (void)startContactInfoEditCoordinatorWithProfile: |
| 41 (autofill::AutofillProfile*)profile; |
| 42 |
38 // Called when the user selects a contact profile. The cell is checked, the | 43 // Called when the user selects a contact profile. The cell is checked, the |
39 // UI is locked so that the user can't interact with it, then the delegate is | 44 // UI is locked so that the user can't interact with it, then the delegate is |
40 // notified. | 45 // notified. |
41 - (void)delayedNotifyDelegateOfSelection: | 46 - (void)delayedNotifyDelegateOfSelection: |
42 (autofill::AutofillProfile*)contactProfile; | 47 (autofill::AutofillProfile*)contactProfile; |
43 | 48 |
44 @end | 49 @end |
45 | 50 |
46 @implementation ContactInfoSelectionCoordinator | 51 @implementation ContactInfoSelectionCoordinator |
47 | 52 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ->contact_profiles()[index]]; | 94 ->contact_profiles()[index]]; |
90 } | 95 } |
91 | 96 |
92 - (void)paymentRequestSelectorViewControllerDidFinish: | 97 - (void)paymentRequestSelectorViewControllerDidFinish: |
93 (PaymentRequestSelectorViewController*)controller { | 98 (PaymentRequestSelectorViewController*)controller { |
94 [self.delegate contactInfoSelectionCoordinatorDidReturn:self]; | 99 [self.delegate contactInfoSelectionCoordinatorDidReturn:self]; |
95 } | 100 } |
96 | 101 |
97 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: | 102 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: |
98 (PaymentRequestSelectorViewController*)controller { | 103 (PaymentRequestSelectorViewController*)controller { |
99 self.contactInfoEditCoordinator = [[ContactInfoEditCoordinator alloc] | 104 [self startContactInfoEditCoordinatorWithProfile:nil]; |
100 initWithBaseViewController:self.viewController]; | 105 } |
101 self.contactInfoEditCoordinator.paymentRequest = self.paymentRequest; | 106 |
102 self.contactInfoEditCoordinator.delegate = self; | 107 - (void)paymentRequestSelectorViewController: |
103 [self.contactInfoEditCoordinator start]; | 108 (PaymentRequestSelectorViewController*)controller |
| 109 didChangeToState: |
| 110 (PaymentRequestSelectorState)state { |
| 111 // Update the data source with the new state. |
| 112 self.mediator.state = state; |
| 113 |
| 114 [self.viewController loadModel]; |
| 115 [self.viewController.collectionView reloadData]; |
| 116 } |
| 117 |
| 118 - (void)paymentRequestSelectorViewController: |
| 119 (PaymentRequestSelectorViewController*)controller |
| 120 didSelectItemAtIndexForEditing:(NSUInteger)index { |
| 121 DCHECK(index < self.paymentRequest->contact_profiles().size()); |
| 122 [self startContactInfoEditCoordinatorWithProfile: |
| 123 self.paymentRequest->contact_profiles()[index]]; |
104 } | 124 } |
105 | 125 |
106 #pragma mark - ContactInfoEditCoordinatorDelegate | 126 #pragma mark - ContactInfoEditCoordinatorDelegate |
107 | 127 |
108 - (void)contactInfoEditCoordinator:(ContactInfoEditCoordinator*)coordinator | 128 - (void)contactInfoEditCoordinator:(ContactInfoEditCoordinator*)coordinator |
109 didFinishEditingProfile:(autofill::AutofillProfile*)profile { | 129 didFinishEditingProfile:(autofill::AutofillProfile*)profile { |
| 130 // Update the data source with the new data. |
| 131 [self.mediator createItems]; |
| 132 |
| 133 [self.viewController loadModel]; |
| 134 [self.viewController.collectionView reloadData]; |
| 135 |
110 [self.contactInfoEditCoordinator stop]; | 136 [self.contactInfoEditCoordinator stop]; |
111 self.contactInfoEditCoordinator = nil; | 137 self.contactInfoEditCoordinator = nil; |
112 | 138 |
113 // Inform |self.delegate| that |profile| has been selected. | 139 if (self.mediator.state != PaymentRequestSelectorStateEdit) { |
114 [self.delegate contactInfoSelectionCoordinator:self | 140 // Inform |self.delegate| that |profile| has been selected. |
115 didSelectContactProfile:profile]; | 141 [self.delegate contactInfoSelectionCoordinator:self |
| 142 didSelectContactProfile:profile]; |
| 143 } |
116 } | 144 } |
117 | 145 |
118 - (void)contactInfoEditCoordinatorDidCancel: | 146 - (void)contactInfoEditCoordinatorDidCancel: |
119 (ContactInfoEditCoordinator*)coordinator { | 147 (ContactInfoEditCoordinator*)coordinator { |
120 [self.contactInfoEditCoordinator stop]; | 148 [self.contactInfoEditCoordinator stop]; |
121 self.contactInfoEditCoordinator = nil; | 149 self.contactInfoEditCoordinator = nil; |
122 } | 150 } |
123 | 151 |
124 #pragma mark - Helper methods | 152 #pragma mark - Helper methods |
125 | 153 |
| 154 - (void)startContactInfoEditCoordinatorWithProfile: |
| 155 (autofill::AutofillProfile*)profile { |
| 156 self.contactInfoEditCoordinator = [[ContactInfoEditCoordinator alloc] |
| 157 initWithBaseViewController:self.viewController]; |
| 158 self.contactInfoEditCoordinator.paymentRequest = self.paymentRequest; |
| 159 self.contactInfoEditCoordinator.profile = profile; |
| 160 self.contactInfoEditCoordinator.delegate = self; |
| 161 [self.contactInfoEditCoordinator start]; |
| 162 } |
| 163 |
126 - (void)delayedNotifyDelegateOfSelection: | 164 - (void)delayedNotifyDelegateOfSelection: |
127 (autofill::AutofillProfile*)contactProfile { | 165 (autofill::AutofillProfile*)contactProfile { |
128 self.viewController.view.userInteractionEnabled = NO; | 166 self.viewController.view.userInteractionEnabled = NO; |
129 __weak ContactInfoSelectionCoordinator* weakSelf = self; | 167 __weak ContactInfoSelectionCoordinator* weakSelf = self; |
130 dispatch_after( | 168 dispatch_after( |
131 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), | 169 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), |
132 dispatch_get_main_queue(), ^{ | 170 dispatch_get_main_queue(), ^{ |
133 [weakSelf.delegate contactInfoSelectionCoordinator:weakSelf | 171 [weakSelf.delegate contactInfoSelectionCoordinator:weakSelf |
134 didSelectContactProfile:contactProfile]; | 172 didSelectContactProfile:contactProfile]; |
135 }); | 173 }); |
136 } | 174 } |
137 | 175 |
138 @end | 176 @end |
OLD | NEW |