| 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" |  | 
| 13 #import "ios/chrome/browser/payments/payment_request_utils.h" | 12 #import "ios/chrome/browser/payments/payment_request_utils.h" | 
| 14 #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" | 
| 15 #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" | 
| 16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 
| 17 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 16 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 
| 18 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 
| 19 #include "ios/chrome/browser/ui/rtl_geometry.h" | 18 #include "ios/chrome/browser/ui/rtl_geometry.h" | 
| 20 #include "ios/chrome/grit/ios_strings.h" | 19 #include "ios/chrome/grit/ios_strings.h" | 
| 21 #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" | 
| 22 #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" | 
| 23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" | 
| 24 | 23 | 
| 25 NSString* const kPaymentItemsDisplayCollectionViewId = | 24 NSString* const kPaymentItemsDisplayCollectionViewId = | 
| 26     @"kPaymentItemsDisplayCollectionViewId"; | 25     @"kPaymentItemsDisplayCollectionViewId"; | 
| 27 NSString* const kPaymentItemsDisplayItemId = @"kPaymentItemsDisplayItemId"; |  | 
| 28 | 26 | 
| 29 namespace { | 27 namespace { | 
| 30 | 28 | 
| 31 const CGFloat kButtonEdgeInset = 9; | 29 const CGFloat kButtonEdgeInset = 9; | 
| 32 const CGFloat kSeparatorEdgeInset = 14; | 30 const CGFloat kSeparatorEdgeInset = 14; | 
| 33 | 31 | 
| 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 32 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 
| 35   SectionIdentifierPayment = kSectionIdentifierEnumZero, | 33   SectionIdentifierPayment = kSectionIdentifierEnumZero, | 
| 36 }; | 34 }; | 
| 37 | 35 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 63 - (instancetype)initWithPayButtonEnabled:(BOOL)payButtonEnabled { | 61 - (instancetype)initWithPayButtonEnabled:(BOOL)payButtonEnabled { | 
| 64   if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 62   if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 
| 65     [self setTitle:l10n_util::GetNSString( | 63     [self setTitle:l10n_util::GetNSString( | 
| 66                        IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; | 64                        IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; | 
| 67 | 65 | 
| 68     // Set up left (return) button. | 66     // Set up left (return) button. | 
| 69     UIBarButtonItem* returnButton = | 67     UIBarButtonItem* returnButton = | 
| 70         [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 68         [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 
| 71                                             target:nil | 69                                             target:nil | 
| 72                                             action:@selector(onReturn)]; | 70                                             action:@selector(onReturn)]; | 
| 73     [returnButton |  | 
| 74         setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)]; |  | 
| 75     [self navigationItem].leftBarButtonItem = returnButton; | 71     [self navigationItem].leftBarButtonItem = returnButton; | 
| 76 | 72 | 
| 77     // Set up right (pay) button. | 73     // Set up right (pay) button. | 
| 78     _payButton.reset([[MDCFlatButton alloc] init]); | 74     _payButton.reset([[MDCFlatButton alloc] init]); | 
| 79     [_payButton | 75     [_payButton | 
| 80         setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 76         setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 
| 81         forState:UIControlStateNormal]; | 77         forState:UIControlStateNormal]; | 
| 82     [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 78     [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 
| 83                           forState:UIControlStateNormal]; | 79                           forState:UIControlStateNormal]; | 
| 84     [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 80     [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 137 #pragma mark - CollectionViewController methods | 133 #pragma mark - CollectionViewController methods | 
| 138 | 134 | 
| 139 - (void)loadModel { | 135 - (void)loadModel { | 
| 140   [super loadModel]; | 136   [super loadModel]; | 
| 141   CollectionViewModel* model = self.collectionViewModel; | 137   CollectionViewModel* model = self.collectionViewModel; | 
| 142   [model addSectionWithIdentifier:SectionIdentifierPayment]; | 138   [model addSectionWithIdentifier:SectionIdentifierPayment]; | 
| 143 | 139 | 
| 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.accessibilityIdentifier = kPaymentItemsDisplayItemId; |  | 
| 148   totalItem.text = base::SysUTF16ToNSString(_total.label); | 143   totalItem.text = base::SysUTF16ToNSString(_total.label); | 
| 149 | 144 | 
| 150   NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); | 145   NSString* currencyCode = base::SysUTF16ToNSString(_total.amount.currency); | 
| 151   NSDecimalNumber* value = [NSDecimalNumber | 146   NSDecimalNumber* value = [NSDecimalNumber | 
| 152       decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; | 147       decimalNumberWithString:SysUTF16ToNSString(_total.amount.value)]; | 
| 153   totalItem.detailText = | 148   totalItem.detailText = | 
| 154       payment_request_utils::FormattedCurrencyString(value, currencyCode); | 149       payment_request_utils::FormattedCurrencyString(value, currencyCode); | 
| 155 | 150 | 
| 156   [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 151   [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 
| 157 | 152 | 
| 158   // Add the line item entries. | 153   // Add the line item entries. | 
| 159   for (size_t i = 0; i < _paymentItems.size(); ++i) { | 154   for (size_t i = 0; i < _paymentItems.size(); ++i) { | 
| 160     web::PaymentItem paymentItem = _paymentItems[i]; | 155     web::PaymentItem paymentItem = _paymentItems[i]; | 
| 161     CollectionViewDetailItem* paymentItemItem = | 156     CollectionViewDetailItem* paymentItemItem = | 
| 162         [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] | 157         [[[CollectionViewDetailItem alloc] initWithType:ItemTypePaymentItem] | 
| 163             autorelease]; | 158             autorelease]; | 
| 164     paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; |  | 
| 165     paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); | 159     paymentItemItem.text = base::SysUTF16ToNSString(paymentItem.label); | 
| 166 | 160 | 
| 167     NSString* currencyCode = | 161     NSString* currencyCode = | 
| 168         base::SysUTF16ToNSString(paymentItem.amount.currency); | 162         base::SysUTF16ToNSString(paymentItem.amount.currency); | 
| 169     NSDecimalNumber* value = [NSDecimalNumber | 163     NSDecimalNumber* value = [NSDecimalNumber | 
| 170         decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; | 164         decimalNumberWithString:SysUTF16ToNSString(paymentItem.amount.value)]; | 
| 171     paymentItemItem.detailText = | 165     paymentItemItem.detailText = | 
| 172         payment_request_utils::FormattedCurrencyString(value, currencyCode); | 166         payment_request_utils::FormattedCurrencyString(value, currencyCode); | 
| 173     [model addItem:paymentItemItem | 167     [model addItem:paymentItemItem | 
| 174         toSectionWithIdentifier:SectionIdentifierPayment]; | 168         toSectionWithIdentifier:SectionIdentifierPayment]; | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 227 #pragma mark MDCCollectionViewStylingDelegate | 221 #pragma mark MDCCollectionViewStylingDelegate | 
| 228 | 222 | 
| 229 // 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 | 
| 230 // an ink ripple. | 224 // an ink ripple. | 
| 231 - (BOOL)collectionView:(UICollectionView*)collectionView | 225 - (BOOL)collectionView:(UICollectionView*)collectionView | 
| 232     hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 226     hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 
| 233   return YES; | 227   return YES; | 
| 234 } | 228 } | 
| 235 | 229 | 
| 236 @end | 230 @end | 
| OLD | NEW | 
|---|