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