OLD | NEW |
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/payments/shipping_option_selection_coordinator.h" | 5 #import "ios/chrome/browser/payments/shipping_option_selection_coordinator.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #import "ios/chrome/browser/payments/payment_request_util.h" | 8 #import "ios/chrome/browser/payments/payment_request_util.h" |
9 | 9 |
10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 - (void)stop { | 46 - (void)stop { |
47 [self.baseViewController.navigationController popViewControllerAnimated:YES]; | 47 [self.baseViewController.navigationController popViewControllerAnimated:YES]; |
48 _viewController = nil; | 48 _viewController = nil; |
49 } | 49 } |
50 | 50 |
51 - (void)stopSpinnerAndDisplayError { | 51 - (void)stopSpinnerAndDisplayError { |
52 // Re-enable user interactions that were disabled earlier in | 52 // Re-enable user interactions that were disabled earlier in |
53 // delayedNotifyDelegateOfSelection. | 53 // delayedNotifyDelegateOfSelection. |
54 _viewController.view.userInteractionEnabled = YES; | 54 _viewController.view.userInteractionEnabled = YES; |
55 | 55 |
56 [_viewController setIsLoading:NO]; | 56 [_viewController setPending:NO]; |
57 NSString* errorMessage = | 57 [_viewController setErrorMessage:payment_request_util:: |
58 payment_request_util::GetShippingOptionSelectorErrorMessage( | 58 GetShippingOptionSelectorErrorMessage( |
59 _paymentRequest); | 59 _paymentRequest)]; |
60 [_viewController setErrorMessage:errorMessage]; | |
61 [_viewController loadModel]; | 60 [_viewController loadModel]; |
62 [[_viewController collectionView] reloadData]; | 61 [[_viewController collectionView] reloadData]; |
63 } | 62 } |
64 | 63 |
65 #pragma mark - ShippingOptionSelectionViewControllerDelegate | 64 #pragma mark - ShippingOptionSelectionViewControllerDelegate |
66 | 65 |
67 - (void)shippingOptionSelectionViewController: | 66 - (void)shippingOptionSelectionViewController: |
68 (ShippingOptionSelectionViewController*)controller | 67 (ShippingOptionSelectionViewController*)controller |
69 didSelectShippingOption: | 68 didSelectShippingOption: |
70 (web::PaymentShippingOption*)shippingOption { | 69 (web::PaymentShippingOption*)shippingOption { |
71 [self delayedNotifyDelegateOfSelection:shippingOption]; | 70 [self delayedNotifyDelegateOfSelection:shippingOption]; |
72 } | 71 } |
73 | 72 |
74 - (void)shippingOptionSelectionViewControllerDidReturn: | 73 - (void)shippingOptionSelectionViewControllerDidReturn: |
75 (ShippingOptionSelectionViewController*)controller { | 74 (ShippingOptionSelectionViewController*)controller { |
76 [_delegate shippingOptionSelectionCoordinatorDidReturn:self]; | 75 [_delegate shippingOptionSelectionCoordinatorDidReturn:self]; |
77 } | 76 } |
78 | 77 |
79 - (void)delayedNotifyDelegateOfSelection: | 78 - (void)delayedNotifyDelegateOfSelection: |
80 (web::PaymentShippingOption*)shippingOption { | 79 (web::PaymentShippingOption*)shippingOption { |
81 _viewController.view.userInteractionEnabled = NO; | 80 _viewController.view.userInteractionEnabled = NO; |
82 __weak ShippingOptionSelectionCoordinator* weakSelf = self; | 81 __weak ShippingOptionSelectionCoordinator* weakSelf = self; |
83 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, | 82 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, |
84 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), | 83 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), |
85 dispatch_get_main_queue(), ^{ | 84 dispatch_get_main_queue(), ^{ |
86 ShippingOptionSelectionCoordinator* strongSelf = weakSelf; | 85 ShippingOptionSelectionCoordinator* strongSelf = weakSelf; |
87 [strongSelf.viewController setIsLoading:YES]; | 86 // Early return if the coordinator has been deallocated. |
| 87 if (!strongSelf) |
| 88 return; |
| 89 [strongSelf.viewController setPending:YES]; |
88 [strongSelf.viewController loadModel]; | 90 [strongSelf.viewController loadModel]; |
89 [[strongSelf.viewController collectionView] reloadData]; | 91 [[strongSelf.viewController collectionView] reloadData]; |
90 | 92 |
91 [strongSelf.delegate | 93 [strongSelf.delegate |
92 shippingOptionSelectionCoordinator:strongSelf | 94 shippingOptionSelectionCoordinator:strongSelf |
93 didSelectShippingOption:shippingOption]; | 95 didSelectShippingOption:shippingOption]; |
94 }); | 96 }); |
95 } | 97 } |
96 | 98 |
97 @end | 99 @end |
OLD | NEW |