| 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 #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/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 initWithType:ItemTypeShippingOption] autorelease]; | 94 initWithType:ItemTypeShippingOption] autorelease]; |
| 95 item.text = base::SysUTF16ToNSString(shippingOption->label); | 95 item.text = base::SysUTF16ToNSString(shippingOption->label); |
| 96 NSString* currencyCode = | 96 NSString* currencyCode = |
| 97 base::SysUTF16ToNSString(shippingOption->amount.currency); | 97 base::SysUTF16ToNSString(shippingOption->amount.currency); |
| 98 NSDecimalNumber* value = [NSDecimalNumber | 98 NSDecimalNumber* value = [NSDecimalNumber |
| 99 decimalNumberWithString:SysUTF16ToNSString( | 99 decimalNumberWithString:SysUTF16ToNSString( |
| 100 shippingOption->amount.value)]; | 100 shippingOption->amount.value)]; |
| 101 item.detailText = | 101 item.detailText = |
| 102 payment_request_utils::FormattedCurrencyString(value, currencyCode); | 102 payment_request_utils::FormattedCurrencyString(value, currencyCode); |
| 103 | 103 |
| 104 // Styling. |
| 105 item.textFont = [MDCTypography body2Font]; |
| 106 item.textColor = [[MDCPalette greyPalette] tint900]; |
| 107 item.detailTextFont = [MDCTypography body1Font]; |
| 108 item.detailTextColor = [[MDCPalette greyPalette] tint900]; |
| 109 |
| 104 if (_selectedShippingOption == shippingOption) { | 110 if (_selectedShippingOption == shippingOption) { |
| 105 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 111 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
| 106 _selectedItem = item; | 112 _selectedItem = item; |
| 107 } | 113 } |
| 108 | 114 |
| 109 [model addItem:item | 115 [model addItem:item |
| 110 toSectionWithIdentifier:SectionIdentifierShippingOption]; | 116 toSectionWithIdentifier:SectionIdentifierShippingOption]; |
| 111 } | 117 } |
| 112 } | 118 } |
| 113 | 119 |
| 114 - (void)viewDidLoad { | 120 - (void)viewDidLoad { |
| 115 [super viewDidLoad]; | 121 [super viewDidLoad]; |
| 116 self.collectionView.accessibilityIdentifier = | 122 self.collectionView.accessibilityIdentifier = |
| 117 kShippingOptionSelectionCollectionViewId; | 123 kShippingOptionSelectionCollectionViewId; |
| 118 | 124 |
| 119 // Customize collection view settings. | 125 // Customize collection view settings. |
| 120 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 126 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 121 self.styler.separatorInset = | 127 self.styler.separatorInset = |
| 122 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 128 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 123 } | 129 } |
| 124 | 130 |
| 125 #pragma mark UICollectionViewDataSource | |
| 126 | |
| 127 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
| 128 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | |
| 129 UICollectionViewCell* cell = | |
| 130 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | |
| 131 | |
| 132 NSInteger itemType = | |
| 133 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | |
| 134 DCHECK(ItemTypeShippingOption == itemType); | |
| 135 | |
| 136 MDCCollectionViewTextCell* textCell = | |
| 137 base::mac::ObjCCastStrict<MDCCollectionViewTextCell>(cell); | |
| 138 textCell.textLabel.font = [MDCTypography body2Font]; | |
| 139 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 140 textCell.detailTextLabel.font = [MDCTypography body1Font]; | |
| 141 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint900]; | |
| 142 | |
| 143 return cell; | |
| 144 } | |
| 145 | |
| 146 #pragma mark UICollectionViewDelegate | 131 #pragma mark UICollectionViewDelegate |
| 147 | 132 |
| 148 - (void)collectionView:(UICollectionView*)collectionView | 133 - (void)collectionView:(UICollectionView*)collectionView |
| 149 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 134 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 150 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 135 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 151 | 136 |
| 152 CollectionViewModel* model = self.collectionViewModel; | 137 CollectionViewModel* model = self.collectionViewModel; |
| 153 | 138 |
| 154 NSInteger itemType = | 139 NSInteger itemType = |
| 155 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 140 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 181 } | 166 } |
| 182 | 167 |
| 183 #pragma mark MDCCollectionViewStylingDelegate | 168 #pragma mark MDCCollectionViewStylingDelegate |
| 184 | 169 |
| 185 - (CGFloat)collectionView:(UICollectionView*)collectionView | 170 - (CGFloat)collectionView:(UICollectionView*)collectionView |
| 186 cellHeightAtIndexPath:(NSIndexPath*)indexPath { | 171 cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
| 187 return MDCCellDefaultTwoLineHeight; | 172 return MDCCellDefaultTwoLineHeight; |
| 188 } | 173 } |
| 189 | 174 |
| 190 @end | 175 @end |
| OLD | NEW |