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

Side by Side Diff: ios/chrome/browser/ui/payments/billing_address_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
« no previous file with comments | « no previous file | ios/chrome/browser/ui/payments/billing_address_selection_mediator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/billing_address_selection_coordinator.h" 5 #import "ios/chrome/browser/ui/payments/billing_address_selection_coordinator.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "components/autofill/core/browser/autofill_profile.h" 8 #include "components/autofill/core/browser/autofill_profile.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #include "ios/chrome/browser/payments/payment_request.h" 10 #include "ios/chrome/browser/payments/payment_request.h"
(...skipping 11 matching lines...) Expand all
22 22
23 @interface BillingAddressSelectionCoordinator () 23 @interface BillingAddressSelectionCoordinator ()
24 24
25 @property(nonatomic, strong) AddressEditCoordinator* addressEditCoordinator; 25 @property(nonatomic, strong) AddressEditCoordinator* addressEditCoordinator;
26 26
27 @property(nonatomic, strong) 27 @property(nonatomic, strong)
28 PaymentRequestSelectorViewController* viewController; 28 PaymentRequestSelectorViewController* viewController;
29 29
30 @property(nonatomic, strong) BillingAddressSelectionMediator* mediator; 30 @property(nonatomic, strong) BillingAddressSelectionMediator* mediator;
31 31
32 // Initializes and starts the AddressEditCoordinator. Sets |address| as the
33 // address to be edited.
34 - (void)startAddressEditCoordinatorWithAddress:
35 (autofill::AutofillProfile*)address;
36
32 // Called when the user selects a billing address. The cell is checked, the 37 // Called when the user selects a billing address. 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: 41 - (void)delayedNotifyDelegateOfSelection:
37 (autofill::AutofillProfile*)billingAddress; 42 (autofill::AutofillProfile*)billingAddress;
38 43
39 @end 44 @end
40 45
41 @implementation BillingAddressSelectionCoordinator 46 @implementation BillingAddressSelectionCoordinator
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ->billing_profiles()[index]]; 91 ->billing_profiles()[index]];
87 } 92 }
88 93
89 - (void)paymentRequestSelectorViewControllerDidFinish: 94 - (void)paymentRequestSelectorViewControllerDidFinish:
90 (PaymentRequestSelectorViewController*)controller { 95 (PaymentRequestSelectorViewController*)controller {
91 [self.delegate billingAddressSelectionCoordinatorDidReturn:self]; 96 [self.delegate billingAddressSelectionCoordinatorDidReturn:self];
92 } 97 }
93 98
94 - (void)paymentRequestSelectorViewControllerDidSelectAddItem: 99 - (void)paymentRequestSelectorViewControllerDidSelectAddItem:
95 (PaymentRequestSelectorViewController*)controller { 100 (PaymentRequestSelectorViewController*)controller {
96 self.addressEditCoordinator = [[AddressEditCoordinator alloc] 101 [self startAddressEditCoordinatorWithAddress:nil];
97 initWithBaseViewController:self.viewController]; 102 }
98 self.addressEditCoordinator.paymentRequest = self.paymentRequest; 103
99 self.addressEditCoordinator.delegate = self; 104 - (void)paymentRequestSelectorViewControllerDidToggleEditingMode:
100 [self.addressEditCoordinator start]; 105 (PaymentRequestSelectorViewController*)controller {
106 [self.viewController loadModel];
107 [self.viewController.collectionView reloadData];
108 }
109
110 - (void)paymentRequestSelectorViewController:
111 (PaymentRequestSelectorViewController*)controller
112 didSelectItemAtIndexForEditing:(NSUInteger)index {
113 DCHECK(index < self.paymentRequest->billing_profiles().size());
114 [self startAddressEditCoordinatorWithAddress:self.paymentRequest
115 ->billing_profiles()[index]];
101 } 116 }
102 117
103 #pragma mark - AddressEditCoordinatorDelegate 118 #pragma mark - AddressEditCoordinatorDelegate
104 119
105 - (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator 120 - (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator
106 didFinishEditingAddress:(autofill::AutofillProfile*)address { 121 didFinishEditingAddress:(autofill::AutofillProfile*)address {
122 // Update the data source with the new data.
123 [self.mediator loadItems];
124
125 [self.viewController loadModel];
126 [self.viewController.collectionView reloadData];
127
107 [self.addressEditCoordinator stop]; 128 [self.addressEditCoordinator stop];
108 self.addressEditCoordinator = nil; 129 self.addressEditCoordinator = nil;
109 130
110 // Inform |self.delegate| that |address| has been selected. 131 if (self.mediator.state != PaymentRequestSelectorStateEdit) {
111 [self.delegate billingAddressSelectionCoordinator:self 132 // Inform |self.delegate| that |address| has been selected.
112 didSelectBillingAddress:address]; 133 [self.delegate billingAddressSelectionCoordinator:self
134 didSelectBillingAddress:address];
135 }
113 } 136 }
114 137
115 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { 138 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator {
116 [self.addressEditCoordinator stop]; 139 [self.addressEditCoordinator stop];
117 self.addressEditCoordinator = nil; 140 self.addressEditCoordinator = nil;
118 } 141 }
119 142
120 #pragma mark - Helper methods 143 #pragma mark - Helper methods
121 144
145 - (void)startAddressEditCoordinatorWithAddress:
146 (autofill::AutofillProfile*)address {
147 self.addressEditCoordinator = [[AddressEditCoordinator alloc]
148 initWithBaseViewController:self.viewController];
149 self.addressEditCoordinator.paymentRequest = self.paymentRequest;
150 self.addressEditCoordinator.address = address;
151 self.addressEditCoordinator.delegate = self;
152 [self.addressEditCoordinator start];
153 }
154
122 - (void)delayedNotifyDelegateOfSelection: 155 - (void)delayedNotifyDelegateOfSelection:
123 (autofill::AutofillProfile*)billingAddress { 156 (autofill::AutofillProfile*)billingAddress {
124 self.viewController.view.userInteractionEnabled = NO; 157 self.viewController.view.userInteractionEnabled = NO;
125 __weak BillingAddressSelectionCoordinator* weakSelf = self; 158 __weak BillingAddressSelectionCoordinator* weakSelf = self;
126 dispatch_after( 159 dispatch_after(
127 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), 160 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds),
128 dispatch_get_main_queue(), ^{ 161 dispatch_get_main_queue(), ^{
129 [weakSelf.delegate billingAddressSelectionCoordinator:weakSelf 162 [weakSelf.delegate billingAddressSelectionCoordinator:weakSelf
130 didSelectBillingAddress:billingAddress]; 163 didSelectBillingAddress:billingAddress];
131 }); 164 });
132 } 165 }
133 166
134 @end 167 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/payments/billing_address_selection_mediator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698