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/payment_items_display_view_controller.h" | 5 #import "ios/chrome/browser/payments/payment_items_display_view_controller.h" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
| 12 #include "components/strings/grit/components_strings.h" |
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
15 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 16 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
16 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
17 #include "ios/chrome/browser/ui/rtl_geometry.h" | 18 #include "ios/chrome/browser/ui/rtl_geometry.h" |
18 #include "ios/chrome/grit/ios_strings.h" | 19 #include "ios/chrome/grit/ios_strings.h" |
19 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 20 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
20 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 21 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
21 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 22 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 NSString* const kPaymentItemsDisplayCollectionViewId = | 25 NSString* const kPaymentItemsDisplayCollectionViewId = |
25 @"kPaymentItemsDisplayCollectionViewId"; | 26 @"kPaymentItemsDisplayCollectionViewId"; |
| 27 NSString* const kPaymentItemsDisplayItemId = @"kPaymentItemsDisplayItemId"; |
26 | 28 |
27 namespace { | 29 namespace { |
28 | 30 |
29 const CGFloat kButtonEdgeInset = 9; | 31 const CGFloat kButtonEdgeInset = 9; |
30 const CGFloat kSeparatorEdgeInset = 14; | 32 const CGFloat kSeparatorEdgeInset = 14; |
31 | 33 |
32 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
33 SectionIdentifierPayment = kSectionIdentifierEnumZero, | 35 SectionIdentifierPayment = kSectionIdentifierEnumZero, |
34 }; | 36 }; |
35 | 37 |
(...skipping 25 matching lines...) Expand all Loading... |
61 - (instancetype)initWithPayButtonEnabled:(BOOL)payButtonEnabled { | 63 - (instancetype)initWithPayButtonEnabled:(BOOL)payButtonEnabled { |
62 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 64 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
63 [self setTitle:l10n_util::GetNSString( | 65 [self setTitle:l10n_util::GetNSString( |
64 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; | 66 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; |
65 | 67 |
66 // Set up left (return) button. | 68 // Set up left (return) button. |
67 UIBarButtonItem* returnButton = | 69 UIBarButtonItem* returnButton = |
68 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 70 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
69 target:nil | 71 target:nil |
70 action:@selector(onReturn)]; | 72 action:@selector(onReturn)]; |
| 73 [returnButton |
| 74 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)]; |
71 [self navigationItem].leftBarButtonItem = returnButton; | 75 [self navigationItem].leftBarButtonItem = returnButton; |
72 | 76 |
73 // Set up right (pay) button. | 77 // Set up right (pay) button. |
74 _payButton.reset([[MDCFlatButton alloc] init]); | 78 _payButton.reset([[MDCFlatButton alloc] init]); |
75 [_payButton | 79 [_payButton |
76 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 80 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) |
77 forState:UIControlStateNormal]; | 81 forState:UIControlStateNormal]; |
78 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 82 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
79 forState:UIControlStateNormal]; | 83 forState:UIControlStateNormal]; |
80 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 84 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 CollectionViewModel* model = self.collectionViewModel; | 141 CollectionViewModel* model = self.collectionViewModel; |
138 [model addSectionWithIdentifier:SectionIdentifierPayment]; | 142 [model addSectionWithIdentifier:SectionIdentifierPayment]; |
139 | 143 |
140 NSNumberFormatter* currencyFormatter = | 144 NSNumberFormatter* currencyFormatter = |
141 [[[NSNumberFormatter alloc] init] autorelease]; | 145 [[[NSNumberFormatter alloc] init] autorelease]; |
142 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; | 146 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; |
143 | 147 |
144 // Add the total entry. | 148 // Add the total entry. |
145 CollectionViewDetailItem* totalItem = [[[CollectionViewDetailItem alloc] | 149 CollectionViewDetailItem* totalItem = [[[CollectionViewDetailItem alloc] |
146 initWithType:ItemTypePaymentItemTotal] autorelease]; | 150 initWithType:ItemTypePaymentItemTotal] autorelease]; |
| 151 totalItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; |
147 totalItem.text = base::SysUTF16ToNSString(_total.label); | 152 totalItem.text = base::SysUTF16ToNSString(_total.label); |
148 | 153 |
149 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); | 154 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); |
150 NSDecimalNumber* value = [NSDecimalNumber | 155 NSDecimalNumber* value = [NSDecimalNumber |
151 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; | 156 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; |
152 [currencyFormatter setCurrencyCode:currencyCode]; | 157 [currencyFormatter setCurrencyCode:currencyCode]; |
153 totalItem.detailText = [currencyFormatter stringFromNumber:value]; | 158 totalItem.detailText = [currencyFormatter stringFromNumber:value]; |
154 | 159 |
155 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 160 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; |
156 | 161 |
157 // Add the line item entries. | 162 // Add the line item entries. |
158 for (size_t i = 0; i < _paymentItems.size(); ++i) { | 163 for (size_t i = 0; i < _paymentItems.size(); ++i) { |
159 web::PaymentItem paymentItem = _paymentItems[i]; | 164 web::PaymentItem paymentItem = _paymentItems[i]; |
160 CollectionViewDetailItem* paymentItemItem = | 165 CollectionViewDetailItem* paymentItemItem = |
161 [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] | 166 [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] |
162 autorelease]; | 167 autorelease]; |
| 168 paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; |
163 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); | 169 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); |
164 | 170 |
165 NSString* currencyCode = | 171 NSString* currencyCode = |
166 base::SysUTF16ToNSString(paymentItem.amount.currency); | 172 base::SysUTF16ToNSString(paymentItem.amount.currency); |
167 NSDecimalNumber* value = [NSDecimalNumber | 173 NSDecimalNumber* value = [NSDecimalNumber |
168 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; | 174 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; |
169 [currencyFormatter setCurrencyCode:currencyCode]; | 175 [currencyFormatter setCurrencyCode:currencyCode]; |
170 paymentItemItem.detailText = [currencyFormatter stringFromNumber:value]; | 176 paymentItemItem.detailText = [currencyFormatter stringFromNumber:value]; |
171 | 177 |
172 [model addItem:paymentItemItem | 178 [model addItem:paymentItemItem |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 #pragma mark MDCCollectionViewStylingDelegate | 232 #pragma mark MDCCollectionViewStylingDelegate |
227 | 233 |
228 // There are no effects from touching the payment items so there should not be | 234 // There are no effects from touching the payment items so there should not be |
229 // an ink ripple. | 235 // an ink ripple. |
230 - (BOOL)collectionView:(UICollectionView*)collectionView | 236 - (BOOL)collectionView:(UICollectionView*)collectionView |
231 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 237 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
232 return YES; | 238 return YES; |
233 } | 239 } |
234 | 240 |
235 @end | 241 @end |
OLD | NEW |