| 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 "components/payments/core/strings_util.h" | 9 #include "components/payments/core/strings_util.h" |
| 10 #include "ios/chrome/browser/payments/payment_request.h" | 10 #include "ios/chrome/browser/payments/payment_request.h" |
| 11 #include "ios/chrome/browser/payments/payment_request_selector_view_controller.h
" | 11 #include "ios/chrome/browser/payments/payment_request_selector_view_controller.h
" |
| 12 #import "ios/chrome/browser/payments/payment_request_util.h" | 12 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 13 #include "ios/chrome/browser/payments/shipping_address_selection_mediator.h" | 13 #include "ios/chrome/browser/payments/shipping_address_selection_mediator.h" |
| 14 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 using ::payment_request_util::GetShippingAddressSelectorErrorMessage; | 20 using ::payment_request_util::GetShippingAddressSelectorErrorMessage; |
| 21 using ::payments::GetShippingAddressSectionString; | 21 using ::payments::GetShippingAddressSectionString; |
| 22 using ::payments::GetShippingAddressSelectorInfoMessage; | 22 using ::payments::GetShippingAddressSelectorInfoMessage; |
| 23 |
| 24 // The delay in nano seconds before notifying the delegate of the selection. |
| 25 const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC; |
| 23 } // namespace | 26 } // namespace |
| 24 | 27 |
| 25 @interface ShippingAddressSelectionCoordinator () | 28 @interface ShippingAddressSelectionCoordinator () |
| 26 | 29 |
| 27 @property(nonatomic, strong) | 30 @property(nonatomic, strong) |
| 28 PaymentRequestSelectorViewController* viewController; | 31 PaymentRequestSelectorViewController* viewController; |
| 29 | 32 |
| 30 @property(nonatomic, strong) ShippingAddressSelectionMediator* mediator; | 33 @property(nonatomic, strong) ShippingAddressSelectionMediator* mediator; |
| 31 | 34 |
| 32 // Called when the user selects a shipping address. The cell is checked, the | 35 // Called when the user selects a shipping address. The cell is checked, the |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // TODO(crbug.com/602666): Present a shipping address addition UI. | 112 // TODO(crbug.com/602666): Present a shipping address addition UI. |
| 110 } | 113 } |
| 111 | 114 |
| 112 #pragma mark - Helper methods | 115 #pragma mark - Helper methods |
| 113 | 116 |
| 114 - (void)delayedNotifyDelegateOfSelection: | 117 - (void)delayedNotifyDelegateOfSelection: |
| 115 (autofill::AutofillProfile*)shippingAddress { | 118 (autofill::AutofillProfile*)shippingAddress { |
| 116 self.viewController.view.userInteractionEnabled = NO; | 119 self.viewController.view.userInteractionEnabled = NO; |
| 117 __weak ShippingAddressSelectionCoordinator* weakSelf = self; | 120 __weak ShippingAddressSelectionCoordinator* weakSelf = self; |
| 118 dispatch_after( | 121 dispatch_after( |
| 119 dispatch_time(DISPATCH_TIME_NOW, | 122 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds), |
| 120 static_cast<int64_t>(0.2 * NSEC_PER_SEC)), | |
| 121 dispatch_get_main_queue(), ^{ | 123 dispatch_get_main_queue(), ^{ |
| 122 [weakSelf.mediator setState:PaymentRequestSelectorStatePending]; | 124 [weakSelf.mediator setState:PaymentRequestSelectorStatePending]; |
| 123 [weakSelf.viewController loadModel]; | 125 [weakSelf.viewController loadModel]; |
| 124 [[weakSelf.viewController collectionView] reloadData]; | 126 [weakSelf.viewController.collectionView reloadData]; |
| 125 | 127 |
| 126 [weakSelf.delegate shippingAddressSelectionCoordinator:weakSelf | 128 [weakSelf.delegate shippingAddressSelectionCoordinator:weakSelf |
| 127 didSelectShippingAddress:shippingAddress]; | 129 didSelectShippingAddress:shippingAddress]; |
| 128 }); | 130 }); |
| 129 } | 131 } |
| 130 | 132 |
| 131 @end | 133 @end |
| OLD | NEW |