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

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

Issue 2938673003: [Payment Request] Selector view edit mode (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 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
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
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)paymentRequestSelectorViewControllerDidToggleEditingMode {
96 [self.creditCardEditCoordinator start]; 101 [self.viewController loadModel];
102 [self.viewController.collectionView reloadData];
103 }
104
105 - (void)paymentRequestSelectorViewController:
106 (PaymentRequestSelectorViewController*)controller
107 didSelectItemAtIndexForEditing:(NSUInteger)index {
108 DCHECK(index < self.paymentRequest->credit_cards().size());
109 [self
110 startCreditCardEditCoordinatorWithCreditCard:self.paymentRequest
111 ->credit_cards()[index]];
97 } 112 }
98 113
99 #pragma mark - CreditCardEditCoordinatorDelegate 114 #pragma mark - CreditCardEditCoordinatorDelegate
100 115
101 - (void)creditCardEditCoordinator:(CreditCardEditCoordinator*)coordinator 116 - (void)creditCardEditCoordinator:(CreditCardEditCoordinator*)coordinator
102 didFinishEditingCreditCard:(autofill::CreditCard*)creditCard { 117 didFinishEditingCreditCard:(autofill::CreditCard*)creditCard {
118 // Update the data source with the new data.
119 [self.mediator loadItems];
120
121 [self.viewController loadModel];
122 [self.viewController.collectionView reloadData];
123
103 [self.creditCardEditCoordinator stop]; 124 [self.creditCardEditCoordinator stop];
104 self.creditCardEditCoordinator = nil; 125 self.creditCardEditCoordinator = nil;
105 126
106 // Inform |self.delegate| that this card has been selected. 127 if (self.mediator.state != PaymentRequestSelectorStateEdit) {
107 [self.delegate paymentMethodSelectionCoordinator:self 128 // Inform |self.delegate| that this card has been selected.
108 didSelectPaymentMethod:creditCard]; 129 [self.delegate paymentMethodSelectionCoordinator:self
130 didSelectPaymentMethod:creditCard];
131 }
109 } 132 }
110 133
111 - (void)creditCardEditCoordinatorDidCancel: 134 - (void)creditCardEditCoordinatorDidCancel:
112 (CreditCardEditCoordinator*)coordinator { 135 (CreditCardEditCoordinator*)coordinator {
113 [self.creditCardEditCoordinator stop]; 136 [self.creditCardEditCoordinator stop];
114 self.creditCardEditCoordinator = nil; 137 self.creditCardEditCoordinator = nil;
115 } 138 }
116 139
117 #pragma mark - Helper methods 140 #pragma mark - Helper methods
118 141
142 - (void)startCreditCardEditCoordinatorWithCreditCard:
143 (autofill::CreditCard*)creditCard {
144 self.creditCardEditCoordinator = [[CreditCardEditCoordinator alloc]
145 initWithBaseViewController:self.viewController];
146 self.creditCardEditCoordinator.paymentRequest = self.paymentRequest;
147 self.creditCardEditCoordinator.creditCard = creditCard;
148 self.creditCardEditCoordinator.delegate = self;
149 [self.creditCardEditCoordinator start];
150 }
151
119 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod { 152 - (void)delayedNotifyDelegateOfSelection:(autofill::CreditCard*)paymentMethod {
120 self.viewController.view.userInteractionEnabled = NO; 153 self.viewController.view.userInteractionEnabled = NO;
121 __weak PaymentMethodSelectionCoordinator* weakSelf = self; 154 __weak PaymentMethodSelectionCoordinator* weakSelf = self;
122 dispatch_after( 155 dispatch_after(
123 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), 156 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds),
124 dispatch_get_main_queue(), ^{ 157 dispatch_get_main_queue(), ^{
125 weakSelf.viewController.view.userInteractionEnabled = YES; 158 weakSelf.viewController.view.userInteractionEnabled = YES;
126 [weakSelf.delegate paymentMethodSelectionCoordinator:weakSelf 159 [weakSelf.delegate paymentMethodSelectionCoordinator:weakSelf
127 didSelectPaymentMethod:paymentMethod]; 160 didSelectPaymentMethod:paymentMethod];
128 }); 161 });
129 } 162 }
130 163
131 @end 164 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698