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 #import "ios/chrome/browser/payments/payment_request_utils.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_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 21 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 | 23 |
24 NSString* const kPaymentItemsDisplayCollectionViewId = | 24 NSString* const kPaymentItemsDisplayCollectionViewId = |
25 @"kPaymentItemsDisplayCollectionViewId"; | 25 @"kPaymentItemsDisplayCollectionViewId"; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 const CGFloat kButtonEdgeInset = 9; | 29 const CGFloat kButtonEdgeInset = 9; |
30 const CGFloat kSeparatorEdgeInset = 14; | 30 const CGFloat kSeparatorEdgeInset = 14; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 [_delegate paymentItemsDisplayViewControllerDidConfirm:self]; | 130 [_delegate paymentItemsDisplayViewControllerDidConfirm:self]; |
131 } | 131 } |
132 | 132 |
133 #pragma mark - CollectionViewController methods | 133 #pragma mark - CollectionViewController methods |
134 | 134 |
135 - (void)loadModel { | 135 - (void)loadModel { |
136 [super loadModel]; | 136 [super loadModel]; |
137 CollectionViewModel* model = self.collectionViewModel; | 137 CollectionViewModel* model = self.collectionViewModel; |
138 [model addSectionWithIdentifier:SectionIdentifierPayment]; | 138 [model addSectionWithIdentifier:SectionIdentifierPayment]; |
139 | 139 |
140 NSNumberFormatter* currencyFormatter = | |
141 [[[NSNumberFormatter alloc] init] autorelease]; | |
142 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; | |
143 | |
144 // Add the total entry. | 140 // Add the total entry. |
145 CollectionViewDetailItem* totalItem = [[[CollectionViewDetailItem alloc] | 141 CollectionViewDetailItem* totalItem = [[[CollectionViewDetailItem alloc] |
146 initWithType:ItemTypePaymentItemTotal] autorelease]; | 142 initWithType:ItemTypePaymentItemTotal] autorelease]; |
147 totalItem.text = base::SysUTF16ToNSString(_total.label); | 143 totalItem.text = base::SysUTF16ToNSString(_total.label); |
148 | 144 |
149 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); | 145 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); |
150 NSDecimalNumber* value = [NSDecimalNumber | 146 NSDecimalNumber* value = [NSDecimalNumber |
151 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; | 147 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; |
152 [currencyFormatter setCurrencyCode:currencyCode]; | 148 totalItem.detailText = |
153 totalItem.detailText = [currencyFormatter stringFromNumber:value]; | 149 payment_request_utils::FormattedCurrencyString(value, currencyCode); |
154 | 150 |
155 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 151 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; |
156 | 152 |
157 // Add the line item entries. | 153 // Add the line item entries. |
158 for (size_t i = 0; i < _paymentItems.size(); ++i) { | 154 for (size_t i = 0; i < _paymentItems.size(); ++i) { |
159 web::PaymentItem paymentItem = _paymentItems[i]; | 155 web::PaymentItem paymentItem = _paymentItems[i]; |
160 CollectionViewDetailItem* paymentItemItem = | 156 CollectionViewDetailItem* paymentItemItem = |
161 [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] | 157 [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] |
162 autorelease]; | 158 autorelease]; |
163 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); | 159 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); |
164 | 160 |
165 NSString* currencyCode = | 161 NSString* currencyCode = |
166 base::SysUTF16ToNSString(paymentItem.amount.currency); | 162 base::SysUTF16ToNSString(paymentItem.amount.currency); |
167 NSDecimalNumber* value = [NSDecimalNumber | 163 NSDecimalNumber* value = [NSDecimalNumber |
168 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; | 164 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; |
169 [currencyFormatter setCurrencyCode:currencyCode]; | 165 paymentItemItem.detailText = |
170 paymentItemItem.detailText = [currencyFormatter stringFromNumber:value]; | 166 payment_request_utils::FormattedCurrencyString(value, currencyCode); |
171 | |
172 [model addItem:paymentItemItem | 167 [model addItem:paymentItemItem |
173 toSectionWithIdentifier:SectionIdentifierPayment]; | 168 toSectionWithIdentifier:SectionIdentifierPayment]; |
174 } | 169 } |
175 } | 170 } |
176 | 171 |
177 - (void)viewDidLoad { | 172 - (void)viewDidLoad { |
178 [super viewDidLoad]; | 173 [super viewDidLoad]; |
179 self.collectionView.accessibilityIdentifier = | 174 self.collectionView.accessibilityIdentifier = |
180 kPaymentItemsDisplayCollectionViewId; | 175 kPaymentItemsDisplayCollectionViewId; |
181 | 176 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 #pragma mark MDCCollectionViewStylingDelegate | 221 #pragma mark MDCCollectionViewStylingDelegate |
227 | 222 |
228 // There are no effects from touching the payment items so there should not be | 223 // There are no effects from touching the payment items so there should not be |
229 // an ink ripple. | 224 // an ink ripple. |
230 - (BOOL)collectionView:(UICollectionView*)collectionView | 225 - (BOOL)collectionView:(UICollectionView*)collectionView |
231 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 226 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
232 return YES; | 227 return YES; |
233 } | 228 } |
234 | 229 |
235 @end | 230 @end |
OLD | NEW |