| 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/payments/shipping_address_selection_coordinator.h" | 5 #import "ios/chrome/browser/payments/shipping_address_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 "ios/chrome/browser/payments/payment_request.h" | 9 #include "ios/chrome/browser/payments/payment_request.h" |
| 10 #import "ios/chrome/browser/payments/payment_request_util.h" | 10 #import "ios/chrome/browser/payments/payment_request_util.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 - (void)stop { | 48 - (void)stop { |
| 49 [self.baseViewController.navigationController popViewControllerAnimated:YES]; | 49 [self.baseViewController.navigationController popViewControllerAnimated:YES]; |
| 50 _viewController = nil; | 50 _viewController = nil; |
| 51 } | 51 } |
| 52 | 52 |
| 53 - (void)stopSpinnerAndDisplayError { | 53 - (void)stopSpinnerAndDisplayError { |
| 54 // Re-enable user interactions that were disabled earlier in | 54 // Re-enable user interactions that were disabled earlier in |
| 55 // delayedNotifyDelegateOfSelection. | 55 // delayedNotifyDelegateOfSelection. |
| 56 _viewController.view.userInteractionEnabled = YES; | 56 _viewController.view.userInteractionEnabled = YES; |
| 57 | 57 |
| 58 [_viewController setIsLoading:NO]; | 58 [_viewController setPending:NO]; |
| 59 NSString* errorMessage = | 59 [_viewController setErrorMessage:payment_request_util:: |
| 60 payment_request_util::GetShippingAddressSelectorErrorMessage( | 60 GetShippingAddressSelectorErrorMessage( |
| 61 _paymentRequest); | 61 _paymentRequest)]; |
| 62 [_viewController setErrorMessage:errorMessage]; | |
| 63 [_viewController loadModel]; | 62 [_viewController loadModel]; |
| 64 [[_viewController collectionView] reloadData]; | 63 [[_viewController collectionView] reloadData]; |
| 65 } | 64 } |
| 66 | 65 |
| 67 #pragma mark - ShippingAddressSelectionViewControllerDelegate | 66 #pragma mark - ShippingAddressSelectionViewControllerDelegate |
| 68 | 67 |
| 69 - (void)shippingAddressSelectionViewController: | 68 - (void)shippingAddressSelectionViewController: |
| 70 (ShippingAddressSelectionViewController*)controller | 69 (ShippingAddressSelectionViewController*)controller |
| 71 didSelectShippingAddress: | 70 didSelectShippingAddress: |
| 72 (autofill::AutofillProfile*)shippingAddress { | 71 (autofill::AutofillProfile*)shippingAddress { |
| 73 [self delayedNotifyDelegateOfSelection:shippingAddress]; | 72 [self delayedNotifyDelegateOfSelection:shippingAddress]; |
| 74 } | 73 } |
| 75 | 74 |
| 76 - (void)shippingAddressSelectionViewControllerDidReturn: | 75 - (void)shippingAddressSelectionViewControllerDidReturn: |
| 77 (ShippingAddressSelectionViewController*)controller { | 76 (ShippingAddressSelectionViewController*)controller { |
| 78 [_delegate shippingAddressSelectionCoordinatorDidReturn:self]; | 77 [_delegate shippingAddressSelectionCoordinatorDidReturn:self]; |
| 79 } | 78 } |
| 80 | 79 |
| 81 - (void)delayedNotifyDelegateOfSelection: | 80 - (void)delayedNotifyDelegateOfSelection: |
| 82 (autofill::AutofillProfile*)shippingAddress { | 81 (autofill::AutofillProfile*)shippingAddress { |
| 83 _viewController.view.userInteractionEnabled = NO; | 82 _viewController.view.userInteractionEnabled = NO; |
| 84 __weak ShippingAddressSelectionCoordinator* weakSelf = self; | 83 __weak ShippingAddressSelectionCoordinator* weakSelf = self; |
| 85 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, | 84 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, |
| 86 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), | 85 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), |
| 87 dispatch_get_main_queue(), ^{ | 86 dispatch_get_main_queue(), ^{ |
| 88 ShippingAddressSelectionCoordinator* strongSelf = weakSelf; | 87 ShippingAddressSelectionCoordinator* strongSelf = weakSelf; |
| 89 [strongSelf.viewController setIsLoading:YES]; | 88 // Early return if the coordinator has been deallocated. |
| 89 if (!strongSelf) |
| 90 return; |
| 91 |
| 92 [strongSelf.viewController setPending:YES]; |
| 90 [strongSelf.viewController loadModel]; | 93 [strongSelf.viewController loadModel]; |
| 91 [[strongSelf.viewController collectionView] reloadData]; | 94 [[strongSelf.viewController collectionView] reloadData]; |
| 92 | 95 |
| 93 [strongSelf.delegate | 96 [strongSelf.delegate |
| 94 shippingAddressSelectionCoordinator:strongSelf | 97 shippingAddressSelectionCoordinator:strongSelf |
| 95 didSelectShippingAddress:shippingAddress]; | 98 didSelectShippingAddress:shippingAddress]; |
| 96 }); | 99 }); |
| 97 } | 100 } |
| 98 | 101 |
| 99 @end | 102 @end |
| OLD | NEW |