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

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

Issue 2712053003: [Payment Request] Displays Contact Info in the payment summary view (Closed)
Patch Set: rebase Created 3 years, 9 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_request_view_controller.h" 5 #import "ios/chrome/browser/payments/payment_request_view_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 8
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_data_util.h" 11 #include "components/autofill/core/browser/autofill_data_util.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 12 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h" 13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h" 14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/personal_data_manager.h" 15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "components/payments/core/currency_formatter.h" 16 #include "components/payments/core/currency_formatter.h"
17 #include "components/strings/grit/components_strings.h" 17 #include "components/strings/grit/components_strings.h"
18 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h"
18 #import "ios/chrome/browser/payments/cells/page_info_item.h" 19 #import "ios/chrome/browser/payments/cells/page_info_item.h"
19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 20 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
20 #import "ios/chrome/browser/payments/cells/price_item.h" 21 #import "ios/chrome/browser/payments/cells/price_item.h"
21 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
22 #import "ios/chrome/browser/payments/payment_request_util.h" 22 #import "ios/chrome/browser/payments/payment_request_util.h"
23 #import "ios/chrome/browser/payments/payment_request_view_controller_actions.h" 23 #import "ios/chrome/browser/payments/payment_request_view_controller_actions.h"
24 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 24 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 28 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 29 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
30 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 30 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
31 #include "ios/chrome/browser/ui/rtl_geometry.h" 31 #include "ios/chrome/browser/ui/rtl_geometry.h"
32 #include "ios/chrome/browser/ui/uikit_ui_util.h" 32 #include "ios/chrome/browser/ui/uikit_ui_util.h"
33 #include "ios/chrome/grit/ios_strings.h" 33 #include "ios/chrome/grit/ios_strings.h"
34 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 34 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
35 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 35 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
36 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 36 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
37 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 37 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
40 40
41 #if !defined(__has_feature) || !__has_feature(objc_arc) 41 #if !defined(__has_feature) || !__has_feature(objc_arc)
42 #error "This file requires ARC support." 42 #error "This file requires ARC support."
43 #endif 43 #endif
44 44
45 using payment_request_util::NameLabelFromAutofillProfile; 45 namespace {
46 using payment_request_util::AddressLabelFromAutofillProfile; 46 using ::payment_request_util::GetNameLabelFromAutofillProfile;
47 using payment_request_util::PhoneNumberLabelFromAutofillProfile; 47 using ::payment_request_util::GetAddressLabelFromAutofillProfile;
48 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
49 using ::payment_request_util::GetEmailLabelFromAutofillProfile;
50 } // namespace
48 51
49 NSString* const kPaymentRequestCollectionViewID = 52 NSString* const kPaymentRequestCollectionViewID =
50 @"kPaymentRequestCollectionViewID"; 53 @"kPaymentRequestCollectionViewID";
51 54
52 namespace { 55 namespace {
53 56
54 const CGFloat kButtonEdgeInset = 9; 57 const CGFloat kButtonEdgeInset = 9;
55 const CGFloat kSeparatorEdgeInset = 14; 58 const CGFloat kSeparatorEdgeInset = 14;
56 59
57 typedef NS_ENUM(NSInteger, SectionIdentifier) { 60 typedef NS_ENUM(NSInteger, SectionIdentifier) {
58 SectionIdentifierSummary = kSectionIdentifierEnumZero, 61 SectionIdentifierSummary = kSectionIdentifierEnumZero,
59 SectionIdentifierShipping, 62 SectionIdentifierShipping,
60 SectionIdentifierPayment, 63 SectionIdentifierPayment,
61 64 SectionIdentifierContactInfo,
62 }; 65 };
63 66
64 typedef NS_ENUM(NSInteger, ItemType) { 67 typedef NS_ENUM(NSInteger, ItemType) {
65 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 68 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
66 ItemTypeSpinner, 69 ItemTypeSpinner,
67 ItemTypeSummaryTotal, 70 ItemTypeSummaryTotal,
68 ItemTypeShippingTitle, 71 ItemTypeShippingTitle,
69 ItemTypeShippingAddress, 72 ItemTypeShippingAddress,
70 ItemTypeAddShippingAddress, 73 ItemTypeAddShippingAddress,
71 ItemTypeShippingOption, 74 ItemTypeShippingOption,
72 ItemTypeSelectShippingOption, 75 ItemTypeSelectShippingOption,
73 ItemTypePaymentTitle, 76 ItemTypePaymentTitle,
74 ItemTypePaymentMethod, 77 ItemTypePaymentMethod,
75 ItemTypeAddPaymentMethod, 78 ItemTypeAddPaymentMethod,
79 ItemTypeContactInfoTitle,
80 ItemTypeContactInfo,
81 ItemTypeAddContactInfo,
76 }; 82 };
77 83
78 } // namespace 84 } // namespace
79 85
80 @interface PaymentRequestViewController ()< 86 @interface PaymentRequestViewController ()<
81 PaymentRequestViewControllerActions> { 87 PaymentRequestViewControllerActions> {
82 UIBarButtonItem* _cancelButton; 88 UIBarButtonItem* _cancelButton;
83 MDCFlatButton* _payButton; 89 MDCFlatButton* _payButton;
84 90
85 // The PaymentRequest object owning an instance of web::PaymentRequest as 91 // The PaymentRequest object owning an instance of web::PaymentRequest as
86 // provided by the page invoking the Payment Request API. This is a weak 92 // provided by the page invoking the Payment Request API. This is a weak
87 // pointer and should outlive this class. 93 // pointer and should outlive this class.
88 PaymentRequest* _paymentRequest; 94 PaymentRequest* _paymentRequest;
89 95
90 PriceItem* _paymentSummaryItem; 96 __weak PriceItem* _paymentSummaryItem;
91 ShippingAddressItem* _selectedShippingAddressItem; 97 __weak AutofillProfileItem* _selectedShippingAddressItem;
92 CollectionViewTextItem* _selectedShippingOptionItem; 98 __weak CollectionViewTextItem* _selectedShippingOptionItem;
93 PaymentMethodItem* _selectedPaymentMethodItem; 99 __weak PaymentMethodItem* _selectedPaymentMethodItem;
100 __weak AutofillProfileItem* _selectedContactInfoItem;
94 } 101 }
95 102
96 @end 103 @end
97 104
98 @implementation PaymentRequestViewController 105 @implementation PaymentRequestViewController
99 106
100 @synthesize pageFavicon = _pageFavicon; 107 @synthesize pageFavicon = _pageFavicon;
101 @synthesize pageTitle = _pageTitle; 108 @synthesize pageTitle = _pageTitle;
102 @synthesize pageHost = _pageHost; 109 @synthesize pageHost = _pageHost;
103 @synthesize pending = _pending; 110 @synthesize pending = _pending;
104 @synthesize delegate = _delegate; 111 @synthesize delegate = _delegate;
105 112
106 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { 113 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
107 DCHECK(paymentRequest); 114 DCHECK(paymentRequest);
108 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 115 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
109 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; 116 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
110 117
111 // Set up leading (cancel) button. 118 // Set up leading (cancel) button.
112 _cancelButton = [[UIBarButtonItem alloc] 119 _cancelButton = [[UIBarButtonItem alloc]
113 initWithTitle:l10n_util::GetNSString( 120 initWithTitle:l10n_util::GetNSString(IDS_CANCEL)
114 IDS_IOS_PAYMENT_REQUEST_CANCEL_BUTTON)
115 style:UIBarButtonItemStylePlain 121 style:UIBarButtonItemStylePlain
116 target:nil 122 target:nil
117 action:@selector(onCancel)]; 123 action:@selector(onCancel)];
118 [_cancelButton setTitleTextAttributes:@{ 124 [_cancelButton setTitleTextAttributes:@{
119 NSForegroundColorAttributeName : [UIColor lightGrayColor] 125 NSForegroundColorAttributeName : [UIColor lightGrayColor]
120 } 126 }
121 forState:UIControlStateDisabled]; 127 forState:UIControlStateDisabled];
122 [_cancelButton 128 [_cancelButton
123 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; 129 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
124 [self navigationItem].leftBarButtonItem = _cancelButton; 130 [self navigationItem].leftBarButtonItem = _cancelButton;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (_pending) { 199 if (_pending) {
194 [_payButton setEnabled:NO]; 200 [_payButton setEnabled:NO];
195 [_cancelButton setEnabled:NO]; 201 [_cancelButton setEnabled:NO];
196 202
197 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner]; 203 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner];
198 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE); 204 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE);
199 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary]; 205 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary];
200 return; 206 return;
201 } 207 }
202 208
203 _paymentSummaryItem = [[PriceItem alloc] initWithType:ItemTypeSummaryTotal]; 209 PriceItem* paymentSummaryItem =
204 [self fillPaymentSummaryItem:_paymentSummaryItem 210 [[PriceItem alloc] initWithType:ItemTypeSummaryTotal];
211 _paymentSummaryItem = paymentSummaryItem;
212 [self fillPaymentSummaryItem:paymentSummaryItem
205 withPaymentItem:_paymentRequest->payment_details().total 213 withPaymentItem:_paymentRequest->payment_details().total
206 withTotalValueChanged:NO]; 214 withTotalValueChanged:NO];
207 if (!_paymentRequest->payment_details().display_items.empty()) { 215 if (!_paymentRequest->payment_details().display_items.empty()) {
208 _paymentSummaryItem.accessoryType = 216 paymentSummaryItem.accessoryType =
209 MDCCollectionViewCellAccessoryDisclosureIndicator; 217 MDCCollectionViewCellAccessoryDisclosureIndicator;
210 _paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton; 218 paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton;
211 } 219 }
212 [model addItem:_paymentSummaryItem 220 [model addItem:paymentSummaryItem
213 toSectionWithIdentifier:SectionIdentifierSummary]; 221 toSectionWithIdentifier:SectionIdentifierSummary];
214 222
215 // Shipping section. 223 // Shipping section.
216 [model addSectionWithIdentifier:SectionIdentifierShipping]; 224 [model addSectionWithIdentifier:SectionIdentifierShipping];
217 225
218 CollectionViewTextItem* shippingTitle = 226 CollectionViewTextItem* shippingTitle =
219 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingTitle]; 227 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingTitle];
220 shippingTitle.text = 228 shippingTitle.text =
221 payment_request_util::GetShippingSectionTitle(_paymentRequest); 229 payment_request_util::GetShippingSectionTitle(_paymentRequest);
222 [model setHeader:shippingTitle 230 [model setHeader:shippingTitle
223 forSectionWithIdentifier:SectionIdentifierShipping]; 231 forSectionWithIdentifier:SectionIdentifierShipping];
224 232
225 CollectionViewItem* shippingAddressItem = nil; 233 CollectionViewItem* shippingAddressItem = nil;
226 if (_paymentRequest->selected_shipping_profile()) { 234 if (_paymentRequest->selected_shipping_profile()) {
227 _selectedShippingAddressItem = 235 AutofillProfileItem* selectedShippingAddressItem =
228 [[ShippingAddressItem alloc] initWithType:ItemTypeShippingAddress]; 236 [[AutofillProfileItem alloc] initWithType:ItemTypeShippingAddress];
229 shippingAddressItem = _selectedShippingAddressItem; 237 shippingAddressItem = selectedShippingAddressItem;
230 [self fillShippingAddressItem:_selectedShippingAddressItem 238 _selectedShippingAddressItem = selectedShippingAddressItem;
231 withAddress:_paymentRequest->selected_shipping_profile()]; 239 [self fillShippingAddressItem:selectedShippingAddressItem
232 _selectedShippingAddressItem.accessoryType = 240 withAutofillProfile:_paymentRequest->selected_shipping_profile()];
241 selectedShippingAddressItem.accessoryType =
233 MDCCollectionViewCellAccessoryDisclosureIndicator; 242 MDCCollectionViewCellAccessoryDisclosureIndicator;
234 243 selectedShippingAddressItem.accessibilityTraits |=
244 UIAccessibilityTraitButton;
235 } else { 245 } else {
236 CollectionViewDetailItem* addAddressItem = [[CollectionViewDetailItem alloc] 246 CollectionViewDetailItem* addAddressItem = [[CollectionViewDetailItem alloc]
237 initWithType:ItemTypeAddShippingAddress]; 247 initWithType:ItemTypeAddShippingAddress];
238 shippingAddressItem = addAddressItem; 248 shippingAddressItem = addAddressItem;
239 addAddressItem.text = 249 addAddressItem.text =
240 payment_request_util::GetShippingAddressSelectorTitle(_paymentRequest); 250 payment_request_util::GetShippingAddressSelectorTitle(_paymentRequest);
241 addAddressItem.detailText = [l10n_util::GetNSString( 251 addAddressItem.detailText = [l10n_util::GetNSString(IDS_ADD)
242 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON)
243 uppercaseStringWithLocale:[NSLocale currentLocale]]; 252 uppercaseStringWithLocale:[NSLocale currentLocale]];
253 addAddressItem.accessibilityTraits |= UIAccessibilityTraitButton;
244 } 254 }
245 shippingAddressItem.accessibilityTraits |= UIAccessibilityTraitButton;
246 [model addItem:shippingAddressItem 255 [model addItem:shippingAddressItem
247 toSectionWithIdentifier:SectionIdentifierShipping]; 256 toSectionWithIdentifier:SectionIdentifierShipping];
248 257
249 CollectionViewItem* shippingOptionItem = nil; 258 CollectionViewItem* shippingOptionItem = nil;
250 if (_paymentRequest->selected_shipping_option()) { 259 if (_paymentRequest->selected_shipping_option()) {
251 _selectedShippingOptionItem = 260 CollectionViewTextItem* selectedShippingOptionItem =
252 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingOption]; 261 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingOption];
253 shippingOptionItem = _selectedShippingOptionItem; 262 shippingOptionItem = selectedShippingOptionItem;
254 [self fillShippingOptionItem:_selectedShippingOptionItem 263 _selectedShippingOptionItem = selectedShippingOptionItem;
264 [self fillShippingOptionItem:selectedShippingOptionItem
255 withOption:_paymentRequest->selected_shipping_option()]; 265 withOption:_paymentRequest->selected_shipping_option()];
256 _selectedShippingOptionItem.accessoryType = 266 selectedShippingOptionItem.accessoryType =
257 MDCCollectionViewCellAccessoryDisclosureIndicator; 267 MDCCollectionViewCellAccessoryDisclosureIndicator;
268 selectedShippingOptionItem.accessibilityTraits |=
269 UIAccessibilityTraitButton;
258 } else { 270 } else {
259 CollectionViewDetailItem* selectShippingOptionItem = 271 CollectionViewDetailItem* selectShippingOptionItem =
260 [[CollectionViewDetailItem alloc] 272 [[CollectionViewDetailItem alloc]
261 initWithType:ItemTypeSelectShippingOption]; 273 initWithType:ItemTypeSelectShippingOption];
262 shippingOptionItem = selectShippingOptionItem; 274 shippingOptionItem = selectShippingOptionItem;
263 selectShippingOptionItem.text = 275 selectShippingOptionItem.text =
264 payment_request_util::GetShippingOptionSelectorTitle(_paymentRequest); 276 payment_request_util::GetShippingOptionSelectorTitle(_paymentRequest);
265 selectShippingOptionItem.accessoryType = 277 selectShippingOptionItem.accessoryType =
266 MDCCollectionViewCellAccessoryDisclosureIndicator; 278 MDCCollectionViewCellAccessoryDisclosureIndicator;
279 selectShippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton;
267 } 280 }
268 shippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton;
269 [model addItem:shippingOptionItem 281 [model addItem:shippingOptionItem
270 toSectionWithIdentifier:SectionIdentifierShipping]; 282 toSectionWithIdentifier:SectionIdentifierShipping];
271 283
272 // Payment method section. 284 // Payment method section.
273 [model addSectionWithIdentifier:SectionIdentifierPayment]; 285 [model addSectionWithIdentifier:SectionIdentifierPayment];
274 286
275 CollectionViewItem* paymentMethodItem = nil; 287 CollectionViewItem* paymentMethodItem = nil;
276 if (_paymentRequest->selected_credit_card()) { 288 if (_paymentRequest->selected_credit_card()) {
277 CollectionViewTextItem* paymentTitle = 289 CollectionViewTextItem* paymentTitle =
278 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle]; 290 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle];
279 paymentTitle.text = 291 paymentTitle.text =
280 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER); 292 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL);
281 [model setHeader:paymentTitle 293 [model setHeader:paymentTitle
282 forSectionWithIdentifier:SectionIdentifierPayment]; 294 forSectionWithIdentifier:SectionIdentifierPayment];
283 295
284 _selectedPaymentMethodItem = 296 PaymentMethodItem* selectedPaymentMethodItem =
285 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod]; 297 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod];
286 paymentMethodItem = _selectedPaymentMethodItem; 298 paymentMethodItem = selectedPaymentMethodItem;
287 [self fillPaymentMethodItem:_selectedPaymentMethodItem 299 _selectedPaymentMethodItem = selectedPaymentMethodItem;
288 withPaymentMethod:_paymentRequest->selected_credit_card()]; 300 [self fillPaymentMethodItem:selectedPaymentMethodItem
289 _selectedPaymentMethodItem.accessoryType = 301 withCreditCard:_paymentRequest->selected_credit_card()];
302 selectedPaymentMethodItem.accessoryType =
290 MDCCollectionViewCellAccessoryDisclosureIndicator; 303 MDCCollectionViewCellAccessoryDisclosureIndicator;
304 selectedPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
291 } else { 305 } else {
292 CollectionViewDetailItem* addPaymentMethodItem = [ 306 CollectionViewDetailItem* addPaymentMethodItem = [
293 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod]; 307 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod];
294 paymentMethodItem = addPaymentMethodItem; 308 paymentMethodItem = addPaymentMethodItem;
295 addPaymentMethodItem.text = 309 addPaymentMethodItem.text =
296 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER); 310 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL);
297 addPaymentMethodItem.detailText = [l10n_util::GetNSString( 311 addPaymentMethodItem.detailText = [l10n_util::GetNSString(IDS_ADD)
298 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON)
299 uppercaseStringWithLocale:[NSLocale currentLocale]]; 312 uppercaseStringWithLocale:[NSLocale currentLocale]];
313 addPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
300 } 314 }
301 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
302 [model addItem:paymentMethodItem 315 [model addItem:paymentMethodItem
303 toSectionWithIdentifier:SectionIdentifierPayment]; 316 toSectionWithIdentifier:SectionIdentifierPayment];
317
318 // Contact Info section.
319 [model addSectionWithIdentifier:SectionIdentifierContactInfo];
320
321 CollectionViewItem* contactInfoItem = nil;
322 if (_paymentRequest->selected_contact_profile()) {
323 CollectionViewTextItem* contactInfoTitle =
324 [[CollectionViewTextItem alloc] initWithType:ItemTypeContactInfoTitle];
325 contactInfoTitle.text =
326 l10n_util::GetNSString(IDS_PAYMENTS_CONTACT_DETAILS_LABEL);
327 [model setHeader:contactInfoTitle
328 forSectionWithIdentifier:SectionIdentifierContactInfo];
329
330 AutofillProfileItem* selectedContactInfoItem =
331 [[AutofillProfileItem alloc] initWithType:ItemTypeContactInfo];
332 contactInfoItem = selectedContactInfoItem;
333 _selectedContactInfoItem = selectedContactInfoItem;
334 [self fillContactInfoItem:selectedContactInfoItem
335 withAutofillProfile:_paymentRequest->selected_contact_profile()];
336 selectedContactInfoItem.accessoryType =
337 MDCCollectionViewCellAccessoryDisclosureIndicator;
338
339 } else {
340 CollectionViewDetailItem* addContactInfoItem =
341 [[CollectionViewDetailItem alloc] initWithType:ItemTypeAddContactInfo];
342 contactInfoItem = addContactInfoItem;
343 addContactInfoItem.text =
344 l10n_util::GetNSString(IDS_PAYMENTS_CONTACT_DETAILS_LABEL);
345 addContactInfoItem.detailText = [l10n_util::GetNSString(IDS_ADD)
346 uppercaseStringWithLocale:[NSLocale currentLocale]];
347 addContactInfoItem.accessibilityTraits |= UIAccessibilityTraitButton;
348 }
349 [model addItem:contactInfoItem
350 toSectionWithIdentifier:SectionIdentifierContactInfo];
304 } 351 }
305 352
306 - (void)viewDidLoad { 353 - (void)viewDidLoad {
307 [super viewDidLoad]; 354 [super viewDidLoad];
308 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID; 355 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID;
309 356
310 // Customize collection view settings. 357 // Customize collection view settings.
311 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 358 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
312 self.styler.separatorInset = 359 self.styler.separatorInset =
313 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); 360 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
314 } 361 }
315 362
316 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { 363 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged {
317 [self fillPaymentSummaryItem:_paymentSummaryItem 364 [self fillPaymentSummaryItem:_paymentSummaryItem
318 withPaymentItem:_paymentRequest->payment_details().total 365 withPaymentItem:_paymentRequest->payment_details().total
319 withTotalValueChanged:totalValueChanged]; 366 withTotalValueChanged:totalValueChanged];
320 NSIndexPath* indexPath = 367 NSIndexPath* indexPath =
321 [self.collectionViewModel indexPathForItem:_paymentSummaryItem 368 [self.collectionViewModel indexPathForItem:_paymentSummaryItem
322 inSectionWithIdentifier:SectionIdentifierSummary]; 369 inSectionWithIdentifier:SectionIdentifierSummary];
323 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 370 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
324 } 371 }
325 372
326 - (void)updateSelectedShippingAddressUI { 373 - (void)updateSelectedShippingAddressUI {
327 [self fillShippingAddressItem:_selectedShippingAddressItem 374 [self fillShippingAddressItem:_selectedShippingAddressItem
328 withAddress:_paymentRequest->selected_shipping_profile()]; 375 withAutofillProfile:_paymentRequest->selected_shipping_profile()];
329 NSIndexPath* indexPath = 376 NSIndexPath* indexPath =
330 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem 377 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem
331 inSectionWithIdentifier:SectionIdentifierShipping]; 378 inSectionWithIdentifier:SectionIdentifierShipping];
332 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 379 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
333 } 380 }
334 381
335 - (void)updateSelectedShippingOptionUI { 382 - (void)updateSelectedShippingOptionUI {
336 [self fillShippingOptionItem:_selectedShippingOptionItem 383 [self fillShippingOptionItem:_selectedShippingOptionItem
337 withOption:_paymentRequest->selected_shipping_option()]; 384 withOption:_paymentRequest->selected_shipping_option()];
338 NSIndexPath* indexPath = 385 NSIndexPath* indexPath =
339 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem 386 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem
340 inSectionWithIdentifier:SectionIdentifierShipping]; 387 inSectionWithIdentifier:SectionIdentifierShipping];
341 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 388 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
342 } 389 }
343 390
344 - (void)updateSelectedPaymentMethodUI { 391 - (void)updateSelectedPaymentMethodUI {
345 [self fillPaymentMethodItem:_selectedPaymentMethodItem 392 [self fillPaymentMethodItem:_selectedPaymentMethodItem
346 withPaymentMethod:_paymentRequest->selected_credit_card()]; 393 withCreditCard:_paymentRequest->selected_credit_card()];
347 NSIndexPath* indexPath = 394 NSIndexPath* indexPath =
348 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem 395 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem
349 inSectionWithIdentifier:SectionIdentifierPayment]; 396 inSectionWithIdentifier:SectionIdentifierPayment];
350 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 397 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
351 } 398 }
352 399
353 #pragma mark - Helper methods 400 #pragma mark - Helper methods
354 401
355 - (void)fillPaymentSummaryItem:(PriceItem*)item 402 - (void)fillPaymentSummaryItem:(PriceItem*)item
356 withPaymentItem:(web::PaymentItem)paymentItem 403 withPaymentItem:(web::PaymentItem)paymentItem
357 withTotalValueChanged:(BOOL)totalValueChanged { 404 withTotalValueChanged:(BOOL)totalValueChanged {
358 item.item = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER); 405 item.item = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER);
359 payments::CurrencyFormatter* currencyFormatter = 406 payments::CurrencyFormatter* currencyFormatter =
360 _paymentRequest->GetOrCreateCurrencyFormatter(); 407 _paymentRequest->GetOrCreateCurrencyFormatter();
361 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( 408 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16(
362 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, 409 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT,
363 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), 410 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()),
364 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value)))); 411 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value))));
365 item.notification = 412 item.notification =
366 totalValueChanged 413 totalValueChanged
367 ? l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_UPDATED_LABEL) 414 ? l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_UPDATED_LABEL)
368 : nil; 415 : nil;
369 } 416 }
370 417
371 - (void)fillShippingAddressItem:(ShippingAddressItem*)item 418 - (void)fillShippingAddressItem:(AutofillProfileItem*)item
372 withAddress:(autofill::AutofillProfile*)address { 419 withAutofillProfile:(autofill::AutofillProfile*)profile {
373 item.name = NameLabelFromAutofillProfile(address); 420 item.name = GetNameLabelFromAutofillProfile(profile);
374 item.address = AddressLabelFromAutofillProfile(address); 421 item.address = GetAddressLabelFromAutofillProfile(profile);
375 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(address); 422 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile);
376 } 423 }
377 424
378 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item 425 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item
379 withOption:(web::PaymentShippingOption*)option { 426 withOption:(web::PaymentShippingOption*)option {
380 item.text = base::SysUTF16ToNSString(option->label); 427 item.text = base::SysUTF16ToNSString(option->label);
381 payments::CurrencyFormatter* currencyFormatter = 428 payments::CurrencyFormatter* currencyFormatter =
382 _paymentRequest->GetOrCreateCurrencyFormatter(); 429 _paymentRequest->GetOrCreateCurrencyFormatter();
383 item.detailText = SysUTF16ToNSString( 430 item.detailText = SysUTF16ToNSString(
384 currencyFormatter->Format(base::UTF16ToASCII(option->amount.value))); 431 currencyFormatter->Format(base::UTF16ToASCII(option->amount.value)));
385 } 432 }
386 433
387 - (void)fillPaymentMethodItem:(PaymentMethodItem*)item 434 - (void)fillPaymentMethodItem:(PaymentMethodItem*)item
388 withPaymentMethod:(autofill::CreditCard*)creditCard { 435 withCreditCard:(autofill::CreditCard*)creditCard {
389 item.methodID = base::SysUTF16ToNSString(creditCard->TypeAndLastFourDigits()); 436 item.methodID = base::SysUTF16ToNSString(creditCard->TypeAndLastFourDigits());
390 item.methodDetail = base::SysUTF16ToNSString( 437 item.methodDetail = base::SysUTF16ToNSString(
391 creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); 438 creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL));
392 int selectedMethodCardTypeIconID = 439 int selectedMethodCardTypeIconID =
393 autofill::data_util::GetPaymentRequestData(creditCard->type()) 440 autofill::data_util::GetPaymentRequestData(creditCard->type())
394 .icon_resource_id; 441 .icon_resource_id;
395 item.methodTypeIcon = NativeImage(selectedMethodCardTypeIconID); 442 item.methodTypeIcon = NativeImage(selectedMethodCardTypeIconID);
396 } 443 }
397 444
445 - (void)fillContactInfoItem:(AutofillProfileItem*)item
446 withAutofillProfile:(autofill::AutofillProfile*)profile {
447 item.name = GetNameLabelFromAutofillProfile(profile);
448 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile);
449 item.email = GetEmailLabelFromAutofillProfile(profile);
450 }
451
398 #pragma mark UICollectionViewDataSource 452 #pragma mark UICollectionViewDataSource
399 453
400 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 454 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
401 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 455 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
402 UICollectionViewCell* cell = 456 UICollectionViewCell* cell =
403 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; 457 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
404 458
405 NSInteger itemType = 459 NSInteger itemType =
406 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 460 [self.collectionViewModel itemTypeForIndexPath:indexPath];
407 switch (itemType) { 461 switch (itemType) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self]; 501 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self];
448 break; 502 break;
449 case ItemTypeShippingOption: 503 case ItemTypeShippingOption:
450 case ItemTypeSelectShippingOption: 504 case ItemTypeSelectShippingOption:
451 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self]; 505 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self];
452 break; 506 break;
453 case ItemTypePaymentMethod: 507 case ItemTypePaymentMethod:
454 case ItemTypeAddPaymentMethod: 508 case ItemTypeAddPaymentMethod:
455 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self]; 509 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self];
456 break; 510 break;
511 case ItemTypeContactInfo:
512 case ItemTypeAddContactInfo:
513 // TODO(crbug.com/602666): Handle displaying contact info selection view.
514 break;
457 default: 515 default:
458 NOTREACHED(); 516 NOTREACHED();
459 break; 517 break;
460 } 518 }
461 } 519 }
462 520
463 #pragma mark MDCCollectionViewStylingDelegate 521 #pragma mark MDCCollectionViewStylingDelegate
464 522
465 - (CGFloat)collectionView:(UICollectionView*)collectionView 523 - (CGFloat)collectionView:(UICollectionView*)collectionView
466 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 524 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
467 CollectionViewItem* item = 525 CollectionViewItem* item =
468 [self.collectionViewModel itemAtIndexPath:indexPath]; 526 [self.collectionViewModel itemAtIndexPath:indexPath];
469 switch (item.type) { 527 switch (item.type) {
470 case ItemTypeSpinner: 528 case ItemTypeSpinner:
471 case ItemTypeShippingAddress: 529 case ItemTypeShippingAddress:
472 case ItemTypePaymentMethod: 530 case ItemTypePaymentMethod:
531 case ItemTypeContactInfo:
473 return [MDCCollectionViewCell 532 return [MDCCollectionViewCell
474 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 533 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
475 forItem:item]; 534 forItem:item];
476 case ItemTypeShippingOption: 535 case ItemTypeShippingOption:
477 return MDCCellDefaultTwoLineHeight; 536 return MDCCellDefaultTwoLineHeight;
478 case ItemTypeSummaryPageInfo: 537 case ItemTypeSummaryPageInfo:
479 case ItemTypeSummaryTotal: 538 case ItemTypeSummaryTotal:
480 case ItemTypeShippingTitle: 539 case ItemTypeShippingTitle:
481 case ItemTypeAddShippingAddress: 540 case ItemTypeAddShippingAddress:
482 case ItemTypeSelectShippingOption: 541 case ItemTypeSelectShippingOption:
483 case ItemTypePaymentTitle: 542 case ItemTypePaymentTitle:
484 case ItemTypeAddPaymentMethod: 543 case ItemTypeAddPaymentMethod:
544 case ItemTypeContactInfoTitle:
545 case ItemTypeAddContactInfo:
485 return MDCCellDefaultOneLineHeight; 546 return MDCCellDefaultOneLineHeight;
486 default: 547 default:
487 NOTREACHED(); 548 NOTREACHED();
488 return MDCCellDefaultOneLineHeight; 549 return MDCCellDefaultOneLineHeight;
489 } 550 }
490 } 551 }
491 552
492 // If there are no payment items to display, there is no effect from touching 553 // If there are no payment items to display, there is no effect from touching
493 // the total so there should not be an ink ripple. 554 // the total so there should not be an ink ripple.
494 - (BOOL)collectionView:(UICollectionView*)collectionView 555 - (BOOL)collectionView:(UICollectionView*)collectionView
495 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 556 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
496 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 557 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
497 if (type == ItemTypeSummaryTotal && 558 if (type == ItemTypeSummaryTotal &&
498 _paymentRequest->payment_details().display_items.empty()) { 559 _paymentRequest->payment_details().display_items.empty()) {
499 return YES; 560 return YES;
500 } else { 561 } else {
501 return NO; 562 return NO;
502 } 563 }
503 } 564 }
504 565
505 @end 566 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698