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/payment_method_selection_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/payment_method_selection_coordinator.h" |
6 | 6 |
7 #include "components/autofill/core/browser/credit_card.h" | 7 #include "components/autofill/core/browser/credit_card.h" |
8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
9 #include "ios/chrome/browser/payments/payment_request.h" | 9 #include "ios/chrome/browser/payments/payment_request.h" |
10 #include "ios/chrome/browser/ui/payments/payment_method_selection_mediator.h" | 10 #include "ios/chrome/browser/ui/payments/payment_method_selection_mediator.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 @interface PaymentMethodSelectionCoordinator () | 22 @interface PaymentMethodSelectionCoordinator () |
23 | 23 |
24 @property(nonatomic, strong) | 24 @property(nonatomic, strong) |
25 CreditCardEditCoordinator* creditCardEditCoordinator; | 25 CreditCardEditCoordinator* creditCardEditCoordinator; |
26 | 26 |
27 @property(nonatomic, strong) | 27 @property(nonatomic, strong) |
28 PaymentRequestSelectorViewController* viewController; | 28 PaymentRequestSelectorViewController* viewController; |
29 | 29 |
30 @property(nonatomic, strong) PaymentMethodSelectionMediator* mediator; | 30 @property(nonatomic, strong) PaymentMethodSelectionMediator* mediator; |
31 | 31 |
| 32 // Initializes and starts the CreditCardEditCoordinator. Sets |creditCard| as |
| 33 // the credit card to be edited. |
| 34 - (void)startCreditCardEditCoordinatorWithCreditCard: |
| 35 (autofill::CreditCard*)creditCard; |
| 36 |
32 // Called when the user selects a payment method. The cell is checked, the | 37 // Called when the user selects a payment method. The cell is checked, the |
33 // UI is locked so that the user can't interact with it, then the delegate is | 38 // UI is locked so that the user can't interact with it, then the delegate is |
34 // notified. The delay is here to let the user get a visual feedback of the | 39 // notified. The delay is here to let the user get a visual feedback of the |
35 // selection before this view disappears. | 40 // selection before this view disappears. |
36 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod; | 41 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod; |
37 | 42 |
38 @end | 43 @end |
39 | 44 |
40 @implementation PaymentMethodSelectionCoordinator | 45 @implementation PaymentMethodSelectionCoordinator |
41 @synthesize paymentRequest = _paymentRequest; | 46 @synthesize paymentRequest = _paymentRequest; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ->credit_cards()[index]]; | 87 ->credit_cards()[index]]; |
83 } | 88 } |
84 | 89 |
85 - (void)paymentRequestSelectorViewControllerDidFinish: | 90 - (void)paymentRequestSelectorViewControllerDidFinish: |
86 (PaymentRequestSelectorViewController*)controller { | 91 (PaymentRequestSelectorViewController*)controller { |
87 [self.delegate paymentMethodSelectionCoordinatorDidReturn:self]; | 92 [self.delegate paymentMethodSelectionCoordinatorDidReturn:self]; |
88 } | 93 } |
89 | 94 |
90 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: | 95 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: |
91 (PaymentRequestSelectorViewController*)controller { | 96 (PaymentRequestSelectorViewController*)controller { |
92 self.creditCardEditCoordinator = [[CreditCardEditCoordinator alloc] | 97 [self startCreditCardEditCoordinatorWithCreditCard:nil]; |
93 initWithBaseViewController:self.viewController]; | 98 } |
94 self.creditCardEditCoordinator.paymentRequest = self.paymentRequest; | 99 |
95 self.creditCardEditCoordinator.delegate = self; | 100 - (void)paymentRequestSelectorViewController: |
96 [self.creditCardEditCoordinator start]; | 101 (PaymentRequestSelectorViewController*)controller |
| 102 didChangeToState: |
| 103 (PaymentRequestSelectorState)state { |
| 104 // Update the data source with the new state. |
| 105 self.mediator.state = state; |
| 106 |
| 107 [self.viewController loadModel]; |
| 108 [self.viewController.collectionView reloadData]; |
| 109 } |
| 110 |
| 111 - (void)paymentRequestSelectorViewController: |
| 112 (PaymentRequestSelectorViewController*)controller |
| 113 didSelectItemAtIndexForEditing:(NSUInteger)index { |
| 114 DCHECK(index < self.paymentRequest->credit_cards().size()); |
| 115 [self |
| 116 startCreditCardEditCoordinatorWithCreditCard:self.paymentRequest |
| 117 ->credit_cards()[index]]; |
97 } | 118 } |
98 | 119 |
99 #pragma mark - CreditCardEditCoordinatorDelegate | 120 #pragma mark - CreditCardEditCoordinatorDelegate |
100 | 121 |
101 - (void)creditCardEditCoordinator:(CreditCardEditCoordinator*)coordinator | 122 - (void)creditCardEditCoordinator:(CreditCardEditCoordinator*)coordinator |
102 didFinishEditingCreditCard:(autofill::CreditCard*)creditCard { | 123 didFinishEditingCreditCard:(autofill::CreditCard*)creditCard { |
| 124 // Update the data source with the new data. |
| 125 [self.mediator createItems]; |
| 126 |
| 127 [self.viewController loadModel]; |
| 128 [self.viewController.collectionView reloadData]; |
| 129 |
103 [self.creditCardEditCoordinator stop]; | 130 [self.creditCardEditCoordinator stop]; |
104 self.creditCardEditCoordinator = nil; | 131 self.creditCardEditCoordinator = nil; |
105 | 132 |
106 // Inform |self.delegate| that this card has been selected. | 133 if (self.mediator.state != PaymentRequestSelectorStateEdit) { |
107 [self.delegate paymentMethodSelectionCoordinator:self | 134 // Inform |self.delegate| that this card has been selected. |
108 didSelectPaymentMethod:creditCard]; | 135 [self.delegate paymentMethodSelectionCoordinator:self |
| 136 didSelectPaymentMethod:creditCard]; |
| 137 } |
109 } | 138 } |
110 | 139 |
111 - (void)creditCardEditCoordinatorDidCancel: | 140 - (void)creditCardEditCoordinatorDidCancel: |
112 (CreditCardEditCoordinator*)coordinator { | 141 (CreditCardEditCoordinator*)coordinator { |
113 [self.creditCardEditCoordinator stop]; | 142 [self.creditCardEditCoordinator stop]; |
114 self.creditCardEditCoordinator = nil; | 143 self.creditCardEditCoordinator = nil; |
115 } | 144 } |
116 | 145 |
117 #pragma mark - Helper methods | 146 #pragma mark - Helper methods |
118 | 147 |
| 148 - (void)startCreditCardEditCoordinatorWithCreditCard: |
| 149 (autofill::CreditCard*)creditCard { |
| 150 self.creditCardEditCoordinator = [[CreditCardEditCoordinator alloc] |
| 151 initWithBaseViewController:self.viewController]; |
| 152 self.creditCardEditCoordinator.paymentRequest = self.paymentRequest; |
| 153 self.creditCardEditCoordinator.creditCard = creditCard; |
| 154 self.creditCardEditCoordinator.delegate = self; |
| 155 [self.creditCardEditCoordinator start]; |
| 156 } |
| 157 |
119 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod { | 158 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod { |
120 self.viewController.view.userInteractionEnabled = NO; | 159 self.viewController.view.userInteractionEnabled = NO; |
121 __weak PaymentMethodSelectionCoordinator* weakSelf = self; | 160 __weak PaymentMethodSelectionCoordinator* weakSelf = self; |
122 dispatch_after( | 161 dispatch_after( |
123 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), | 162 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), |
124 dispatch_get_main_queue(), ^{ | 163 dispatch_get_main_queue(), ^{ |
125 weakSelf.viewController.view.userInteractionEnabled = YES; | 164 weakSelf.viewController.view.userInteractionEnabled = YES; |
126 [weakSelf.delegate paymentMethodSelectionCoordinator:weakSelf | 165 [weakSelf.delegate paymentMethodSelectionCoordinator:weakSelf |
127 didSelectPaymentMethod:paymentMethod]; | 166 didSelectPaymentMethod:paymentMethod]; |
128 }); | 167 }); |
129 } | 168 } |
130 | 169 |
131 @end | 170 @end |
OLD | NEW |