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

Side by Side Diff: ios/chrome/browser/ui/payments/country_selection_coordinator.mm

Issue 2896623002: [Payment Request] Country selection coordinator (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/payments/country_selection_coordinator.h"
6
7 #include "base/strings/sys_string_conversions.h"
8 #import "ios/chrome/browser/ui/payments/payment_request_picker_row.h"
9 #include "ios/chrome/browser/ui/payments/payment_request_picker_view_controller. h"
10 #include "ios/chrome/grit/ios_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 namespace {
18 // The delay in nano seconds before notifying the delegate of the selection.
macourteau 2017/05/19 20:20:43 nit: please elaborate on why this delay is needed
Moe 2017/05/19 22:19:14 Done.
19 const int64_t kDelegateNotificationDelayInNanoSeconds = 0.2 * NSEC_PER_SEC;
20 } // namespace
21
22 @interface CountrySelectionCoordinator ()
23
24 @property(nonatomic, strong) PaymentRequestPickerViewController* viewController;
25
26 // Called when the user selects a country. The cell is checked, the UI is locked
27 // so that the user can't interact with it, then the delegate is notified. The
28 // delay is here to let the user get a visual feedback of the selection before
29 // this view disappears.
30 - (void)delayedNotifyDelegateOfSelection:(NSString*)countryCode;
31
32 @end
33
34 @implementation CountrySelectionCoordinator
35
36 @synthesize delegate = _delegate;
37 @synthesize countries = _countries;
38 @synthesize selectedCountryCode = _selectedCountryCode;
39 @synthesize viewController = _viewController;
40
41 - (void)start {
42 // Create the rows to display in the view controller.
43 NSMutableArray<PickerRow*>* rows = [[NSMutableArray alloc] init];
44 __block PickerRow* selectedRow = nil;
45 [self.countries
46 enumerateKeysAndObjectsUsingBlock:^(NSString* countryCode,
47 NSString* countryName, BOOL* stop) {
48 PickerRow* row =
49 [[PickerRow alloc] initWithLabel:countryName value:countryCode];
50 [rows addObject:row];
51 if (self.selectedCountryCode == countryCode)
52 selectedRow = row;
53 }];
54 self.viewController =
55 [[PaymentRequestPickerViewController alloc] initWithRows:rows
56 selected:selectedRow];
57 self.viewController.title = l10n_util::GetNSString(IDS_IOS_AUTOFILL_COUNTRY);
58 self.viewController.delegate = self;
59
60 DCHECK(self.baseViewController.navigationController);
61 [self.baseViewController.navigationController
62 pushViewController:self.viewController
63 animated:YES];
64 }
65
66 - (void)stop {
67 [self.viewController.navigationController popViewControllerAnimated:YES];
68 self.viewController = nil;
69 }
70
71 #pragma mark - PaymentRequestPickerViewControllerDelegate
72
73 - (void)paymentRequestPickerViewController:
74 (PaymentRequestPickerViewController*)controller
75 didSelectRow:(PickerRow*)row {
76 [self delayedNotifyDelegateOfSelection:row.value];
77 }
78
79 #pragma mark - Helper methods
80
81 - (void)delayedNotifyDelegateOfSelection:(NSString*)countryCode {
82 self.viewController.view.userInteractionEnabled = NO;
83 __weak CountrySelectionCoordinator* weakSelf = self;
84 dispatch_after(
85 dispatch_time(DISPATCH_TIME_NOW, kDelegateNotificationDelayInNanoSeconds),
86 dispatch_get_main_queue(), ^{
87 weakSelf.viewController.view.userInteractionEnabled = YES;
88 [weakSelf.delegate countrySelectionCoordinator:weakSelf
89 didSelectCountryWithCode:countryCode];
90 });
91 }
92
93 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698