Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
lpromero
2017/01/11 12:51:15
2017, here and in every file.
Moe
2017/01/12 00:06:18
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/payments/shipping_option_selection_coordinator.h" | |
| 6 | |
| 7 #import "base/ios/weak_nsobject.h" | |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h " | |
| 10 | |
| 11 @interface ShippingOptionSelectionCoordinator ()< | |
| 12 ShippingOptionSelectionViewControllerDelegate> { | |
| 13 base::WeakNSProtocol<id<ShippingOptionSelectionCoordinatorDelegate>> | |
| 14 _delegate; | |
| 15 base::scoped_nsobject<ShippingOptionSelectionViewController> _viewController; | |
| 16 } | |
| 17 | |
| 18 // Called when the user selects a shipping option. The cell is checked, the | |
| 19 // UI is locked so that the user can't interact with it, then the delegate is | |
| 20 // notified. The delay is here to let the user get a visual feedback of the | |
| 21 // selection before this view disappears. | |
| 22 - (void)delayedNotifyDelegateOfSelection; | |
| 23 | |
| 24 @end | |
| 25 | |
| 26 @implementation ShippingOptionSelectionCoordinator | |
| 27 | |
| 28 @synthesize shippingOptions = _shippingOptions; | |
| 29 @synthesize selectedShippingOption = _selectedShippingOption; | |
| 30 | |
| 31 - (id<ShippingOptionSelectionCoordinatorDelegate>)delegate { | |
| 32 return _delegate.get(); | |
| 33 } | |
| 34 | |
| 35 - (void)setDelegate:(id<ShippingOptionSelectionCoordinatorDelegate>)delegate { | |
| 36 _delegate.reset(delegate); | |
| 37 } | |
| 38 | |
| 39 - (void)start { | |
| 40 _viewController.reset([[ShippingOptionSelectionViewController alloc] init]); | |
| 41 [_viewController setShippingOptions:_shippingOptions]; | |
| 42 [_viewController setSelectedShippingOption:_selectedShippingOption]; | |
| 43 [_viewController setDelegate:self]; | |
| 44 [_viewController loadModel]; | |
| 45 | |
| 46 DCHECK(self.baseViewController.navigationController); | |
|
lpromero
2017/01/11 12:51:15
No action needed: We never need baseViewController
Moe
2017/01/12 00:06:18
Acknowledged.
| |
| 47 [self.baseViewController.navigationController | |
| 48 pushViewController:_viewController | |
| 49 animated:YES]; | |
| 50 } | |
| 51 | |
| 52 - (void)stop { | |
| 53 [self.baseViewController.navigationController popViewControllerAnimated:YES]; | |
| 54 _viewController.reset(); | |
| 55 } | |
| 56 | |
| 57 #pragma mark - ShippingOptionSelectionViewControllerDelegate | |
| 58 | |
| 59 - (void)shippingOptionSelectionViewController: | |
| 60 (ShippingOptionSelectionViewController*)controller | |
| 61 selectedShippingOption: | |
| 62 (web::PaymentShippingOption*)shippingOption { | |
| 63 _selectedShippingOption = shippingOption; | |
| 64 [self delayedNotifyDelegateOfSelection]; | |
| 65 } | |
| 66 | |
| 67 - (void)shippingOptionSelectionViewControllerDidReturn: | |
| 68 (ShippingOptionSelectionViewController*)controller { | |
| 69 [_delegate shippingOptionSelectionCoordinatorDidReturn:self]; | |
| 70 } | |
| 71 | |
| 72 - (void)delayedNotifyDelegateOfSelection { | |
| 73 _viewController.get().view.userInteractionEnabled = NO; | |
| 74 base::WeakNSObject<ShippingOptionSelectionCoordinator> weakSelf(self); | |
| 75 dispatch_after( | |
| 76 dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), | |
| 77 dispatch_get_main_queue(), ^{ | |
| 78 base::scoped_nsobject<ShippingOptionSelectionCoordinator> strongSelf( | |
| 79 [weakSelf retain]); | |
| 80 // Early return if the coordinator has been deallocated. | |
| 81 if (!strongSelf) | |
| 82 return; | |
| 83 | |
| 84 _viewController.get().view.userInteractionEnabled = YES; | |
|
Justin Donnelly
2017/01/10 17:11:53
Why re-enable interaction here? Wouldn't it be saf
lpromero
2017/01/11 12:51:15
Why not, good idea.
Justin Donnelly
2017/01/12 00:23:29
What about this comment?
Moe
2017/01/12 14:32:26
I copied this logic from bookmark_folder_view_cont
Justin Donnelly
2017/01/12 16:05:10
I'm having trouble parsing your last statement. Yo
| |
| 85 [_delegate shippingOptionSelectionCoordinator:self | |
| 86 selectedShippingOption:_selectedShippingOption]; | |
| 87 }); | |
| 88 } | |
| 89 | |
| 90 @end | |
| OLD | NEW |