Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ios/chrome/browser/payments/payment_items_display_view_controller.mm

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: Addressed comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ui/collection_view/cells/collection_view_item.h" 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
18 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 18 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
19 #import "ios/chrome/browser/ui/icons/chrome_icon.h" 19 #import "ios/chrome/browser/ui/icons/chrome_icon.h"
20 #include "ios/chrome/browser/ui/rtl_geometry.h" 20 #include "ios/chrome/browser/ui/rtl_geometry.h"
21 #include "ios/chrome/grit/ios_strings.h" 21 #include "ios/chrome/grit/ios_strings.h"
22 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 22 #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" 23 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 25
26 NSString* const kPaymentItemsDisplayCollectionViewId = 26 NSString* const kPaymentItemsDisplayCollectionViewID =
27 @"kPaymentItemsDisplayCollectionViewId"; 27 @"kPaymentItemsDisplayCollectionViewID";
28 NSString* const kPaymentItemsDisplayItemId = @"kPaymentItemsDisplayItemId"; 28 NSString* const kPaymentItemsDisplayItemID = @"kPaymentItemsDisplayItemID";
29 29
30 namespace { 30 namespace {
31 31
32 const CGFloat kButtonEdgeInset = 9; 32 const CGFloat kButtonEdgeInset = 9;
33 const CGFloat kSeparatorEdgeInset = 14; 33 const CGFloat kSeparatorEdgeInset = 14;
34 34
35 typedef NS_ENUM(NSInteger, SectionIdentifier) { 35 typedef NS_ENUM(NSInteger, SectionIdentifier) {
36 SectionIdentifierPayment = kSectionIdentifierEnumZero, 36 SectionIdentifierPayment = kSectionIdentifierEnumZero,
37 }; 37 };
38 38
(...skipping 24 matching lines...) Expand all
63 63
64 @implementation PaymentItemsDisplayViewController 64 @implementation PaymentItemsDisplayViewController
65 65
66 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest 66 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest
67 payButtonEnabled:(BOOL)payButtonEnabled { 67 payButtonEnabled:(BOOL)payButtonEnabled {
68 DCHECK(paymentRequest); 68 DCHECK(paymentRequest);
69 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 69 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
70 [self setTitle:l10n_util::GetNSString( 70 [self setTitle:l10n_util::GetNSString(
71 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)]; 71 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TITLE)];
72 72
73 // Set up left (return) button. 73 // Set up leading (return) button.
74 UIBarButtonItem* returnButton = 74 UIBarButtonItem* returnButton =
75 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] 75 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon]
76 target:nil 76 target:nil
77 action:@selector(onReturn)]; 77 action:@selector(onReturn)];
78 [returnButton 78 [returnButton
79 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)]; 79 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_BACK)];
80 [self navigationItem].leftBarButtonItem = returnButton; 80 [self navigationItem].leftBarButtonItem = returnButton;
81 81
82 // Set up right (pay) button. 82 // Set up trailing (pay) button.
83 _payButton.reset([[MDCFlatButton alloc] init]); 83 _payButton.reset([[MDCFlatButton alloc] init]);
84 [_payButton 84 [_payButton
85 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON) 85 setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAY_BUTTON)
86 forState:UIControlStateNormal]; 86 forState:UIControlStateNormal];
87 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] 87 [_payButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500]
88 forState:UIControlStateNormal]; 88 forState:UIControlStateNormal];
89 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; 89 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]];
90 [_payButton setBackgroundColor:[UIColor grayColor] 90 [_payButton setBackgroundColor:[UIColor grayColor]
91 forState:UIControlStateDisabled]; 91 forState:UIControlStateDisabled];
92 [_payButton addTarget:nil 92 [_payButton addTarget:nil
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 #pragma mark - CollectionViewController methods 144 #pragma mark - CollectionViewController methods
145 145
146 - (void)loadModel { 146 - (void)loadModel {
147 [super loadModel]; 147 [super loadModel];
148 CollectionViewModel* model = self.collectionViewModel; 148 CollectionViewModel* model = self.collectionViewModel;
149 [model addSectionWithIdentifier:SectionIdentifierPayment]; 149 [model addSectionWithIdentifier:SectionIdentifierPayment];
150 150
151 // Add the total entry. 151 // Add the total entry.
152 PriceItem* totalItem = 152 PriceItem* totalItem =
153 [[[PriceItem alloc] initWithType:ItemTypePaymentItemTotal] autorelease]; 153 [[[PriceItem alloc] initWithType:ItemTypePaymentItemTotal] autorelease];
154 totalItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; 154 totalItem.accessibilityIdentifier = kPaymentItemsDisplayItemID;
155 totalItem.item = 155 totalItem.item =
156 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label); 156 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label);
157 payments::CurrencyFormatter* currencyFormatter = 157 payments::CurrencyFormatter* currencyFormatter =
158 _paymentRequest->GetOrCreateCurrencyFormatter(); 158 _paymentRequest->GetOrCreateCurrencyFormatter();
159 totalItem.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( 159 totalItem.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16(
160 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, 160 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT,
161 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), 161 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()),
162 currencyFormatter->Format(base::UTF16ToASCII( 162 currencyFormatter->Format(base::UTF16ToASCII(
163 _paymentRequest->payment_details().total.amount.value)))); 163 _paymentRequest->payment_details().total.amount.value))));
164 164
165 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment]; 165 [model addItem:totalItem toSectionWithIdentifier:SectionIdentifierPayment];
166 166
167 // Add the line item entries. 167 // Add the line item entries.
168 for (const auto& paymentItem : 168 for (const auto& paymentItem :
169 _paymentRequest->payment_details().display_items) { 169 _paymentRequest->payment_details().display_items) {
170 PriceItem* paymentItemItem = 170 PriceItem* paymentItemItem =
171 [[[PriceItem alloc] initWithType:ItemTypePaymentItem] autorelease]; 171 [[[PriceItem alloc] initWithType:ItemTypePaymentItem] autorelease];
172 paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemId; 172 paymentItemItem.accessibilityIdentifier = kPaymentItemsDisplayItemID;
173 paymentItemItem.item = base::SysUTF16ToNSString(paymentItem.label); 173 paymentItemItem.item = base::SysUTF16ToNSString(paymentItem.label);
174 payments::CurrencyFormatter* currencyFormatter = 174 payments::CurrencyFormatter* currencyFormatter =
175 _paymentRequest->GetOrCreateCurrencyFormatter(); 175 _paymentRequest->GetOrCreateCurrencyFormatter();
176 paymentItemItem.price = SysUTF16ToNSString(currencyFormatter->Format( 176 paymentItemItem.price = SysUTF16ToNSString(currencyFormatter->Format(
177 base::UTF16ToASCII(paymentItem.amount.value))); 177 base::UTF16ToASCII(paymentItem.amount.value)));
178 [model addItem:paymentItemItem 178 [model addItem:paymentItemItem
179 toSectionWithIdentifier:SectionIdentifierPayment]; 179 toSectionWithIdentifier:SectionIdentifierPayment];
180 } 180 }
181 } 181 }
182 182
183 - (void)viewDidLoad { 183 - (void)viewDidLoad {
184 [super viewDidLoad]; 184 [super viewDidLoad];
185 self.collectionView.accessibilityIdentifier = 185 self.collectionView.accessibilityIdentifier =
186 kPaymentItemsDisplayCollectionViewId; 186 kPaymentItemsDisplayCollectionViewID;
187 187
188 // Customize collection view settings. 188 // Customize collection view settings.
189 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 189 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
190 self.styler.separatorInset = 190 self.styler.separatorInset =
191 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); 191 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
192 } 192 }
193 193
194 #pragma mark UICollectionViewDataSource 194 #pragma mark UICollectionViewDataSource
195 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 195 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
196 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 196 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 #pragma mark MDCCollectionViewStylingDelegate 230 #pragma mark MDCCollectionViewStylingDelegate
231 231
232 // There are no effects from touching the payment items so there should not be 232 // There are no effects from touching the payment items so there should not be
233 // an ink ripple. 233 // an ink ripple.
234 - (BOOL)collectionView:(UICollectionView*)collectionView 234 - (BOOL)collectionView:(UICollectionView*)collectionView
235 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 235 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
236 return YES; 236 return YES;
237 } 237 }
238 238
239 @end 239 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698