Chromium Code Reviews| 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/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 10 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
| 11 #import "ios/chrome/browser/payments/cells/order_summary_line_item.h" | |
| 12 #import "ios/chrome/browser/payments/cells/order_summary_total_item.h" | |
| 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" | 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" |
| 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 16 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 15 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 16 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 18 #include "ios/chrome/browser/ui/rtl_geometry.h" | 17 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 19 #include "ios/chrome/grit/ios_strings.h" | 18 #include "ios/chrome/grit/ios_strings.h" |
| 20 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.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/Palettes/src/Mat erialPalettes.h" | |
| 21 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 NSString* const kPaymentItemsDisplayCollectionViewId = | 24 NSString* const kPaymentItemsDisplayCollectionViewId = |
| 24 @"kPaymentItemsDisplayCollectionViewId"; | 25 @"kPaymentItemsDisplayCollectionViewId"; |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const CGFloat kButtonEdgeInset = 9; | 29 const CGFloat kButtonEdgeInset = 9; |
| 29 const CGFloat kSeparatorEdgeInset = 14; | 30 const CGFloat kSeparatorEdgeInset = 14; |
| 30 | 31 |
| 31 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 32 SectionIdentifierPayment = kSectionIdentifierEnumZero, | 33 SectionIdentifierPayment = kSectionIdentifierEnumZero, |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 typedef NS_ENUM(NSInteger, ItemType) { | 36 typedef NS_ENUM(NSInteger, ItemType) { |
| 36 ItemTypePaymentItem = kItemTypeEnumZero, // This is a repeated item type. | 37 ItemTypePaymentItemTotal = kItemTypeEnumZero, |
| 38 ItemTypePaymentItem, // This is a repeated item type. | |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 } // namespace | 41 } // namespace |
| 40 | 42 |
| 41 @interface PaymentItemsDisplayViewController () { | 43 @interface PaymentItemsDisplayViewController () { |
| 42 base::WeakNSProtocol<id<PaymentItemsDisplayViewControllerDelegate>> _delegate; | 44 base::WeakNSProtocol<id<PaymentItemsDisplayViewControllerDelegate>> _delegate; |
| 43 base::scoped_nsobject<MDCFlatButton> _payButton; | 45 base::scoped_nsobject<MDCFlatButton> _payButton; |
| 44 } | 46 } |
| 45 | 47 |
| 46 // Called when the user presses the return button. | 48 // Called when the user presses the return button. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 - (void)loadModel { | 135 - (void)loadModel { |
| 134 [super loadModel]; | 136 [super loadModel]; |
| 135 CollectionViewModel* model = self.collectionViewModel; | 137 CollectionViewModel* model = self.collectionViewModel; |
| 136 [model addSectionWithIdentifier:SectionIdentifierPayment]; | 138 [model addSectionWithIdentifier:SectionIdentifierPayment]; |
| 137 | 139 |
| 138 NSNumberFormatter* currencyFormatter = | 140 NSNumberFormatter* currencyFormatter = |
| 139 [[[NSNumberFormatter alloc] init] autorelease]; | 141 [[[NSNumberFormatter alloc] init] autorelease]; |
| 140 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; | 142 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; |
| 141 | 143 |
| 142 // Add the total entry. | 144 // Add the total entry. |
| 143 OrderSummaryTotalItem* totalItem = [[[OrderSummaryTotalItem alloc] | 145 CollectionViewDetailItem* totalItem = [[[CollectionViewDetailItem alloc] |
| 144 initWithType:ItemTypePaymentItem] autorelease]; | 146 initWithType:ItemTypePaymentItemTotal] autorelease]; |
| 145 totalItem.text = base::SysUTF16ToNSString(_total.label); | 147 totalItem.text = base::SysUTF16ToNSString(_total.label); |
| 146 | 148 |
| 147 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); | 149 NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); |
| 148 NSDecimalNumber* value = [NSDecimalNumber | 150 NSDecimalNumber* value = [NSDecimalNumber |
| 149 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; | 151 decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; |
| 150 [currencyFormatter setCurrencyCode:currencyCode]; | 152 [currencyFormatter setCurrencyCode:currencyCode]; |
| 151 totalItem.detailText = [currencyFormatter stringFromNumber:value]; | 153 totalItem.detailText = [currencyFormatter stringFromNumber:value]; |
| 152 | 154 |
| 153 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 155 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; |
| 154 | 156 |
| 155 // Add the line item entries. | 157 // Add the line item entries. |
| 156 for (size_t i = 0; i < _paymentItems.size(); ++i) { | 158 for (size_t i = 0; i < _paymentItems.size(); ++i) { |
| 157 web::PaymentItem paymentItem = _paymentItems[i]; | 159 web::PaymentItem paymentItem = _paymentItems[i]; |
| 158 OrderSummaryLineItem* paymentItemItem = [[[OrderSummaryLineItem alloc] | 160 CollectionViewDetailItem* paymentItemItem = |
| 159 initWithType:ItemTypePaymentItem] autorelease]; | 161 [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] |
| 162 autorelease]; | |
| 160 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); | 163 paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); |
| 161 | 164 |
| 162 NSString* currencyCode = | 165 NSString* currencyCode = |
| 163 base::SysUTF16ToNSString(paymentItem.amount.currency); | 166 base::SysUTF16ToNSString(paymentItem.amount.currency); |
| 164 NSDecimalNumber* value = [NSDecimalNumber | 167 NSDecimalNumber* value = [NSDecimalNumber |
| 165 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; | 168 decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; |
| 166 [currencyFormatter setCurrencyCode:currencyCode]; | 169 [currencyFormatter setCurrencyCode:currencyCode]; |
| 167 paymentItemItem.detailText = [currencyFormatter stringFromNumber:value]; | 170 paymentItemItem.detailText = [currencyFormatter stringFromNumber:value]; |
| 168 | 171 |
| 169 [model addItem:paymentItemItem | 172 [model addItem:paymentItemItem |
| 170 toSectionWithIdentifier:SectionIdentifierPayment]; | 173 toSectionWithIdentifier:SectionIdentifierPayment]; |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 - (void)viewDidLoad { | 177 - (void)viewDidLoad { |
| 175 [super viewDidLoad]; | 178 [super viewDidLoad]; |
| 176 self.collectionView.accessibilityIdentifier = | 179 self.collectionView.accessibilityIdentifier = |
| 177 kPaymentItemsDisplayCollectionViewId; | 180 kPaymentItemsDisplayCollectionViewId; |
| 178 | 181 |
| 179 // Customize collection view settings. | 182 // Customize collection view settings. |
| 180 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 183 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 181 self.styler.separatorInset = | 184 self.styler.separatorInset = |
| 182 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 185 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 183 } | 186 } |
| 184 | 187 |
| 188 #pragma mark UICollectionViewDataSource | |
| 189 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
| 190 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | |
| 191 UICollectionViewCell* cell = | |
| 192 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | |
| 193 | |
| 194 NSInteger itemType = | |
| 195 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | |
| 196 switch (itemType) { | |
| 197 case ItemTypePaymentItemTotal: { | |
|
Justin Donnelly
2016/12/20 15:44:23
I see that this is being done elsewhere in the cod
Justin Donnelly
2016/12/20 16:46:38
Ah, I see. Thanks for the explanation.
| |
| 198 CollectionViewDetailCell* detailCell = | |
| 199 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell); | |
| 200 detailCell.textLabel.font = | |
| 201 [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:14]; | |
| 202 detailCell.textLabel.textColor = [[MDCPalette greyPalette] tint600]; | |
| 203 detailCell.detailTextLabel.font = | |
| 204 [[MDFRobotoFontLoader sharedInstance] boldFontOfSize:14]; | |
| 205 detailCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 206 break; | |
| 207 } | |
| 208 case ItemTypePaymentItem: { | |
| 209 CollectionViewDetailCell* detailCell = | |
| 210 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell); | |
| 211 detailCell.textLabel.font = | |
| 212 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; | |
| 213 detailCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 214 | |
| 215 detailCell.detailTextLabel.font = | |
| 216 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; | |
| 217 detailCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 218 break; | |
| 219 } | |
| 220 default: | |
| 221 break; | |
| 222 } | |
| 223 return cell; | |
| 224 } | |
| 225 | |
| 185 #pragma mark MDCCollectionViewStylingDelegate | 226 #pragma mark MDCCollectionViewStylingDelegate |
| 186 | 227 |
| 187 // There are no effects from touching the payment items so there should not be | 228 // There are no effects from touching the payment items so there should not be |
| 188 // an ink ripple. | 229 // an ink ripple. |
| 189 - (BOOL)collectionView:(UICollectionView*)collectionView | 230 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 190 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 231 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 191 return YES; | 232 return YES; |
| 192 } | 233 } |
| 193 | 234 |
| 194 @end | 235 @end |
| OLD | NEW |