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

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

Issue 2710683012: [Payment Request] Payment request summary view pending state (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/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/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/price_item.h" 20 #import "ios/chrome/browser/payments/cells/price_item.h"
21 #import "ios/chrome/browser/payments/cells/shipping_address_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/ui/autofill/cells/status_item.h"
23 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 24 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
26 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 27 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
27 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 28 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
28 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 29 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
29 #include "ios/chrome/browser/ui/rtl_geometry.h" 30 #include "ios/chrome/browser/ui/rtl_geometry.h"
30 #include "ios/chrome/browser/ui/uikit_ui_util.h" 31 #include "ios/chrome/browser/ui/uikit_ui_util.h"
31 #include "ios/chrome/grit/ios_strings.h" 32 #include "ios/chrome/grit/ios_strings.h"
32 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 33 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
(...skipping 21 matching lines...) Expand all
54 55
55 typedef NS_ENUM(NSInteger, SectionIdentifier) { 56 typedef NS_ENUM(NSInteger, SectionIdentifier) {
56 SectionIdentifierSummary = kSectionIdentifierEnumZero, 57 SectionIdentifierSummary = kSectionIdentifierEnumZero,
57 SectionIdentifierShipping, 58 SectionIdentifierShipping,
58 SectionIdentifierPayment, 59 SectionIdentifierPayment,
59 60
60 }; 61 };
61 62
62 typedef NS_ENUM(NSInteger, ItemType) { 63 typedef NS_ENUM(NSInteger, ItemType) {
63 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 64 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
65 ItemTypeSpinner,
64 ItemTypeSummaryTotal, 66 ItemTypeSummaryTotal,
65 ItemTypeShippingTitle, 67 ItemTypeShippingTitle,
66 ItemTypeShippingAddress, 68 ItemTypeShippingAddress,
67 ItemTypeAddShippingAddress, 69 ItemTypeAddShippingAddress,
68 ItemTypeShippingOption, 70 ItemTypeShippingOption,
69 ItemTypeSelectShippingOption, 71 ItemTypeSelectShippingOption,
70 ItemTypePaymentTitle, 72 ItemTypePaymentTitle,
71 ItemTypePaymentMethod, 73 ItemTypePaymentMethod,
72 ItemTypeAddPaymentMethod, 74 ItemTypeAddPaymentMethod,
73 }; 75 };
(...skipping 21 matching lines...) Expand all
95 // Called when the user presses the confirm button. 97 // Called when the user presses the confirm button.
96 - (void)onConfirm; 98 - (void)onConfirm;
97 99
98 @end 100 @end
99 101
100 @implementation PaymentRequestViewController 102 @implementation PaymentRequestViewController
101 103
102 @synthesize pageFavicon = _pageFavicon; 104 @synthesize pageFavicon = _pageFavicon;
103 @synthesize pageTitle = _pageTitle; 105 @synthesize pageTitle = _pageTitle;
104 @synthesize pageHost = _pageHost; 106 @synthesize pageHost = _pageHost;
107 @synthesize pending = _pending;
105 @synthesize delegate = _delegate; 108 @synthesize delegate = _delegate;
106 109
107 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { 110 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
108 DCHECK(paymentRequest); 111 DCHECK(paymentRequest);
109 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 112 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
110 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; 113 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
111 114
112 // Set up left (cancel) button. 115 // Set up left (cancel) button.
113 _cancelButton = [[UIBarButtonItem alloc] 116 _cancelButton = [[UIBarButtonItem alloc]
114 initWithTitle:l10n_util::GetNSString( 117 initWithTitle:l10n_util::GetNSString(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Summary section. 187 // Summary section.
185 [model addSectionWithIdentifier:SectionIdentifierSummary]; 188 [model addSectionWithIdentifier:SectionIdentifierSummary];
186 189
187 PageInfoItem* pageInfo = 190 PageInfoItem* pageInfo =
188 [[PageInfoItem alloc] initWithType:ItemTypeSummaryPageInfo]; 191 [[PageInfoItem alloc] initWithType:ItemTypeSummaryPageInfo];
189 pageInfo.pageFavicon = _pageFavicon; 192 pageInfo.pageFavicon = _pageFavicon;
190 pageInfo.pageTitle = _pageTitle; 193 pageInfo.pageTitle = _pageTitle;
191 pageInfo.pageHost = _pageHost; 194 pageInfo.pageHost = _pageHost;
192 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary]; 195 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary];
193 196
197 if (_pending) {
198 [_payButton setEnabled:NO];
199 [_cancelButton setEnabled:NO];
200
201 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner];
202 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE);
203 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary];
204 return;
205 }
206
194 _paymentSummaryItem = [[PriceItem alloc] initWithType:ItemTypeSummaryTotal]; 207 _paymentSummaryItem = [[PriceItem alloc] initWithType:ItemTypeSummaryTotal];
195 [self fillPaymentSummaryItem:_paymentSummaryItem 208 [self fillPaymentSummaryItem:_paymentSummaryItem
196 withPaymentItem:_paymentRequest->payment_details().total 209 withPaymentItem:_paymentRequest->payment_details().total
197 withTotalValueChanged:NO]; 210 withTotalValueChanged:NO];
198 if (!_paymentRequest->payment_details().display_items.empty()) { 211 if (!_paymentRequest->payment_details().display_items.empty()) {
199 _paymentSummaryItem.accessoryType = 212 _paymentSummaryItem.accessoryType =
200 MDCCollectionViewCellAccessoryDisclosureIndicator; 213 MDCCollectionViewCellAccessoryDisclosureIndicator;
201 _paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton; 214 _paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton;
202 } 215 }
203 [model addItem:_paymentSummaryItem 216 [model addItem:_paymentSummaryItem
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 464 }
452 } 465 }
453 466
454 #pragma mark MDCCollectionViewStylingDelegate 467 #pragma mark MDCCollectionViewStylingDelegate
455 468
456 - (CGFloat)collectionView:(UICollectionView*)collectionView 469 - (CGFloat)collectionView:(UICollectionView*)collectionView
457 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 470 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
458 CollectionViewItem* item = 471 CollectionViewItem* item =
459 [self.collectionViewModel itemAtIndexPath:indexPath]; 472 [self.collectionViewModel itemAtIndexPath:indexPath];
460 switch (item.type) { 473 switch (item.type) {
474 case ItemTypeSpinner:
461 case ItemTypeShippingAddress: 475 case ItemTypeShippingAddress:
462 case ItemTypePaymentMethod: 476 case ItemTypePaymentMethod:
463 return [MDCCollectionViewCell 477 return [MDCCollectionViewCell
464 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 478 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
465 forItem:item]; 479 forItem:item];
466 case ItemTypeShippingOption: 480 case ItemTypeShippingOption:
467 return MDCCellDefaultTwoLineHeight; 481 return MDCCellDefaultTwoLineHeight;
468 case ItemTypeSummaryPageInfo: 482 case ItemTypeSummaryPageInfo:
469 case ItemTypeSummaryTotal: 483 case ItemTypeSummaryTotal:
470 case ItemTypeShippingTitle: 484 case ItemTypeShippingTitle:
(...skipping 15 matching lines...) Expand all
486 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 500 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
487 if (type == ItemTypeSummaryTotal && 501 if (type == ItemTypeSummaryTotal &&
488 _paymentRequest->payment_details().display_items.empty()) { 502 _paymentRequest->payment_details().display_items.empty()) {
489 return YES; 503 return YES;
490 } else { 504 } else {
491 return NO; 505 return NO;
492 } 506 }
493 } 507 }
494 508
495 @end 509 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698