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_view_controller.h
" | 5 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h
" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/payments/currency_formatter.h" | 10 #include "components/payments/currency_formatter.h" |
11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
13 #include "ios/chrome/browser/payments/payment_request.h" | 13 #include "ios/chrome/browser/payments/payment_request.h" |
14 #import "ios/chrome/browser/payments/payment_request_util.h" | 14 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 15 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller_a
ctions.h" |
15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 16 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
16 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 17 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 21 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
21 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 22 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
22 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 23 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
23 #include "ios/chrome/grit/ios_strings.h" | 24 #include "ios/chrome/grit/ios_strings.h" |
24 #include "ios/chrome/grit/ios_theme_resources.h" | 25 #include "ios/chrome/grit/ios_theme_resources.h" |
25 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 26 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
27 | 28 |
28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 29 #if !defined(__has_feature) || !__has_feature(objc_arc) |
29 #error "This file requires ARC support." | 30 #error "This file requires ARC support." |
30 #endif | 31 #endif |
31 | 32 |
32 NSString* const kShippingOptionSelectionCollectionViewId = | 33 NSString* const kShippingOptionSelectionCollectionViewID = |
33 @"kShippingOptionSelectionCollectionViewId"; | 34 @"kShippingOptionSelectionCollectionViewID"; |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 const CGFloat kSeparatorEdgeInset = 14; | 38 const CGFloat kSeparatorEdgeInset = 14; |
38 | 39 |
39 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 40 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
40 SectionIdentifierShippingOption = kSectionIdentifierEnumZero, | 41 SectionIdentifierShippingOption = kSectionIdentifierEnumZero, |
41 }; | 42 }; |
42 | 43 |
43 typedef NS_ENUM(NSInteger, ItemType) { | 44 typedef NS_ENUM(NSInteger, ItemType) { |
44 ItemTypeSpinner = kItemTypeEnumZero, | 45 ItemTypeSpinner = kItemTypeEnumZero, |
45 ItemTypeMessage, | 46 ItemTypeMessage, |
46 ItemTypeShippingOption, // This is a repeated item type. | 47 ItemTypeShippingOption, // This is a repeated item type. |
47 }; | 48 }; |
48 | 49 |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 @interface ShippingOptionSelectionViewController () { | 52 @interface ShippingOptionSelectionViewController ()< |
52 __weak id<ShippingOptionSelectionViewControllerDelegate> _delegate; | 53 ShippingOptionSelectionViewControllerActions> { |
53 | |
54 // The PaymentRequest object owning an instance of web::PaymentRequest as | 54 // The PaymentRequest object owning an instance of web::PaymentRequest as |
55 // provided by the page invoking the Payment Request API. This is a weak | 55 // provided by the page invoking the Payment Request API. This is a weak |
56 // pointer and should outlive this class. | 56 // pointer and should outlive this class. |
57 PaymentRequest* _paymentRequest; | 57 PaymentRequest* _paymentRequest; |
58 | 58 |
59 // The currently selected item. May be nil. | 59 // The currently selected item. May be nil. |
60 CollectionViewTextItem* _selectedItem; | 60 CollectionViewTextItem* _selectedItem; |
61 } | 61 } |
62 | 62 |
63 // Called when the user presses the return button. | |
64 - (void)onReturn; | |
65 | |
66 @end | 63 @end |
67 | 64 |
68 @implementation ShippingOptionSelectionViewController | 65 @implementation ShippingOptionSelectionViewController |
69 | 66 |
70 @synthesize pending = _pending; | 67 @synthesize pending = _pending; |
71 @synthesize errorMessage = _errorMessage; | 68 @synthesize errorMessage = _errorMessage; |
| 69 @synthesize delegate = _delegate; |
72 | 70 |
73 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 71 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
74 DCHECK(paymentRequest); | 72 DCHECK(paymentRequest); |
75 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 73 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
76 self.title = | 74 self.title = |
77 payment_request_util::GetShippingOptionSelectorTitle(paymentRequest); | 75 payment_request_util::GetShippingOptionSelectorTitle(paymentRequest); |
78 | 76 |
| 77 // Set up leading (return) button. |
79 UIBarButtonItem* returnButton = | 78 UIBarButtonItem* returnButton = |
80 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 79 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
81 target:nil | 80 target:nil |
82 action:@selector(onReturn)]; | 81 action:@selector(onReturn)]; |
83 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); | 82 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); |
84 self.navigationItem.leftBarButtonItem = returnButton; | 83 self.navigationItem.leftBarButtonItem = returnButton; |
85 | 84 |
86 _paymentRequest = paymentRequest; | 85 _paymentRequest = paymentRequest; |
87 } | 86 } |
88 return self; | 87 return self; |
89 } | 88 } |
90 | 89 |
91 - (id<ShippingOptionSelectionViewControllerDelegate>)delegate { | |
92 return _delegate; | |
93 } | |
94 | |
95 - (void)setDelegate: | |
96 (id<ShippingOptionSelectionViewControllerDelegate>)delegate { | |
97 _delegate = delegate; | |
98 } | |
99 | |
100 - (void)onReturn { | 90 - (void)onReturn { |
101 [_delegate shippingOptionSelectionViewControllerDidReturn:self]; | 91 [_delegate shippingOptionSelectionViewControllerDidReturn:self]; |
102 } | 92 } |
103 | 93 |
104 #pragma mark - CollectionViewController methods | 94 #pragma mark - CollectionViewController methods |
105 | 95 |
106 - (void)loadModel { | 96 - (void)loadModel { |
107 [super loadModel]; | 97 [super loadModel]; |
108 CollectionViewModel* model = self.collectionViewModel; | 98 CollectionViewModel* model = self.collectionViewModel; |
109 _selectedItem = nil; | 99 _selectedItem = nil; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 139 } |
150 | 140 |
151 [model addItem:item | 141 [model addItem:item |
152 toSectionWithIdentifier:SectionIdentifierShippingOption]; | 142 toSectionWithIdentifier:SectionIdentifierShippingOption]; |
153 } | 143 } |
154 } | 144 } |
155 | 145 |
156 - (void)viewDidLoad { | 146 - (void)viewDidLoad { |
157 [super viewDidLoad]; | 147 [super viewDidLoad]; |
158 self.collectionView.accessibilityIdentifier = | 148 self.collectionView.accessibilityIdentifier = |
159 kShippingOptionSelectionCollectionViewId; | 149 kShippingOptionSelectionCollectionViewID; |
160 | 150 |
161 // Customize collection view settings. | 151 // Customize collection view settings. |
162 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 152 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
163 self.styler.separatorInset = | 153 self.styler.separatorInset = |
164 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 154 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
165 } | 155 } |
166 | 156 |
167 #pragma mark UICollectionViewDataSource | 157 #pragma mark UICollectionViewDataSource |
168 | 158 |
169 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 159 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 237 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
248 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 238 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
249 if (type == ItemTypeMessage) { | 239 if (type == ItemTypeMessage) { |
250 return YES; | 240 return YES; |
251 } else { | 241 } else { |
252 return NO; | 242 return NO; |
253 } | 243 } |
254 } | 244 } |
255 | 245 |
256 @end | 246 @end |
OLD | NEW |