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

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

Issue 2621453002: Selected shipping option in payment summary view + shipping option selection view (Closed)
Patch Set: Addressed comments by lpromero@ and jdonnelley@ Created 3 years, 11 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 #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/objc_property_releaser.h" 9 #include "base/mac/objc_property_releaser.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "components/autofill/core/browser/autofill_data_util.h" 12 #include "components/autofill/core/browser/autofill_data_util.h"
13 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/credit_card.h" 14 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/autofill/core/browser/field_types.h" 15 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/personal_data_manager.h" 16 #include "components/autofill/core/browser/personal_data_manager.h"
17 #include "ios/chrome/browser/application_context.h" 17 #include "ios/chrome/browser/application_context.h"
18 #import "ios/chrome/browser/payments/cells/page_info_item.h" 18 #import "ios/chrome/browser/payments/cells/page_info_item.h"
19 #import "ios/chrome/browser/payments/cells/payment_method_item.h" 19 #import "ios/chrome/browser/payments/cells/payment_method_item.h"
20 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" 20 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
21 #import "ios/chrome/browser/payments/payment_request_utils.h" 21 #import "ios/chrome/browser/payments/payment_request_utils.h"
22 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
25 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
26 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 26 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
27 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 27 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
28 #include "ios/chrome/browser/ui/rtl_geometry.h" 28 #include "ios/chrome/browser/ui/rtl_geometry.h"
29 #include "ios/chrome/grit/ios_strings.h" 29 #include "ios/chrome/grit/ios_strings.h"
30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
31 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" 31 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
32 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
32 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" 33 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
33 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
35 36
36 NSString* const kPaymentRequestCollectionViewId = 37 NSString* const kPaymentRequestCollectionViewId =
37 @"kPaymentRequestCollectionViewId"; 38 @"kPaymentRequestCollectionViewId";
38 39
39 namespace { 40 namespace {
40 41
41 const CGFloat kButtonEdgeInset = 9; 42 const CGFloat kButtonEdgeInset = 9;
42 const CGFloat kSeparatorEdgeInset = 14; 43 const CGFloat kSeparatorEdgeInset = 14;
43 44
44 typedef NS_ENUM(NSInteger, SectionIdentifier) { 45 typedef NS_ENUM(NSInteger, SectionIdentifier) {
45 SectionIdentifierSummary = kSectionIdentifierEnumZero, 46 SectionIdentifierSummary = kSectionIdentifierEnumZero,
46 SectionIdentifierShipping, 47 SectionIdentifierShipping,
47 SectionIdentifierPayment, 48 SectionIdentifierPayment,
48 49
49 }; 50 };
50 51
51 typedef NS_ENUM(NSInteger, ItemType) { 52 typedef NS_ENUM(NSInteger, ItemType) {
52 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 53 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
53 ItemTypeSummaryTotal, 54 ItemTypeSummaryTotal,
54 ItemTypeShippingTitle, 55 ItemTypeShippingTitle,
55 ItemTypeShippingAddress, 56 ItemTypeShippingAddress,
56 ItemTypeAddShippingAddress, 57 ItemTypeAddShippingAddress,
58 ItemTypeShippingOption,
59 ItemTypeSelectShippingOption,
57 ItemTypePaymentTitle, 60 ItemTypePaymentTitle,
58 ItemTypePaymentMethod, 61 ItemTypePaymentMethod,
59 }; 62 };
60 63
61 } // namespace 64 } // namespace
62 65
63 @interface PaymentRequestViewController () { 66 @interface PaymentRequestViewController () {
64 base::WeakNSProtocol<id<PaymentRequestViewControllerDelegate>> _delegate; 67 base::WeakNSProtocol<id<PaymentRequestViewControllerDelegate>> _delegate;
65 base::scoped_nsobject<UIBarButtonItem> _cancelButton; 68 base::scoped_nsobject<UIBarButtonItem> _cancelButton;
66 base::scoped_nsobject<MDCFlatButton> _payButton; 69 base::scoped_nsobject<MDCFlatButton> _payButton;
67 70
68 ShippingAddressItem* _selectedShippingAddressItem; 71 ShippingAddressItem* _selectedShippingAddressItem;
72 CollectionViewTextItem* _selectedShippingOptionItem;
69 73
70 base::mac::ObjCPropertyReleaser 74 base::mac::ObjCPropertyReleaser
71 _propertyReleaser_PaymentRequestViewController; 75 _propertyReleaser_PaymentRequestViewController;
72 } 76 }
73 77
74 // Called when the user presses the cancel button. 78 // Called when the user presses the cancel button.
75 - (void)onCancel; 79 - (void)onCancel;
76 80
77 // Called when the user presses the confirm button. 81 // Called when the user presses the confirm button.
78 - (void)onConfirm; 82 - (void)onConfirm;
79 83
80 @end 84 @end
81 85
82 @implementation PaymentRequestViewController 86 @implementation PaymentRequestViewController
83 87
84 @synthesize paymentRequest = _paymentRequest; 88 @synthesize paymentRequest = _paymentRequest;
85 @synthesize pageFavicon = _pageFavicon; 89 @synthesize pageFavicon = _pageFavicon;
86 @synthesize pageTitle = _pageTitle; 90 @synthesize pageTitle = _pageTitle;
87 @synthesize pageHost = _pageHost; 91 @synthesize pageHost = _pageHost;
92 @synthesize selectedShippingAddress = _selectedShippingAddress;
93 @synthesize selectedShippingOption = _selectedShippingOption;
88 @synthesize selectedPaymentMethod = _selectedPaymentMethod; 94 @synthesize selectedPaymentMethod = _selectedPaymentMethod;
89 @synthesize selectedShippingAddress = _selectedShippingAddress;
90 95
91 - (instancetype)init { 96 - (instancetype)init {
92 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 97 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
93 _propertyReleaser_PaymentRequestViewController.Init( 98 _propertyReleaser_PaymentRequestViewController.Init(
94 self, [PaymentRequestViewController class]); 99 self, [PaymentRequestViewController class]);
95 100
96 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; 101 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
97 102
98 // Set up left (cancel) button. 103 // Set up left (cancel) button.
99 _cancelButton.reset([[UIBarButtonItem alloc] 104 _cancelButton.reset([[UIBarButtonItem alloc]
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary]; 199 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary];
195 200
196 CollectionViewDetailItem* total = [[[CollectionViewDetailItem alloc] 201 CollectionViewDetailItem* total = [[[CollectionViewDetailItem alloc]
197 initWithType:ItemTypeSummaryTotal] autorelease]; 202 initWithType:ItemTypeSummaryTotal] autorelease];
198 total.text = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER); 203 total.text = l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TOTAL_HEADER);
199 NSString* currencyCode = 204 NSString* currencyCode =
200 base::SysUTF16ToNSString(_paymentRequest.details.total.amount.currency); 205 base::SysUTF16ToNSString(_paymentRequest.details.total.amount.currency);
201 NSDecimalNumber* value = [NSDecimalNumber 206 NSDecimalNumber* value = [NSDecimalNumber
202 decimalNumberWithString:SysUTF16ToNSString( 207 decimalNumberWithString:SysUTF16ToNSString(
203 _paymentRequest.details.total.amount.value)]; 208 _paymentRequest.details.total.amount.value)];
204 NSNumberFormatter* currencyFormatter = 209 total.detailText =
205 [[[NSNumberFormatter alloc] init] autorelease]; 210 payment_request_utils::FormattedCurrencyString(value, currencyCode);
206 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
207 [currencyFormatter setCurrencyCode:currencyCode];
208 total.detailText = [currencyFormatter stringFromNumber:value];
209 if (!_paymentRequest.details.display_items.empty()) { 211 if (!_paymentRequest.details.display_items.empty()) {
210 total.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator; 212 total.accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
211 total.accessibilityTraits |= UIAccessibilityTraitButton; 213 total.accessibilityTraits |= UIAccessibilityTraitButton;
212 } 214 }
213 [model addItem:total toSectionWithIdentifier:SectionIdentifierSummary]; 215 [model addItem:total toSectionWithIdentifier:SectionIdentifierSummary];
214 216
215 // Shipping section. 217 // Shipping section.
216 [model addSectionWithIdentifier:SectionIdentifierShipping]; 218 [model addSectionWithIdentifier:SectionIdentifierShipping];
217 CollectionViewTextItem* shippingTitle = [[[CollectionViewTextItem alloc] 219 CollectionViewTextItem* shippingTitle = [[[CollectionViewTextItem alloc]
218 initWithType:ItemTypeShippingTitle] autorelease]; 220 initWithType:ItemTypeShippingTitle] autorelease];
219 shippingTitle.text = 221 shippingTitle.text =
220 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_HEADER); 222 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_HEADER);
221 [model setHeader:shippingTitle 223 [model setHeader:shippingTitle
222 forSectionWithIdentifier:SectionIdentifierShipping]; 224 forSectionWithIdentifier:SectionIdentifierShipping];
223 225
224 CollectionViewItem* shippingItem = nil; 226 CollectionViewItem* shippingAddressItem = nil;
225 if (_selectedShippingAddress) { 227 if (_selectedShippingAddress) {
226 _selectedShippingAddressItem = [[[ShippingAddressItem alloc] 228 _selectedShippingAddressItem = [[[ShippingAddressItem alloc]
227 initWithType:ItemTypeShippingAddress] autorelease]; 229 initWithType:ItemTypeShippingAddress] autorelease];
228 shippingItem = _selectedShippingAddressItem; 230 shippingAddressItem = _selectedShippingAddressItem;
229 [self fillShippingAddressItem:_selectedShippingAddressItem 231 [self fillShippingAddressItem:_selectedShippingAddressItem
230 withAddress:_selectedShippingAddress]; 232 withAddress:_selectedShippingAddress];
231 _selectedShippingAddressItem.accessoryType = 233 _selectedShippingAddressItem.accessoryType =
232 MDCCollectionViewCellAccessoryDisclosureIndicator; 234 MDCCollectionViewCellAccessoryDisclosureIndicator;
233 235
234 } else { 236 } else {
235 CollectionViewDetailItem* addAddressItem = 237 CollectionViewDetailItem* addAddressItem =
236 [[[CollectionViewDetailItem alloc] 238 [[[CollectionViewDetailItem alloc]
237 initWithType:ItemTypeAddShippingAddress] autorelease]; 239 initWithType:ItemTypeAddShippingAddress] autorelease];
238 shippingItem = addAddressItem; 240 shippingAddressItem = addAddressItem;
239 addAddressItem.text = l10n_util::GetNSString( 241 addAddressItem.text = l10n_util::GetNSString(
240 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE); 242 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE);
241 addAddressItem.detailText = [l10n_util::GetNSString( 243 addAddressItem.detailText = [l10n_util::GetNSString(
242 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON) 244 IDS_IOS_PAYMENT_REQUEST_ADD_SHIPPING_ADDRESS_BUTTON)
243 uppercaseStringWithLocale:[NSLocale currentLocale]]; 245 uppercaseStringWithLocale:[NSLocale currentLocale]];
244 } 246 }
245 shippingItem.accessibilityTraits |= UIAccessibilityTraitButton; 247 shippingAddressItem.accessibilityTraits |= UIAccessibilityTraitButton;
246 [model addItem:shippingItem 248 [model addItem:shippingAddressItem
249 toSectionWithIdentifier:SectionIdentifierShipping];
250
251 CollectionViewTextItem* shippingOptionItem = nil;
252 if (_selectedShippingOption) {
253 _selectedShippingOptionItem = [[[CollectionViewTextItem alloc]
254 initWithType:ItemTypeShippingOption] autorelease];
255 shippingOptionItem = _selectedShippingOptionItem;
256 [self fillShippingOptionItem:_selectedShippingOptionItem
257 withOption:_selectedShippingOption];
258 } else {
259 shippingOptionItem = [[[CollectionViewTextItem alloc]
260 initWithType:ItemTypeSelectShippingOption] autorelease];
261 shippingOptionItem.text = l10n_util::GetNSString(
262 IDS_IOS_PAYMENT_REQUEST_SHIPPING_OPTION_SELECTION_TITLE);
263 }
264 shippingOptionItem.accessoryType =
265 MDCCollectionViewCellAccessoryDisclosureIndicator;
266 shippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton;
267 [model addItem:shippingOptionItem
247 toSectionWithIdentifier:SectionIdentifierShipping]; 268 toSectionWithIdentifier:SectionIdentifierShipping];
248 269
249 // Payment method section. 270 // Payment method section.
250 [model addSectionWithIdentifier:SectionIdentifierPayment]; 271 [model addSectionWithIdentifier:SectionIdentifierPayment];
251 272
252 CollectionViewTextItem* paymentTitle = [[[CollectionViewTextItem alloc] 273 CollectionViewTextItem* paymentTitle = [[[CollectionViewTextItem alloc]
253 initWithType:ItemTypePaymentTitle] autorelease]; 274 initWithType:ItemTypePaymentTitle] autorelease];
254 paymentTitle.text = 275 paymentTitle.text =
255 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER); 276 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_PAYMENT_METHOD_HEADER);
256 [model setHeader:paymentTitle 277 [model setHeader:paymentTitle
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 (autofill::AutofillProfile*)shippingAddress { 326 (autofill::AutofillProfile*)shippingAddress {
306 [self setSelectedShippingAddress:shippingAddress]; 327 [self setSelectedShippingAddress:shippingAddress];
307 [self fillShippingAddressItem:_selectedShippingAddressItem 328 [self fillShippingAddressItem:_selectedShippingAddressItem
308 withAddress:shippingAddress]; 329 withAddress:shippingAddress];
309 NSIndexPath* indexPath = 330 NSIndexPath* indexPath =
310 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem 331 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem
311 inSectionWithIdentifier:SectionIdentifierShipping]; 332 inSectionWithIdentifier:SectionIdentifierShipping];
312 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 333 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
313 } 334 }
314 335
336 - (void)updateSelectedShippingOption:
337 (web::PaymentShippingOption*)shippingOption {
338 [self setSelectedShippingOption:shippingOption];
339 [self fillShippingOptionItem:_selectedShippingOptionItem
340 withOption:shippingOption];
341 NSIndexPath* indexPath =
342 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem
343 inSectionWithIdentifier:SectionIdentifierShipping];
344 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
345 }
346
315 #pragma mark - Helper methods 347 #pragma mark - Helper methods
316 348
317 - (void)fillShippingAddressItem:(ShippingAddressItem*)item 349 - (void)fillShippingAddressItem:(ShippingAddressItem*)item
318 withAddress:(autofill::AutofillProfile*)address { 350 withAddress:(autofill::AutofillProfile*)address {
319 item.name = 351 item.name =
320 base::SysUTF16ToNSString(address->GetRawInfo(autofill::NAME_FULL)); 352 base::SysUTF16ToNSString(address->GetRawInfo(autofill::NAME_FULL));
321 item.address = 353 item.address =
322 payment_request_utils::AddressLabelFromAutofillProfile(address); 354 payment_request_utils::AddressLabelFromAutofillProfile(address);
323 item.phoneNumber = base::SysUTF16ToNSString( 355 item.phoneNumber = base::SysUTF16ToNSString(
324 address->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); 356 address->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER));
325 } 357 }
326 358
359 - (void)fillShippingOptionItem:(CollectionViewTextItem*)item
360 withOption:(web::PaymentShippingOption*)option {
361 item.text = base::SysUTF16ToNSString(option->label);
362 NSString* currencyCode = base::SysUTF16ToNSString(option->amount.currency);
363 NSDecimalNumber* value = [NSDecimalNumber
364 decimalNumberWithString:SysUTF16ToNSString(option->amount.value)];
365 item.detailText =
366 payment_request_utils::FormattedCurrencyString(value, currencyCode);
367 }
368
327 #pragma mark UICollectionViewDataSource 369 #pragma mark UICollectionViewDataSource
370
328 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 371 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
329 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 372 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
330 UICollectionViewCell* cell = 373 UICollectionViewCell* cell =
331 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; 374 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
332 375
333 NSInteger itemType = 376 NSInteger itemType =
334 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 377 [self.collectionViewModel itemTypeForIndexPath:indexPath];
335 switch (itemType) { 378 switch (itemType) {
336 case ItemTypeAddShippingAddress: { 379 case ItemTypeAddShippingAddress: {
337 CollectionViewDetailCell* detailCell = 380 CollectionViewDetailCell* detailCell =
338 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell); 381 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell);
339 detailCell.detailTextLabel.font = 382 detailCell.detailTextLabel.font = [MDCTypography body2Font];
340 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
341 detailCell.detailTextLabel.textColor = 383 detailCell.detailTextLabel.textColor =
342 [[MDCPalette cr_bluePalette] tint700]; 384 [[MDCPalette cr_bluePalette] tint700];
343 break; 385 break;
344 } 386 }
387 case ItemTypeShippingOption: {
388 MDCCollectionViewTextCell* textCell =
389 base::mac::ObjCCastStrict<MDCCollectionViewTextCell>(cell);
390 textCell.textLabel.font = [MDCTypography body2Font];
391 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900];
392 textCell.detailTextLabel.font = [MDCTypography body1Font];
393 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint900];
394 break;
395 }
345 default: 396 default:
346 break; 397 break;
347 } 398 }
348 return cell; 399 return cell;
349 } 400 }
350 401
351 #pragma mark UICollectionViewDelegate 402 #pragma mark UICollectionViewDelegate
352 403
353 - (void)collectionView:(UICollectionView*)collectionView 404 - (void)collectionView:(UICollectionView*)collectionView
354 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 405 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
355 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 406 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
356 407
357 NSInteger itemType = 408 NSInteger itemType =
358 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 409 [self.collectionViewModel itemTypeForIndexPath:indexPath];
359 switch (itemType) { 410 switch (itemType) {
360 case ItemTypeSummaryTotal: 411 case ItemTypeSummaryTotal:
361 if (!_paymentRequest.details.display_items.empty()) 412 if (!_paymentRequest.details.display_items.empty())
362 [_delegate paymentRequestViewControllerDisplayPaymentItems]; 413 [_delegate paymentRequestViewControllerDisplayPaymentItems];
363 break; 414 break;
364 case ItemTypeShippingAddress: 415 case ItemTypeShippingAddress:
365 case ItemTypeAddShippingAddress: 416 case ItemTypeAddShippingAddress:
366 [_delegate paymentRequestViewControllerSelectShippingAddress]; 417 [_delegate paymentRequestViewControllerSelectShippingAddress];
367 break; 418 break;
419 case ItemTypeShippingOption:
420 case ItemTypeSelectShippingOption:
421 [_delegate paymentRequestViewControllerSelectShippingOption];
422 break;
368 case ItemTypePaymentMethod: 423 case ItemTypePaymentMethod:
369 [_delegate paymentRequestViewControllerSelectPaymentMethod]; 424 [_delegate paymentRequestViewControllerSelectPaymentMethod];
370 break; 425 break;
371 default: 426 default:
372 NOTREACHED(); 427 NOTREACHED();
373 break; 428 break;
374 } 429 }
375 } 430 }
376 431
377 #pragma mark MDCCollectionViewStylingDelegate 432 #pragma mark MDCCollectionViewStylingDelegate
378 433
379 - (CGFloat)collectionView:(UICollectionView*)collectionView 434 - (CGFloat)collectionView:(UICollectionView*)collectionView
380 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 435 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
381 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 436 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
382 if ((type == ItemTypePaymentMethod && _selectedPaymentMethod) || 437 if ((type == ItemTypePaymentMethod && _selectedPaymentMethod) ||
383 (type == ItemTypeShippingAddress)) { 438 (type == ItemTypeShippingAddress)) {
384 CollectionViewItem* item = 439 CollectionViewItem* item =
385 [self.collectionViewModel itemAtIndexPath:indexPath]; 440 [self.collectionViewModel itemAtIndexPath:indexPath];
386 return [MDCCollectionViewCell 441 return [MDCCollectionViewCell
387 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 442 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
388 forItem:item]; 443 forItem:item];
444 } else if (type == ItemTypeShippingOption) {
445 return MDCCellDefaultTwoLineHeight;
389 } else { 446 } else {
390 return MDCCellDefaultOneLineHeight; 447 return MDCCellDefaultOneLineHeight;
391 } 448 }
392 } 449 }
393 450
394 // If there are no payment items to display, there is no effect from touching 451 // If there are no payment items to display, there is no effect from touching
395 // the total so there should not be an ink ripple. 452 // the total so there should not be an ink ripple.
396 - (BOOL)collectionView:(UICollectionView*)collectionView 453 - (BOOL)collectionView:(UICollectionView*)collectionView
397 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 454 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
398 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 455 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
399 if (type == ItemTypeSummaryTotal && 456 if (type == ItemTypeSummaryTotal &&
400 _paymentRequest.details.display_items.empty()) { 457 _paymentRequest.details.display_items.empty()) {
401 return YES; 458 return YES;
402 } else { 459 } else {
403 return NO; 460 return NO;
404 } 461 }
405 } 462 }
406 463
407 @end 464 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698