Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: ios/chrome/browser/payments/shipping_option_selection_coordinator.mm

Issue 2621453002: Selected shipping option in payment summary view + shipping option selection view (Closed)
Patch Set: Addressed comments by lpromero@ and jdonnelley@ Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/payments/shipping_option_selection_coordinator.mm
diff --git a/ios/chrome/browser/payments/shipping_option_selection_coordinator.mm b/ios/chrome/browser/payments/shipping_option_selection_coordinator.mm
new file mode 100644
index 0000000000000000000000000000000000000000..65ec7fbca89072db51aea8e9197985f6f8b0f7fc
--- /dev/null
+++ b/ios/chrome/browser/payments/shipping_option_selection_coordinator.mm
@@ -0,0 +1,90 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/payments/shipping_option_selection_coordinator.h"
+
+#import "base/ios/weak_nsobject.h"
+#include "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h"
+
+@interface ShippingOptionSelectionCoordinator ()<
+ ShippingOptionSelectionViewControllerDelegate> {
+ base::WeakNSProtocol<id<ShippingOptionSelectionCoordinatorDelegate>>
+ _delegate;
+ base::scoped_nsobject<ShippingOptionSelectionViewController> _viewController;
+}
+
+// Called when the user selects a shipping option. 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
+// selection before this view disappears.
+- (void)delayedNotifyDelegateOfSelection;
+
+@end
+
+@implementation ShippingOptionSelectionCoordinator
+
+@synthesize shippingOptions = _shippingOptions;
+@synthesize selectedShippingOption = _selectedShippingOption;
+
+- (id<ShippingOptionSelectionCoordinatorDelegate>)delegate {
+ return _delegate.get();
+}
+
+- (void)setDelegate:(id<ShippingOptionSelectionCoordinatorDelegate>)delegate {
+ _delegate.reset(delegate);
+}
+
+- (void)start {
+ _viewController.reset([[ShippingOptionSelectionViewController alloc] init]);
+ [_viewController setShippingOptions:_shippingOptions];
+ [_viewController setSelectedShippingOption:_selectedShippingOption];
+ [_viewController setDelegate:self];
+ [_viewController loadModel];
+
+ DCHECK(self.baseViewController.navigationController);
+ [self.baseViewController.navigationController
+ pushViewController:_viewController
+ animated:YES];
+}
+
+- (void)stop {
+ [self.baseViewController.navigationController popViewControllerAnimated:YES];
+ _viewController.reset();
+}
+
+#pragma mark - ShippingOptionSelectionViewControllerDelegate
+
+- (void)shippingOptionSelectionViewController:
+ (ShippingOptionSelectionViewController*)controller
+ selectedShippingOption:
+ (web::PaymentShippingOption*)shippingOption {
+ _selectedShippingOption = shippingOption;
+ [self delayedNotifyDelegateOfSelection];
+}
+
+- (void)shippingOptionSelectionViewControllerDidReturn:
+ (ShippingOptionSelectionViewController*)controller {
+ [_delegate shippingOptionSelectionCoordinatorDidReturn:self];
+}
+
+- (void)delayedNotifyDelegateOfSelection {
+ _viewController.get().view.userInteractionEnabled = NO;
+ base::WeakNSObject<ShippingOptionSelectionCoordinator> weakSelf(self);
+ dispatch_after(
+ dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)),
+ dispatch_get_main_queue(), ^{
+ base::scoped_nsobject<ShippingOptionSelectionCoordinator> strongSelf(
+ [weakSelf retain]);
+ // Early return if the coordinator has been deallocated.
+ if (!strongSelf)
+ return;
+
+ _viewController.get().view.userInteractionEnabled = YES;
+ [_delegate shippingOptionSelectionCoordinator:self
+ selectedShippingOption:_selectedShippingOption];
+ });
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698