| 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)paymentRequestSelectorViewControllerDidToggleEditingMode: |
| 103 [self.contactInfoEditCoordinator start]; | 108 (PaymentRequestSelectorViewController*)controller { |
| 109 [self.viewController loadModel]; |
| 110 [self.viewController.collectionView reloadData]; |
| 111 } |
| 112 |
| 113 - (void)paymentRequestSelectorViewController: |
| 114 (PaymentRequestSelectorViewController*)controller |
| 115 didSelectItemAtIndexForEditing:(NSUInteger)index { |
| 116 DCHECK(index < self.paymentRequest->contact_profiles().size()); |
| 117 [self startContactInfoEditCoordinatorWithProfile: |
| 118 self.paymentRequest->contact_profiles()[index]]; |
| 104 } | 119 } |
| 105 | 120 |
| 106 #pragma mark - ContactInfoEditCoordinatorDelegate | 121 #pragma mark - ContactInfoEditCoordinatorDelegate |
| 107 | 122 |
| 108 - (void)contactInfoEditCoordinator:(ContactInfoEditCoordinator*)coordinator | 123 - (void)contactInfoEditCoordinator:(ContactInfoEditCoordinator*)coordinator |
| 109 didFinishEditingProfile:(autofill::AutofillProfile*)profile { | 124 didFinishEditingProfile:(autofill::AutofillProfile*)profile { |
| 125 // Update the data source with the new data. |
| 126 [self.mediator loadItems]; |
| 127 |
| 128 [self.viewController loadModel]; |
| 129 [self.viewController.collectionView reloadData]; |
| 130 |
| 110 [self.contactInfoEditCoordinator stop]; | 131 [self.contactInfoEditCoordinator stop]; |
| 111 self.contactInfoEditCoordinator = nil; | 132 self.contactInfoEditCoordinator = nil; |
| 112 | 133 |
| 113 // Inform |self.delegate| that |profile| has been selected. | 134 if (self.mediator.state != PaymentRequestSelectorStateEdit) { |
| 114 [self.delegate contactInfoSelectionCoordinator:self | 135 // Inform |self.delegate| that |profile| has been selected. |
| 115 didSelectContactProfile:profile]; | 136 [self.delegate contactInfoSelectionCoordinator:self |
| 137 didSelectContactProfile:profile]; |
| 138 } |
| 116 } | 139 } |
| 117 | 140 |
| 118 - (void)contactInfoEditCoordinatorDidCancel: | 141 - (void)contactInfoEditCoordinatorDidCancel: |
| 119 (ContactInfoEditCoordinator*)coordinator { | 142 (ContactInfoEditCoordinator*)coordinator { |
| 120 [self.contactInfoEditCoordinator stop]; | 143 [self.contactInfoEditCoordinator stop]; |
| 121 self.contactInfoEditCoordinator = nil; | 144 self.contactInfoEditCoordinator = nil; |
| 122 } | 145 } |
| 123 | 146 |
| 124 #pragma mark - Helper methods | 147 #pragma mark - Helper methods |
| 125 | 148 |
| 149 - (void)startContactInfoEditCoordinatorWithProfile: |
| 150 (autofill::AutofillProfile*)profile { |
| 151 self.contactInfoEditCoordinator = [[ContactInfoEditCoordinator alloc] |
| 152 initWithBaseViewController:self.viewController]; |
| 153 self.contactInfoEditCoordinator.paymentRequest = self.paymentRequest; |
| 154 self.contactInfoEditCoordinator.profile = profile; |
| 155 self.contactInfoEditCoordinator.delegate = self; |
| 156 [self.contactInfoEditCoordinator start]; |
| 157 } |
| 158 |
| 126 - (void)delayedNotifyDelegateOfSelection: | 159 - (void)delayedNotifyDelegateOfSelection: |
| 127 (autofill::AutofillProfile*)contactProfile { | 160 (autofill::AutofillProfile*)contactProfile { |
| 128 self.viewController.view.userInteractionEnabled = NO; | 161 self.viewController.view.userInteractionEnabled = NO; |
| 129 __weak ContactInfoSelectionCoordinator* weakSelf = self; | 162 __weak ContactInfoSelectionCoordinator* weakSelf = self; |
| 130 dispatch_after( | 163 dispatch_after( |
| 131 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), | 164 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), |
| 132 dispatch_get_main_queue(), ^{ | 165 dispatch_get_main_queue(), ^{ |
| 133 [weakSelf.delegate contactInfoSelectionCoordinator:weakSelf | 166 [weakSelf.delegate contactInfoSelectionCoordinator:weakSelf |
| 134 didSelectContactProfile:contactProfile]; | 167 didSelectContactProfile:contactProfile]; |
| 135 }); | 168 }); |
| 136 } | 169 } |
| 137 | 170 |
| 138 @end | 171 @end |
| OLD | NEW |