Chromium Code Reviews| 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_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/currency_formatter.h" | 16 #include "components/payments/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 using payment_request_util::GetNameLabelFromAutofillProfile; |
| 46 using payment_request_util::AddressLabelFromAutofillProfile; | 46 using payment_request_util::GetAddressLabelFromAutofillProfile; |
| 47 using payment_request_util::PhoneNumberLabelFromAutofillProfile; | 47 using payment_request_util::GetPhoneNumberLabelFromAutofillProfile; |
| 48 using payment_request_util::GetEmailLabelFromAutofillProfile; | |
|
please use gerrit instead
2017/02/26 01:55:25
Please put these statements inside the anonymous n
Moe
2017/02/27 16:43:23
Done.
| |
| 48 | 49 |
| 49 NSString* const kPaymentRequestCollectionViewID = | 50 NSString* const kPaymentRequestCollectionViewID = |
| 50 @"kPaymentRequestCollectionViewID"; | 51 @"kPaymentRequestCollectionViewID"; |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 54 const CGFloat kButtonEdgeInset = 9; | 55 const CGFloat kButtonEdgeInset = 9; |
| 55 const CGFloat kSeparatorEdgeInset = 14; | 56 const CGFloat kSeparatorEdgeInset = 14; |
| 56 | 57 |
| 57 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 58 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 58 SectionIdentifierSummary = kSectionIdentifierEnumZero, | 59 SectionIdentifierSummary = kSectionIdentifierEnumZero, |
| 59 SectionIdentifierShipping, | 60 SectionIdentifierShipping, |
| 60 SectionIdentifierPayment, | 61 SectionIdentifierPayment, |
| 61 | 62 SectionIdentifierContactInfo, |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 typedef NS_ENUM(NSInteger, ItemType) { | 65 typedef NS_ENUM(NSInteger, ItemType) { |
| 65 ItemTypeSummaryPageInfo = kItemTypeEnumZero, | 66 ItemTypeSummaryPageInfo = kItemTypeEnumZero, |
| 66 ItemTypeSpinner, | 67 ItemTypeSpinner, |
| 67 ItemTypeSummaryTotal, | 68 ItemTypeSummaryTotal, |
| 68 ItemTypeShippingTitle, | 69 ItemTypeShippingTitle, |
| 69 ItemTypeShippingAddress, | 70 ItemTypeShippingAddress, |
| 70 ItemTypeAddShippingAddress, | 71 ItemTypeAddShippingAddress, |
| 71 ItemTypeShippingOption, | 72 ItemTypeShippingOption, |
| 72 ItemTypeSelectShippingOption, | 73 ItemTypeSelectShippingOption, |
| 73 ItemTypePaymentTitle, | 74 ItemTypePaymentTitle, |
| 74 ItemTypePaymentMethod, | 75 ItemTypePaymentMethod, |
| 75 ItemTypeAddPaymentMethod, | 76 ItemTypeAddPaymentMethod, |
| 77 ItemTypeContactInfoTitle, | |
| 78 ItemTypeContactInfo, | |
| 79 ItemTypeAddContactInfo, | |
| 76 }; | 80 }; |
| 77 | 81 |
| 78 } // namespace | 82 } // namespace |
| 79 | 83 |
| 80 @interface PaymentRequestViewController ()< | 84 @interface PaymentRequestViewController ()< |
| 81 PaymentRequestViewControllerActions> { | 85 PaymentRequestViewControllerActions> { |
| 82 UIBarButtonItem* _cancelButton; | 86 UIBarButtonItem* _cancelButton; |
| 83 MDCFlatButton* _payButton; | 87 MDCFlatButton* _payButton; |
| 84 | 88 |
| 85 // The PaymentRequest object owning an instance of web::PaymentRequest as | 89 // The PaymentRequest object owning an instance of web::PaymentRequest as |
| 86 // provided by the page invoking the Payment Request API. This is a weak | 90 // provided by the page invoking the Payment Request API. This is a weak |
| 87 // pointer and should outlive this class. | 91 // pointer and should outlive this class. |
| 88 PaymentRequest* _paymentRequest; | 92 PaymentRequest* _paymentRequest; |
| 89 | 93 |
| 90 PriceItem* _paymentSummaryItem; | 94 __weak PriceItem* _paymentSummaryItem; |
| 91 ShippingAddressItem* _selectedShippingAddressItem; | 95 __weak AutofillProfileItem* _selectedShippingAddressItem; |
| 92 CollectionViewTextItem* _selectedShippingOptionItem; | 96 __weak CollectionViewTextItem* _selectedShippingOptionItem; |
| 93 PaymentMethodItem* _selectedPaymentMethodItem; | 97 __weak PaymentMethodItem* _selectedPaymentMethodItem; |
| 98 __weak AutofillProfileItem* _selectedContactInfoItem; | |
| 94 } | 99 } |
| 95 | 100 |
| 96 @end | 101 @end |
| 97 | 102 |
| 98 @implementation PaymentRequestViewController | 103 @implementation PaymentRequestViewController |
| 99 | 104 |
| 100 @synthesize pageFavicon = _pageFavicon; | 105 @synthesize pageFavicon = _pageFavicon; |
| 101 @synthesize pageTitle = _pageTitle; | 106 @synthesize pageTitle = _pageTitle; |
| 102 @synthesize pageHost = _pageHost; | 107 @synthesize pageHost = _pageHost; |
| 103 @synthesize pending = _pending; | 108 @synthesize pending = _pending; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 if (_pending) { | 198 if (_pending) { |
| 194 [_payButton setEnabled:NO]; | 199 [_payButton setEnabled:NO]; |
| 195 [_cancelButton setEnabled:NO]; | 200 [_cancelButton setEnabled:NO]; |
| 196 | 201 |
| 197 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner]; | 202 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner]; |
| 198 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE); | 203 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE); |
| 199 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary]; | 204 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary]; |
| 200 return; | 205 return; |
| 201 } | 206 } |
| 202 | 207 |
| 203 _paymentSummaryItem = [[PriceItem alloc] initWithType:ItemTypeSummaryTotal]; | 208 PriceItem* paymentSummaryItem = |
| 204 [self fillPaymentSummaryItem:_paymentSummaryItem | 209 [[PriceItem alloc] initWithType:ItemTypeSummaryTotal]; |
| 210 _paymentSummaryItem = paymentSummaryItem; | |
| 211 [self fillPaymentSummaryItem:paymentSummaryItem | |
| 205 withPaymentItem:_paymentRequest->payment_details().total | 212 withPaymentItem:_paymentRequest->payment_details().total |
| 206 withTotalValueChanged:NO]; | 213 withTotalValueChanged:NO]; |
| 207 if (!_paymentRequest->payment_details().display_items.empty()) { | 214 if (!_paymentRequest->payment_details().display_items.empty()) { |
| 208 _paymentSummaryItem.accessoryType = | 215 paymentSummaryItem.accessoryType = |
| 209 MDCCollectionViewCellAccessoryDisclosureIndicator; | 216 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 210 _paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton; | 217 paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 211 } | 218 } |
| 212 [model addItem:_paymentSummaryItem | 219 [model addItem:paymentSummaryItem |
| 213 toSectionWithIdentifier:SectionIdentifierSummary]; | 220 toSectionWithIdentifier:SectionIdentifierSummary]; |
| 214 | 221 |
| 215 // Shipping section. | 222 // Shipping section. |
| 216 [model addSectionWithIdentifier:SectionIdentifierShipping]; | 223 [model addSectionWithIdentifier:SectionIdentifierShipping]; |
| 217 | 224 |
| 218 CollectionViewTextItem* shippingTitle = | 225 CollectionViewTextItem* shippingTitle = |
| 219 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingTitle]; | 226 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingTitle]; |
| 220 shippingTitle.text = | 227 shippingTitle.text = |
| 221 payment_request_util::GetShippingSectionTitle(_paymentRequest); | 228 payment_request_util::GetShippingSectionTitle(_paymentRequest); |
| 222 [model setHeader:shippingTitle | 229 [model setHeader:shippingTitle |
| 223 forSectionWithIdentifier:SectionIdentifierShipping]; | 230 forSectionWithIdentifier:SectionIdentifierShipping]; |
| 224 | 231 |
| 225 CollectionViewItem* shippingAddressItem = nil; | 232 id shippingAddressItem = nil; |
| 226 if (_paymentRequest->selected_shipping_profile()) { | 233 if (_paymentRequest->selected_shipping_profile()) { |
| 227 _selectedShippingAddressItem = | 234 AutofillProfileItem* selectedShippingAddressItem = |
| 228 [[ShippingAddressItem alloc] initWithType:ItemTypeShippingAddress]; | 235 [[AutofillProfileItem alloc] initWithType:ItemTypeShippingAddress]; |
| 229 shippingAddressItem = _selectedShippingAddressItem; | 236 shippingAddressItem = selectedShippingAddressItem; |
| 230 [self fillShippingAddressItem:_selectedShippingAddressItem | 237 _selectedShippingAddressItem = selectedShippingAddressItem; |
| 231 withAddress:_paymentRequest->selected_shipping_profile()]; | 238 [self fillShippingAddressItem:selectedShippingAddressItem |
| 232 _selectedShippingAddressItem.accessoryType = | 239 withAutofillProfile:_paymentRequest->selected_shipping_profile()]; |
| 240 selectedShippingAddressItem.accessoryType = | |
| 233 MDCCollectionViewCellAccessoryDisclosureIndicator; | 241 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 234 | 242 selectedShippingAddressItem.accessibilityTraits |= |
| 243 UIAccessibilityTraitButton; | |
| 235 } else { | 244 } else { |
| 236 CollectionViewDetailItem* addAddressItem = [[CollectionViewDetailItem alloc] | 245 CollectionViewDetailItem* addAddressItem = [[CollectionViewDetailItem alloc] |
| 237 initWithType:ItemTypeAddShippingAddress]; | 246 initWithType:ItemTypeAddShippingAddress]; |
| 238 shippingAddressItem = addAddressItem; | 247 shippingAddressItem = addAddressItem; |
| 239 addAddressItem.text = | 248 addAddressItem.text = |
| 240 payment_request_util::GetShippingAddressSelectorTitle(_paymentRequest); | 249 payment_request_util::GetShippingAddressSelectorTitle(_paymentRequest); |
| 241 addAddressItem.detailText = [l10n_util::GetNSString( | 250 addAddressItem.detailText = [l10n_util::GetNSString(IDS_PAYMENTS_ADD_BUTTON) |
| 242 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) | |
| 243 uppercaseStringWithLocale:[NSLocale currentLocale]]; | 251 uppercaseStringWithLocale:[NSLocale currentLocale]]; |
| 252 addAddressItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 244 } | 253 } |
| 245 shippingAddressItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 246 [model addItem:shippingAddressItem | 254 [model addItem:shippingAddressItem |
| 247 toSectionWithIdentifier:SectionIdentifierShipping]; | 255 toSectionWithIdentifier:SectionIdentifierShipping]; |
| 248 | 256 |
| 249 CollectionViewItem* shippingOptionItem = nil; | 257 id shippingOptionItem = nil; |
| 250 if (_paymentRequest->selected_shipping_option()) { | 258 if (_paymentRequest->selected_shipping_option()) { |
| 251 _selectedShippingOptionItem = | 259 CollectionViewTextItem* selectedShippingOptionItem = |
| 252 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingOption]; | 260 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingOption]; |
| 253 shippingOptionItem = _selectedShippingOptionItem; | 261 shippingOptionItem = selectedShippingOptionItem; |
| 254 [self fillShippingOptionItem:_selectedShippingOptionItem | 262 _selectedShippingOptionItem = selectedShippingOptionItem; |
| 263 [self fillShippingOptionItem:selectedShippingOptionItem | |
| 255 withOption:_paymentRequest->selected_shipping_option()]; | 264 withOption:_paymentRequest->selected_shipping_option()]; |
| 256 _selectedShippingOptionItem.accessoryType = | 265 selectedShippingOptionItem.accessoryType = |
| 257 MDCCollectionViewCellAccessoryDisclosureIndicator; | 266 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 267 selectedShippingOptionItem.accessibilityTraits |= | |
| 268 UIAccessibilityTraitButton; | |
| 258 } else { | 269 } else { |
| 259 CollectionViewDetailItem* selectShippingOptionItem = | 270 CollectionViewDetailItem* selectShippingOptionItem = |
| 260 [[CollectionViewDetailItem alloc] | 271 [[CollectionViewDetailItem alloc] |
| 261 initWithType:ItemTypeSelectShippingOption]; | 272 initWithType:ItemTypeSelectShippingOption]; |
| 262 shippingOptionItem = selectShippingOptionItem; | 273 shippingOptionItem = selectShippingOptionItem; |
| 263 selectShippingOptionItem.text = | 274 selectShippingOptionItem.text = |
| 264 payment_request_util::GetShippingOptionSelectorTitle(_paymentRequest); | 275 payment_request_util::GetShippingOptionSelectorTitle(_paymentRequest); |
| 265 selectShippingOptionItem.accessoryType = | 276 selectShippingOptionItem.accessoryType = |
| 266 MDCCollectionViewCellAccessoryDisclosureIndicator; | 277 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 278 selectShippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 267 } | 279 } |
| 268 shippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 269 [model addItem:shippingOptionItem | 280 [model addItem:shippingOptionItem |
| 270 toSectionWithIdentifier:SectionIdentifierShipping]; | 281 toSectionWithIdentifier:SectionIdentifierShipping]; |
| 271 | 282 |
| 272 // Payment method section. | 283 // Payment method section. |
| 273 [model addSectionWithIdentifier:SectionIdentifierPayment]; | 284 [model addSectionWithIdentifier:SectionIdentifierPayment]; |
| 274 | 285 |
| 275 CollectionViewItem* paymentMethodItem = nil; | 286 CollectionViewItem* paymentMethodItem = nil; |
| 276 if (_paymentRequest->selected_credit_card()) { | 287 if (_paymentRequest->selected_credit_card()) { |
| 277 CollectionViewTextItem* paymentTitle = | 288 CollectionViewTextItem* paymentTitle = |
| 278 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle]; | 289 [[CollectionViewTextItem alloc] initWithType:ItemTypePaymentTitle]; |
| 279 paymentTitle.text = | 290 paymentTitle.text = |
| 280 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER); | 291 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL); |
| 281 [model setHeader:paymentTitle | 292 [model setHeader:paymentTitle |
| 282 forSectionWithIdentifier:SectionIdentifierPayment]; | 293 forSectionWithIdentifier:SectionIdentifierPayment]; |
| 283 | 294 |
| 284 _selectedPaymentMethodItem = | 295 PaymentMethodItem* selectedPaymentMethodItem = |
| 285 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod]; | 296 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod]; |
| 286 paymentMethodItem = _selectedPaymentMethodItem; | 297 paymentMethodItem = selectedPaymentMethodItem; |
| 287 [self fillPaymentMethodItem:_selectedPaymentMethodItem | 298 _selectedPaymentMethodItem = selectedPaymentMethodItem; |
| 288 withPaymentMethod:_paymentRequest->selected_credit_card()]; | 299 [self fillPaymentMethodItem:selectedPaymentMethodItem |
| 289 _selectedPaymentMethodItem.accessoryType = | 300 withCreditCard:_paymentRequest->selected_credit_card()]; |
| 301 selectedPaymentMethodItem.accessoryType = | |
| 290 MDCCollectionViewCellAccessoryDisclosureIndicator; | 302 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 303 selectedPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 291 } else { | 304 } else { |
| 292 CollectionViewDetailItem* addPaymentMethodItem = [ | 305 CollectionViewDetailItem* addPaymentMethodItem = [ |
| 293 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod]; | 306 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod]; |
| 294 paymentMethodItem = addPaymentMethodItem; | 307 paymentMethodItem = addPaymentMethodItem; |
| 295 addPaymentMethodItem.text = | 308 addPaymentMethodItem.text = |
| 296 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER); | 309 l10n_util::GetNSString(IDS_PAYMENTS_METHOD_OF_PAYMENT_LABEL); |
| 297 addPaymentMethodItem.detailText = [l10n_util::GetNSString( | 310 addPaymentMethodItem.detailText = |
| 298 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) | 311 [l10n_util::GetNSString(IDS_PAYMENTS_ADD_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 id 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 = | |
| 346 [l10n_util::GetNSString(IDS_PAYMENTS_ADD_BUTTON) | |
| 347 uppercaseStringWithLocale:[NSLocale currentLocale]]; | |
| 348 addContactInfoItem.accessibilityTraits |= UIAccessibilityTraitButton; | |
| 349 } | |
| 350 [model addItem:contactInfoItem | |
| 351 toSectionWithIdentifier:SectionIdentifierContactInfo]; | |
| 304 } | 352 } |
| 305 | 353 |
| 306 - (void)viewDidLoad { | 354 - (void)viewDidLoad { |
| 307 [super viewDidLoad]; | 355 [super viewDidLoad]; |
| 308 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID; | 356 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID; |
| 309 | 357 |
| 310 // Customize collection view settings. | 358 // Customize collection view settings. |
| 311 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 359 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 312 self.styler.separatorInset = | 360 self.styler.separatorInset = |
| 313 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 361 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 314 } | 362 } |
| 315 | 363 |
| 316 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { | 364 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged { |
| 317 [self fillPaymentSummaryItem:_paymentSummaryItem | 365 [self fillPaymentSummaryItem:_paymentSummaryItem |
| 318 withPaymentItem:_paymentRequest->payment_details().total | 366 withPaymentItem:_paymentRequest->payment_details().total |
| 319 withTotalValueChanged:totalValueChanged]; | 367 withTotalValueChanged:totalValueChanged]; |
| 320 NSIndexPath* indexPath = | 368 NSIndexPath* indexPath = |
| 321 [self.collectionViewModel indexPathForItem:_paymentSummaryItem | 369 [self.collectionViewModel indexPathForItem:_paymentSummaryItem |
| 322 inSectionWithIdentifier:SectionIdentifierSummary]; | 370 inSectionWithIdentifier:SectionIdentifierSummary]; |
| 323 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 371 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 324 } | 372 } |
| 325 | 373 |
| 326 - (void)updateSelectedShippingAddressUI { | 374 - (void)updateSelectedShippingAddressUI { |
| 327 [self fillShippingAddressItem:_selectedShippingAddressItem | 375 [self fillShippingAddressItem:_selectedShippingAddressItem |
| 328 withAddress:_paymentRequest->selected_shipping_profile()]; | 376 withAutofillProfile:_paymentRequest->selected_shipping_profile()]; |
| 329 NSIndexPath* indexPath = | 377 NSIndexPath* indexPath = |
| 330 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem | 378 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem |
| 331 inSectionWithIdentifier:SectionIdentifierShipping]; | 379 inSectionWithIdentifier:SectionIdentifierShipping]; |
| 332 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 380 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 333 } | 381 } |
| 334 | 382 |
| 335 - (void)updateSelectedShippingOptionUI { | 383 - (void)updateSelectedShippingOptionUI { |
| 336 [self fillShippingOptionItem:_selectedShippingOptionItem | 384 [self fillShippingOptionItem:_selectedShippingOptionItem |
| 337 withOption:_paymentRequest->selected_shipping_option()]; | 385 withOption:_paymentRequest->selected_shipping_option()]; |
| 338 NSIndexPath* indexPath = | 386 NSIndexPath* indexPath = |
| 339 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem | 387 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem |
| 340 inSectionWithIdentifier:SectionIdentifierShipping]; | 388 inSectionWithIdentifier:SectionIdentifierShipping]; |
| 341 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 389 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 342 } | 390 } |
| 343 | 391 |
| 344 - (void)updateSelectedPaymentMethodUI { | 392 - (void)updateSelectedPaymentMethodUI { |
| 345 [self fillPaymentMethodItem:_selectedPaymentMethodItem | 393 [self fillPaymentMethodItem:_selectedPaymentMethodItem |
| 346 withPaymentMethod:_paymentRequest->selected_credit_card()]; | 394 withCreditCard:_paymentRequest->selected_credit_card()]; |
| 347 NSIndexPath* indexPath = | 395 NSIndexPath* indexPath = |
| 348 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem | 396 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem |
| 349 inSectionWithIdentifier:SectionIdentifierPayment]; | 397 inSectionWithIdentifier:SectionIdentifierPayment]; |
| 350 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; | 398 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 351 } | 399 } |
| 352 | 400 |
| 353 #pragma mark - Helper methods | 401 #pragma mark - Helper methods |
| 354 | 402 |
| 355 - (void)fillPaymentSummaryItem:(PriceItem*)item | 403 - (void)fillPaymentSummaryItem:(PriceItem*)item |
| 356 withPaymentItem:(web::PaymentItem)paymentItem | 404 withPaymentItem:(web::PaymentItem)paymentItem |
| 357 withTotalValueChanged:(BOOL)totalValueChanged { | 405 withTotalValueChanged:(BOOL)totalValueChanged { |
| 358 item.item = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER); | 406 item.item = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER); |
| 359 payments::CurrencyFormatter* currencyFormatter = | 407 payments::CurrencyFormatter* currencyFormatter = |
| 360 _paymentRequest->GetOrCreateCurrencyFormatter(); | 408 _paymentRequest->GetOrCreateCurrencyFormatter(); |
| 361 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( | 409 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16( |
| 362 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, | 410 IDS_IOS_PAYMENT_REQUEST_PAYMENT_ITEMS_TOTAL_FORMAT, |
| 363 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), | 411 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()), |
| 364 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value)))); | 412 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value)))); |
| 365 item.notification = | 413 item.notification = |
| 366 totalValueChanged | 414 totalValueChanged |
| 367 ? l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_UPDATED_LABEL) | 415 ? l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_UPDATED_LABEL) |
| 368 : nil; | 416 : nil; |
| 369 } | 417 } |
| 370 | 418 |
| 371 - (void)fillShippingAddressItem:(ShippingAddressItem*)item | 419 - (void)fillShippingAddressItem:(AutofillProfileItem*)item |
| 372 withAddress:(autofill::AutofillProfile*)address { | 420 withAutofillProfile:(autofill::AutofillProfile*)profile { |
| 373 item.name = NameLabelFromAutofillProfile(address); | 421 item.name = GetNameLabelFromAutofillProfile(profile); |
| 374 item.address = AddressLabelFromAutofillProfile(address); | 422 item.address = GetAddressLabelFromAutofillProfile(profile); |
| 375 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(address); | 423 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile); |
| 376 } | 424 } |
| 377 | 425 |
| 378 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item | 426 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item |
| 379 withOption:(web::PaymentShippingOption*)option { | 427 withOption:(web::PaymentShippingOption*)option { |
| 380 item.text = base::SysUTF16ToNSString(option->label); | 428 item.text = base::SysUTF16ToNSString(option->label); |
| 381 payments::CurrencyFormatter* currencyFormatter = | 429 payments::CurrencyFormatter* currencyFormatter = |
| 382 _paymentRequest->GetOrCreateCurrencyFormatter(); | 430 _paymentRequest->GetOrCreateCurrencyFormatter(); |
| 383 item.detailText = SysUTF16ToNSString( | 431 item.detailText = SysUTF16ToNSString( |
| 384 currencyFormatter->Format(base::UTF16ToASCII(option->amount.value))); | 432 currencyFormatter->Format(base::UTF16ToASCII(option->amount.value))); |
| 385 } | 433 } |
| 386 | 434 |
| 387 - (void)fillPaymentMethodItem:(PaymentMethodItem*)item | 435 - (void)fillPaymentMethodItem:(PaymentMethodItem*)item |
| 388 withPaymentMethod:(autofill::CreditCard*)creditCard { | 436 withCreditCard:(autofill::CreditCard*)creditCard { |
| 389 item.methodID = base::SysUTF16ToNSString(creditCard->TypeAndLastFourDigits()); | 437 item.methodID = base::SysUTF16ToNSString(creditCard->TypeAndLastFourDigits()); |
| 390 item.methodDetail = base::SysUTF16ToNSString( | 438 item.methodDetail = base::SysUTF16ToNSString( |
| 391 creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); | 439 creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); |
| 392 int selectedMethodCardTypeIconID = | 440 int selectedMethodCardTypeIconID = |
| 393 autofill::data_util::GetPaymentRequestData(creditCard->type()) | 441 autofill::data_util::GetPaymentRequestData(creditCard->type()) |
| 394 .icon_resource_id; | 442 .icon_resource_id; |
| 395 item.methodTypeIcon = NativeImage(selectedMethodCardTypeIconID); | 443 item.methodTypeIcon = NativeImage(selectedMethodCardTypeIconID); |
| 396 } | 444 } |
| 397 | 445 |
| 446 - (void)fillContactInfoItem:(AutofillProfileItem*)item | |
| 447 withAutofillProfile:(autofill::AutofillProfile*)profile { | |
| 448 item.name = GetNameLabelFromAutofillProfile(profile); | |
| 449 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(profile); | |
| 450 item.email = GetEmailLabelFromAutofillProfile(profile); | |
| 451 } | |
| 452 | |
| 398 #pragma mark UICollectionViewDataSource | 453 #pragma mark UICollectionViewDataSource |
| 399 | 454 |
| 400 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 455 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 401 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | 456 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
| 402 UICollectionViewCell* cell = | 457 UICollectionViewCell* cell = |
| 403 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | 458 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 404 | 459 |
| 405 NSInteger itemType = | 460 NSInteger itemType = |
| 406 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 461 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 407 switch (itemType) { | 462 switch (itemType) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self]; | 502 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self]; |
| 448 break; | 503 break; |
| 449 case ItemTypeShippingOption: | 504 case ItemTypeShippingOption: |
| 450 case ItemTypeSelectShippingOption: | 505 case ItemTypeSelectShippingOption: |
| 451 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self]; | 506 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self]; |
| 452 break; | 507 break; |
| 453 case ItemTypePaymentMethod: | 508 case ItemTypePaymentMethod: |
| 454 case ItemTypeAddPaymentMethod: | 509 case ItemTypeAddPaymentMethod: |
| 455 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self]; | 510 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self]; |
| 456 break; | 511 break; |
| 512 case ItemTypeContactInfo: | |
| 513 case ItemTypeAddContactInfo: | |
| 514 // TODO(crbug.com/602666): Handle displaying contact info selection view. | |
| 515 break; | |
| 457 default: | 516 default: |
| 458 NOTREACHED(); | 517 NOTREACHED(); |
| 459 break; | 518 break; |
| 460 } | 519 } |
| 461 } | 520 } |
| 462 | 521 |
| 463 #pragma mark MDCCollectionViewStylingDelegate | 522 #pragma mark MDCCollectionViewStylingDelegate |
| 464 | 523 |
| 465 - (CGFloat)collectionView:(UICollectionView*)collectionView | 524 - (CGFloat)collectionView:(UICollectionView*)collectionView |
| 466 cellHeightAtIndexPath:(NSIndexPath*)indexPath { | 525 cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
| 467 CollectionViewItem* item = | 526 CollectionViewItem* item = |
| 468 [self.collectionViewModel itemAtIndexPath:indexPath]; | 527 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 469 switch (item.type) { | 528 switch (item.type) { |
| 470 case ItemTypeSpinner: | 529 case ItemTypeSpinner: |
| 471 case ItemTypeShippingAddress: | 530 case ItemTypeShippingAddress: |
| 472 case ItemTypePaymentMethod: | 531 case ItemTypePaymentMethod: |
| 532 case ItemTypeContactInfo: | |
| 473 return [MDCCollectionViewCell | 533 return [MDCCollectionViewCell |
| 474 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 534 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 475 forItem:item]; | 535 forItem:item]; |
| 476 case ItemTypeShippingOption: | 536 case ItemTypeShippingOption: |
| 477 return MDCCellDefaultTwoLineHeight; | 537 return MDCCellDefaultTwoLineHeight; |
| 478 case ItemTypeSummaryPageInfo: | 538 case ItemTypeSummaryPageInfo: |
| 479 case ItemTypeSummaryTotal: | 539 case ItemTypeSummaryTotal: |
| 480 case ItemTypeShippingTitle: | 540 case ItemTypeShippingTitle: |
| 481 case ItemTypeAddShippingAddress: | 541 case ItemTypeAddShippingAddress: |
| 482 case ItemTypeSelectShippingOption: | 542 case ItemTypeSelectShippingOption: |
| 483 case ItemTypePaymentTitle: | 543 case ItemTypePaymentTitle: |
| 484 case ItemTypeAddPaymentMethod: | 544 case ItemTypeAddPaymentMethod: |
| 545 case ItemTypeContactInfoTitle: | |
| 546 case ItemTypeAddContactInfo: | |
| 485 return MDCCellDefaultOneLineHeight; | 547 return MDCCellDefaultOneLineHeight; |
| 486 default: | 548 default: |
| 487 NOTREACHED(); | 549 NOTREACHED(); |
| 488 return MDCCellDefaultOneLineHeight; | 550 return MDCCellDefaultOneLineHeight; |
| 489 } | 551 } |
| 490 } | 552 } |
| 491 | 553 |
| 492 // If there are no payment items to display, there is no effect from touching | 554 // 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. | 555 // the total so there should not be an ink ripple. |
| 494 - (BOOL)collectionView:(UICollectionView*)collectionView | 556 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 495 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 557 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 496 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 558 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 497 if (type == ItemTypeSummaryTotal && | 559 if (type == ItemTypeSummaryTotal && |
| 498 _paymentRequest->payment_details().display_items.empty()) { | 560 _paymentRequest->payment_details().display_items.empty()) { |
| 499 return YES; | 561 return YES; |
| 500 } else { | 562 } else { |
| 501 return NO; | 563 return NO; |
| 502 } | 564 } |
| 503 } | 565 } |
| 504 | 566 |
| 505 @end | 567 @end |
| OLD | NEW |