| 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 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
| 11 #include "components/payments/currency_formatter.h" | 11 #include "components/payments/currency_formatter.h" |
| 12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
| 13 #import "ios/chrome/browser/payments/cells/price_item.h" | 13 #import "ios/chrome/browser/payments/cells/price_item.h" |
| 14 #import "ios/chrome/browser/payments/payment_items_display_view_controller_actio
ns.h" |
| 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 16 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 17 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 18 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 18 #include "ios/chrome/browser/ui/rtl_geometry.h" | 19 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 19 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 20 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 21 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 NSString* const kPaymentItemsDisplayCollectionViewId = | 29 NSString* const kPaymentItemsDisplayCollectionViewID = |
| 29 @"kPaymentItemsDisplayCollectionViewId"; | 30 @"kPaymentItemsDisplayCollectionViewID"; |
| 30 NSString* const kPaymentItemsDisplayItemId = @"kPaymentItemsDisplayItemId"; | 31 NSString* const kPaymentItemsDisplayItemID = @"kPaymentItemsDisplayItemID"; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 const CGFloat kButtonEdgeInset = 9; | 35 const CGFloat kButtonEdgeInset = 9; |
| 35 const CGFloat kSeparatorEdgeInset = 14; | 36 const CGFloat kSeparatorEdgeInset = 14; |
| 36 | 37 |
| 37 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 38 SectionIdentifierPayment = kSectionIdentifierEnumZero, | 39 SectionIdentifierPayment = kSectionIdentifierEnumZero, |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 typedef NS_ENUM(NSInteger, ItemType) { | 42 typedef NS_ENUM(NSInteger, ItemType) { |
| 42 ItemTypePaymentItemTotal = kItemTypeEnumZero, | 43 ItemTypePaymentItemTotal = kItemTypeEnumZero, |
| 43 ItemTypePaymentItem, // This is a repeated item type. | 44 ItemTypePaymentItem, // This is a repeated item type. |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 } // namespace | 47 } // namespace |
| 47 | 48 |
| 48 @interface PaymentItemsDisplayViewController () { | 49 @interface PaymentItemsDisplayViewController ()< |
| 50 PaymentItemsDisplayViewControllerActions> { |
| 49 MDCFlatButton* _payButton; | 51 MDCFlatButton* _payButton; |
| 50 | 52 |
| 51 // The PaymentRequest object owning an instance of web::PaymentRequest as | 53 // The PaymentRequest object owning an instance of web::PaymentRequest as |
| 52 // provided by the page invoking the Payment Request API. This is a weak | 54 // provided by the page invoking the Payment Request API. This is a weak |
| 53 // pointer and should outlive this class. | 55 // pointer and should outlive this class. |
| 54 PaymentRequest* _paymentRequest; | 56 PaymentRequest* _paymentRequest; |
| 55 } | 57 } |
| 56 | 58 |
| 57 // Called when the user presses the return button. | |
| 58 - (void)onReturn; | |
| 59 | |
| 60 // Called when the user presses the pay button. | |
| 61 - (void)onConfirm; | |
| 62 | |
| 63 @end | 59 @end |
| 64 | 60 |
| 65 @implementation PaymentItemsDisplayViewController | 61 @implementation PaymentItemsDisplayViewController |
| 66 @synthesize delegate = _delegate; | 62 @synthesize delegate = _delegate; |
| 67 | 63 |
| 68 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest | 64 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest |
| 69 payButtonEnabled:(BOOL)payButtonEnabled { | 65 payButtonEnabled:(BOOL)payButtonEnabled { |
| 70 DCHECK(paymentRequest); | 66 DCHECK(paymentRequest); |
| 71 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 67 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
| 72 [self setTitle:l10n_util::GetNSString( | 68 [self setTitle:l10n_util::GetNSString( |
| 73 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; | 69 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; |
| 74 | 70 |
| 75 // Set up left (return) button. | 71 // Set up leading (return) button. |
| 76 UIBarButtonItem* returnButton = | 72 UIBarButtonItem* returnButton = |
| 77 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 73 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
| 78 target:nil | 74 target:nil |
| 79 action:@selector(onReturn)]; | 75 action:@selector(onReturn)]; |
| 80 [returnButton | 76 [returnButton |
| 81 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)]; | 77 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)]; |
| 82 [self navigationItem].leftBarButtonItem = returnButton; | 78 [self navigationItem].leftBarButtonItem = returnButton; |
| 83 | 79 |
| 84 // Set up right (pay) button. | 80 // Set up trailing (pay) button. |
| 85 _payButton = [[MDCFlatButton alloc] init]; | 81 _payButton = [[MDCFlatButton alloc] init]; |
| 86 [_payButton | 82 [_payButton |
| 87 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) | 83 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) |
| 88 forState:UIControlStateNormal]; | 84 forState:UIControlStateNormal]; |
| 89 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 85 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
| 90 forState:UIControlStateNormal]; | 86 forState:UIControlStateNormal]; |
| 91 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; | 87 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; |
| 92 [_payButton setBackgroundColor:[UIColor grayColor] | 88 [_payButton setBackgroundColor:[UIColor grayColor] |
| 93 forState:UIControlStateDisabled]; | 89 forState:UIControlStateDisabled]; |
| 94 [_payButton addTarget:nil | 90 [_payButton addTarget:nil |
| (...skipping 42 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 PriceItem* totalItem = | 141 PriceItem* totalItem = |
| 146 [[PriceItem alloc] initWithType:ItemTypePaymentItemTotal]; | 142 [[PriceItem alloc] initWithType:ItemTypePaymentItemTotal]; |
| 147 totalItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; | 143 totalItem.accessibilityIdentifier = kPaymentItemsDisplayItemID; |
| 148 totalItem.item = | 144 totalItem.item = |
| 149 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label); | 145 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label); |
| 150 payments::CurrencyFormatter* currencyFormatter = | 146 payments::CurrencyFormatter* currencyFormatter = |
| 151 _paymentRequest->GetOrCreateCurrencyFormatter(); | 147 _paymentRequest->GetOrCreateCurrencyFormatter(); |
| 152 totalItem.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( | 148 totalItem.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( |
| 153 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, | 149 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, |
| 154 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), | 150 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), |
| 155 currencyFormatter->Format(base::UTF16ToASCII( | 151 currencyFormatter->Format(base::UTF16ToASCII( |
| 156 _paymentRequest->payment_details().total.amount.value)))); | 152 _paymentRequest->payment_details().total.amount.value)))); |
| 157 | 153 |
| 158 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; | 154 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; |
| 159 | 155 |
| 160 // Add the line item entries. | 156 // Add the line item entries. |
| 161 for (const auto& paymentItem : | 157 for (const auto& paymentItem : |
| 162 _paymentRequest->payment_details().display_items) { | 158 _paymentRequest->payment_details().display_items) { |
| 163 PriceItem* paymentItemItem = | 159 PriceItem* paymentItemItem = |
| 164 [[PriceItem alloc] initWithType:ItemTypePaymentItem]; | 160 [[PriceItem alloc] initWithType:ItemTypePaymentItem]; |
| 165 paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; | 161 paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemID; |
| 166 paymentItemItem.item = base::SysUTF16ToNSString(paymentItem.label); | 162 paymentItemItem.item = base::SysUTF16ToNSString(paymentItem.label); |
| 167 payments::CurrencyFormatter* currencyFormatter = | 163 payments::CurrencyFormatter* currencyFormatter = |
| 168 _paymentRequest->GetOrCreateCurrencyFormatter(); | 164 _paymentRequest->GetOrCreateCurrencyFormatter(); |
| 169 paymentItemItem.price = SysUTF16ToNSString(currencyFormatter->Format( | 165 paymentItemItem.price = SysUTF16ToNSString(currencyFormatter->Format( |
| 170 base::UTF16ToASCII(paymentItem.amount.value))); | 166 base::UTF16ToASCII(paymentItem.amount.value))); |
| 171 [model addItem:paymentItemItem | 167 [model addItem:paymentItemItem |
| 172 toSectionWithIdentifier:SectionIdentifierPayment]; | 168 toSectionWithIdentifier:SectionIdentifierPayment]; |
| 173 } | 169 } |
| 174 } | 170 } |
| 175 | 171 |
| 176 - (void)viewDidLoad { | 172 - (void)viewDidLoad { |
| 177 [super viewDidLoad]; | 173 [super viewDidLoad]; |
| 178 self.collectionView.accessibilityIdentifier = | 174 self.collectionView.accessibilityIdentifier = |
| 179 kPaymentItemsDisplayCollectionViewId; | 175 kPaymentItemsDisplayCollectionViewID; |
| 180 | 176 |
| 181 // Customize collection view settings. | 177 // Customize collection view settings. |
| 182 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 178 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 183 self.styler.separatorInset = | 179 self.styler.separatorInset = |
| 184 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 180 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 185 } | 181 } |
| 186 | 182 |
| 187 #pragma mark UICollectionViewDataSource | 183 #pragma mark UICollectionViewDataSource |
| 188 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 184 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 189 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 185 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 #pragma mark MDCCollectionViewStylingDelegate | 219 #pragma mark MDCCollectionViewStylingDelegate |
| 224 | 220 |
| 225 // There are no effects from touching the payment items so there should not be | 221 // There are no effects from touching the payment items so there should not be |
| 226 // an ink ripple. | 222 // an ink ripple. |
| 227 - (BOOL)collectionView:(UICollectionView*)collectionView | 223 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 228 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 224 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 229 return YES; | 225 return YES; |
| 230 } | 226 } |
| 231 | 227 |
| 232 @end | 228 @end |
| OLD | NEW |