Index: ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm |
diff --git a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm b/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm |
index 14d8864dfeeaea3847ea3c2ae9fc6212208e943d..6f1be34c95d6d348378c32466c0b2a00787607fb 100644 |
--- a/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm |
+++ b/ios/chrome/browser/ui/payments/shipping_address_selection_coordinator.mm |
@@ -34,6 +34,11 @@ const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC; |
@property(nonatomic, strong) ShippingAddressSelectionMediator* mediator; |
+// Initializes and starts the AddressEditCoordinator. Sets |address| as the |
+// address to be edited. |
+- (void)startAddressEditCoordinatorWithAddress: |
+ (autofill::AutofillProfile*)address; |
+ |
// Called when the user selects a shipping address. The cell is checked, the |
// UI is locked so that the user can't interact with it, then the delegate is |
// notified. The delay is here to let the user get a visual feedback of the |
@@ -114,23 +119,41 @@ const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC; |
- (void)paymentRequestSelectorViewControllerDidSelectAddItem: |
(PaymentRequestSelectorViewController*)controller { |
- self.addressEditCoordinator = [[AddressEditCoordinator alloc] |
- initWithBaseViewController:self.viewController]; |
- self.addressEditCoordinator.paymentRequest = self.paymentRequest; |
- self.addressEditCoordinator.delegate = self; |
- [self.addressEditCoordinator start]; |
+ [self startAddressEditCoordinatorWithAddress:nil]; |
+} |
+ |
+- (void)paymentRequestSelectorViewControllerDidToggleEditingMode { |
+ [self.viewController loadModel]; |
+ [self.viewController.collectionView reloadData]; |
+} |
+ |
+- (void)paymentRequestSelectorViewController: |
+ (PaymentRequestSelectorViewController*)controller |
+ didSelectItemAtIndexForEditing:(NSUInteger)index { |
+ DCHECK(index < self.paymentRequest->shipping_profiles().size()); |
+ [self |
+ startAddressEditCoordinatorWithAddress:self.paymentRequest |
+ ->shipping_profiles()[index]]; |
} |
#pragma mark - AddressEditCoordinatorDelegate |
- (void)addressEditCoordinator:(AddressEditCoordinator*)coordinator |
didFinishEditingAddress:(autofill::AutofillProfile*)address { |
+ // Update the data source with the new data. |
+ [self.mediator loadItems]; |
+ |
+ [self.viewController loadModel]; |
+ [self.viewController.collectionView reloadData]; |
+ |
[self.addressEditCoordinator stop]; |
self.addressEditCoordinator = nil; |
- // Inform |self.delegate| that |address| has been selected. |
- [self.delegate shippingAddressSelectionCoordinator:self |
- didSelectShippingAddress:address]; |
+ if (self.mediator.state != PaymentRequestSelectorStateEdit) { |
+ // Inform |self.delegate| that |address| has been selected. |
+ [self.delegate shippingAddressSelectionCoordinator:self |
+ didSelectShippingAddress:address]; |
+ } |
} |
- (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { |
@@ -140,6 +163,16 @@ const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC; |
#pragma mark - Helper methods |
+- (void)startAddressEditCoordinatorWithAddress: |
+ (autofill::AutofillProfile*)address { |
+ self.addressEditCoordinator = [[AddressEditCoordinator alloc] |
+ initWithBaseViewController:self.viewController]; |
+ self.addressEditCoordinator.paymentRequest = self.paymentRequest; |
+ self.addressEditCoordinator.address = address; |
+ self.addressEditCoordinator.delegate = self; |
+ [self.addressEditCoordinator start]; |
+} |
+ |
- (void)delayedNotifyDelegateOfSelection: |
(autofill::AutofillProfile*)shippingAddress { |
self.viewController.view.userInteractionEnabled = NO; |