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

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

Issue 2925053002: Revert of [Payment Request] Moves PaymentRequestViewController to :payments_ui (Closed)
Patch Set: Created 3 years, 6 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/ui/payments/payment_request_view_controller.h" 5 #import "ios/chrome/browser/ui/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"
10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_data_util.h"
12 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/personal_data_manager.h"
16 #include "components/payments/core/currency_formatter.h"
17 #include "components/payments/core/strings_util.h"
9 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
19 #include "ios/chrome/browser/payments/payment_request.h"
20 #import "ios/chrome/browser/payments/payment_request_util.h"
10 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 21 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
11 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 22 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 24 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collec tion_view_controller.h"
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 25 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 26 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
17 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 27 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
28 #import "ios/chrome/browser/ui/payments/cells/autofill_profile_item.h"
18 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h" 29 #import "ios/chrome/browser/ui/payments/cells/page_info_item.h"
30 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h"
31 #import "ios/chrome/browser/ui/payments/cells/payments_text_item.h"
19 #import "ios/chrome/browser/ui/payments/cells/price_item.h" 32 #import "ios/chrome/browser/ui/payments/cells/price_item.h"
20 #import "ios/chrome/browser/ui/payments/payment_request_view_controller_actions. h" 33 #import "ios/chrome/browser/ui/payments/payment_request_view_controller_actions. h"
21 #include "ios/chrome/browser/ui/rtl_geometry.h" 34 #include "ios/chrome/browser/ui/rtl_geometry.h"
22 #include "ios/chrome/browser/ui/uikit_ui_util.h" 35 #include "ios/chrome/browser/ui/uikit_ui_util.h"
23 #include "ios/chrome/grit/ios_strings.h" 36 #include "ios/chrome/grit/ios_strings.h"
24 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 37 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
38 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
25 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 39 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
40 #include "ios/web/public/payments/payment_request.h"
26 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
42 #include "ui/base/resource/resource_bundle.h"
27 43
28 #if !defined(__has_feature) || !__has_feature(objc_arc) 44 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support." 45 #error "This file requires ARC support."
30 #endif 46 #endif
31 47
48 namespace {
49 using ::payment_request_util::GetNameLabelFromAutofillProfile;
50 using ::payment_request_util::GetShippingAddressLabelFromAutofillProfile;
51 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
52 using ::payment_request_util::GetEmailLabelFromAutofillProfile;
53 using ::payment_request_util::GetShippingSectionTitle;
54 using ::payments::GetShippingOptionSectionString;
55 using ::payments::GetShippingAddressSectionString;
56
57 // String used as the "URL" to take the user to the settings page for card and
58 // address options. Needs to be URL-like; otherwise, the link will not appear
59 // as a link in the UI (see setLabelLinkURL: in CollectionViewFooterCell).
60 const char kSettingsURL[] = "settings://card-and-address";
61
62 const CGFloat kFooterCellHorizontalPadding = 16;
63
64 } // namespace
65
32 NSString* const kPaymentRequestCollectionViewID = 66 NSString* const kPaymentRequestCollectionViewID =
33 @"kPaymentRequestCollectionViewID"; 67 @"kPaymentRequestCollectionViewID";
34 68
35 namespace { 69 namespace {
36 const CGFloat kFooterCellHorizontalPadding = 16;
37 70
38 const CGFloat kButtonEdgeInset = 9; 71 const CGFloat kButtonEdgeInset = 9;
39 const CGFloat kSeparatorEdgeInset = 14; 72 const CGFloat kSeparatorEdgeInset = 14;
40 73
41 typedef NS_ENUM(NSInteger, SectionIdentifier) { 74 typedef NS_ENUM(NSInteger, SectionIdentifier) {
42 SectionIdentifierSummary = kSectionIdentifierEnumZero, 75 SectionIdentifierSummary = kSectionIdentifierEnumZero,
43 SectionIdentifierShipping, 76 SectionIdentifierShipping,
44 SectionIdentifierPayment, 77 SectionIdentifierPayment,
45 SectionIdentifierContactInfo, 78 SectionIdentifierContactInfo,
46 SectionIdentifierFooter, 79 SectionIdentifierFooter,
47 }; 80 };
48 81
49 typedef NS_ENUM(NSInteger, ItemType) { 82 typedef NS_ENUM(NSInteger, ItemType) {
50 ItemTypeSummaryPageInfo = kItemTypeEnumZero, 83 ItemTypeSummaryPageInfo = kItemTypeEnumZero,
51 ItemTypeSpinner, 84 ItemTypeSpinner,
52 ItemTypeSummaryTotal, 85 ItemTypeSummaryTotal,
53 ItemTypeShippingTitle, 86 ItemTypeShippingTitle,
54 ItemTypeShippingAddress, 87 ItemTypeShippingAddress,
88 ItemTypeAddShippingAddress,
55 ItemTypeShippingOption, 89 ItemTypeShippingOption,
56 ItemTypePaymentHeader, 90 ItemTypeSelectShippingOption,
91 ItemTypePaymentTitle,
57 ItemTypePaymentMethod, 92 ItemTypePaymentMethod,
58 ItemTypeContactInfoHeader, 93 ItemTypeAddPaymentMethod,
94 ItemTypeContactInfoTitle,
59 ItemTypeContactInfo, 95 ItemTypeContactInfo,
96 ItemTypeAddContactInfo,
60 ItemTypeFooterText, 97 ItemTypeFooterText,
61 }; 98 };
62 99
63 } // namespace 100 } // namespace
64 101
65 @interface PaymentRequestViewController ()< 102 @interface PaymentRequestViewController ()<
66 CollectionViewFooterLinkDelegate,
67 PaymentRequestViewControllerActions> { 103 PaymentRequestViewControllerActions> {
68 UIBarButtonItem* _cancelButton; 104 UIBarButtonItem* _cancelButton;
69 MDCButton* _payButton; 105 MDCButton* _payButton;
106
107 // The PaymentRequest object having a copy of web::PaymentRequest as provided
108 // by the page invoking the Payment Request API. This is a weak pointer and
109 // should outlive this class.
110 PaymentRequest* _paymentRequest;
111
112 __weak PriceItem* _paymentSummaryItem;
113 __weak AutofillProfileItem* _selectedShippingAddressItem;
114 __weak PaymentsTextItem* _selectedShippingOptionItem;
115 __weak PaymentMethodItem* _selectedPaymentMethodItem;
116 __weak AutofillProfileItem* _selectedContactInfoItem;
70 } 117 }
71 118
72 @end 119 @end
73 120
74 @implementation PaymentRequestViewController 121 @implementation PaymentRequestViewController
75 122
76 @synthesize pageFavicon = _pageFavicon; 123 @synthesize pageFavicon = _pageFavicon;
77 @synthesize pageTitle = _pageTitle; 124 @synthesize pageTitle = _pageTitle;
78 @synthesize pageHost = _pageHost; 125 @synthesize pageHost = _pageHost;
79 @synthesize connectionSecure = _connectionSecure; 126 @synthesize connectionSecure = _connectionSecure;
80 @synthesize pending = _pending; 127 @synthesize pending = _pending;
81 @synthesize delegate = _delegate; 128 @synthesize delegate = _delegate;
129 @synthesize showPaymentDataSource = _showPaymentDataSource;
82 @synthesize dataSource = _dataSource; 130 @synthesize dataSource = _dataSource;
83 131
84 - (instancetype)init { 132 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
133 DCHECK(paymentRequest);
85 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 134 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
86 [self setTitle:l10n_util::GetNSString(IDS_PAYMENTS_TITLE)]; 135 [self setTitle:l10n_util::GetNSString(IDS_PAYMENTS_TITLE)];
87 136
88 // Set up leading (cancel) button. 137 // Set up leading (cancel) button.
89 _cancelButton = [[UIBarButtonItem alloc] 138 _cancelButton = [[UIBarButtonItem alloc]
90 initWithTitle:l10n_util::GetNSString(IDS_CANCEL) 139 initWithTitle:l10n_util::GetNSString(IDS_CANCEL)
91 style:UIBarButtonItemStylePlain 140 style:UIBarButtonItemStylePlain
92 target:nil 141 target:nil
93 action:@selector(onCancel)]; 142 action:@selector(onCancel)];
94 [_cancelButton setTitleTextAttributes:@{ 143 [_cancelButton setTitleTextAttributes:@{
95 NSForegroundColorAttributeName : [UIColor lightGrayColor] 144 NSForegroundColorAttributeName : [UIColor lightGrayColor]
96 } 145 }
97 forState:UIControlStateDisabled]; 146 forState:UIControlStateDisabled];
98 [_cancelButton 147 [_cancelButton
99 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)]; 148 setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_CANCEL)];
100 [self navigationItem].leftBarButtonItem = _cancelButton; 149 [self navigationItem].leftBarButtonItem = _cancelButton;
101 150
102 // Set up trailing (pay) button. 151 // Set up trailing (pay) button.
103 _payButton = [[MDCButton alloc] init]; 152 _payButton = [[MDCButton alloc] init];
104 [_payButton setTitle:l10n_util::GetNSString(IDS_PAYMENTS_PAY_BUTTON) 153 [_payButton setTitle:l10n_util::GetNSString(IDS_PAYMENTS_PAY_BUTTON)
105 forState:UIControlStateNormal]; 154 forState:UIControlStateNormal];
106 [_payButton setCustomTitleColor:[UIColor whiteColor]]; 155 [_payButton setCustomTitleColor:[UIColor whiteColor]];
107 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]]; 156 [_payButton setInkColor:[UIColor colorWithWhite:1 alpha:0.2]];
108 [_payButton addTarget:self 157 [_payButton addTarget:self
109 action:@selector(onConfirm) 158 action:@selector(onConfirm)
110 forControlEvents:UIControlEventTouchUpInside]; 159 forControlEvents:UIControlEventTouchUpInside];
111 [_payButton sizeToFit]; 160 [_payButton sizeToFit];
161 [_payButton setEnabled:(paymentRequest->selected_credit_card() != nil)];
112 [_payButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | 162 [_payButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
113 UIViewAutoresizingFlexibleTopMargin | 163 UIViewAutoresizingFlexibleTopMargin |
114 UIViewAutoresizingFlexibleBottomMargin]; 164 UIViewAutoresizingFlexibleBottomMargin];
115 165
116 // The navigation bar will set the rightBarButtonItem's height to the full 166 // The navigation bar will set the rightBarButtonItem's height to the full
117 // height of the bar. We don't want that for the button so we use a UIView 167 // height of the bar. We don't want that for the button so we use a UIView
118 // here to contain the button instead and the button is vertically centered 168 // here to contain the button instead and the button is vertically centered
119 // inside the full bar height. 169 // inside the full bar height.
120 UIView* buttonView = [[UIView alloc] initWithFrame:CGRectZero]; 170 UIView* buttonView = [[UIView alloc] initWithFrame:CGRectZero];
121 [buttonView addSubview:_payButton]; 171 [buttonView addSubview:_payButton];
122 // Navigation bar button items are aligned with the trailing edge of the 172 // Navigation bar button items are aligned with the trailing edge of the
123 // screen. Make the enclosing view larger here. The pay button will be 173 // screen. Make the enclosing view larger here. The pay button will be
124 // aligned with the leading edge of the enclosing view leaving an inset on 174 // aligned with the leading edge of the enclosing view leaving an inset on
125 // the trailing edge. 175 // the trailing edge.
126 CGRect buttonViewBounds = buttonView.bounds; 176 CGRect buttonViewBounds = buttonView.bounds;
127 buttonViewBounds.size.width = 177 buttonViewBounds.size.width =
128 [_payButton frame].size.width + kButtonEdgeInset; 178 [_payButton frame].size.width + kButtonEdgeInset;
129 buttonView.bounds = buttonViewBounds; 179 buttonView.bounds = buttonViewBounds;
130 180
131 UIBarButtonItem* payButtonItem = 181 UIBarButtonItem* payButtonItem =
132 [[UIBarButtonItem alloc] initWithCustomView:buttonView]; 182 [[UIBarButtonItem alloc] initWithCustomView:buttonView];
133 [self navigationItem].rightBarButtonItem = payButtonItem; 183 [self navigationItem].rightBarButtonItem = payButtonItem;
184
185 _paymentRequest = paymentRequest;
186
187 // By default, data source is shown.
188 _showPaymentDataSource = TRUE;
134 } 189 }
135 return self; 190 return self;
136 } 191 }
137 192
138 - (void)onCancel { 193 - (void)onCancel {
139 [_delegate paymentRequestViewControllerDidCancel:self]; 194 [_delegate paymentRequestViewControllerDidCancel:self];
140 } 195 }
141 196
142 - (void)onConfirm { 197 - (void)onConfirm {
143 [_delegate paymentRequestViewControllerDidConfirm:self]; 198 [_delegate paymentRequestViewControllerDidConfirm:self];
144 } 199 }
145 200
146 #pragma mark - Setters
147
148 - (void)setDataSource:(id<PaymentRequestViewControllerDataSource>)dataSource {
149 _dataSource = dataSource;
150 [_payButton setEnabled:[_dataSource canPay]];
151 }
152
153 #pragma mark - CollectionViewController methods 201 #pragma mark - CollectionViewController methods
154 202
155 - (void)loadModel { 203 - (void)loadModel {
156 [super loadModel]; 204 [super loadModel];
157 CollectionViewModel* model = self.collectionViewModel; 205 CollectionViewModel* model = self.collectionViewModel;
158 206
159 // Summary section. 207 // Summary section.
160 [model addSectionWithIdentifier:SectionIdentifierSummary]; 208 [model addSectionWithIdentifier:SectionIdentifierSummary];
161 209
162 PageInfoItem* pageInfo = 210 PageInfoItem* pageInfo =
163 [[PageInfoItem alloc] initWithType:ItemTypeSummaryPageInfo]; 211 [[PageInfoItem alloc] initWithType:ItemTypeSummaryPageInfo];
164 pageInfo.pageFavicon = _pageFavicon; 212 pageInfo.pageFavicon = _pageFavicon;
165 pageInfo.pageTitle = _pageTitle; 213 pageInfo.pageTitle = _pageTitle;
166 pageInfo.pageHost = _pageHost; 214 pageInfo.pageHost = _pageHost;
167 pageInfo.connectionSecure = _connectionSecure; 215 pageInfo.connectionSecure = _connectionSecure;
168 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary]; 216 [model setHeader:pageInfo forSectionWithIdentifier:SectionIdentifierSummary];
169 217
170 if (_pending) { 218 if (_pending) {
171 [_payButton setEnabled:NO]; 219 [_payButton setEnabled:NO];
172 [_cancelButton setEnabled:NO]; 220 [_cancelButton setEnabled:NO];
173 221
174 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner]; 222 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner];
175 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE); 223 statusItem.text = l10n_util::GetNSString(IDS_PAYMENTS_PROCESSING_MESSAGE);
176 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary]; 224 [model addItem:statusItem toSectionWithIdentifier:SectionIdentifierSummary];
177 return; 225 return;
178 } 226 }
179 227
180 [self addPaymentSummaryItem]; 228 PriceItem* paymentSummaryItem =
229 [[PriceItem alloc] initWithType:ItemTypeSummaryTotal];
230 _paymentSummaryItem = paymentSummaryItem;
231 [self fillPaymentSummaryItem:paymentSummaryItem
232 withPaymentItem:_paymentRequest->payment_details().total
233 withTotalValueChanged:NO];
234 if (!_paymentRequest->payment_details().display_items.empty()) {
235 paymentSummaryItem.accessoryType =
236 MDCCollectionViewCellAccessoryDisclosureIndicator;
237 paymentSummaryItem.accessibilityTraits |= UIAccessibilityTraitButton;
238 }
239 [model addItem:paymentSummaryItem
240 toSectionWithIdentifier:SectionIdentifierSummary];
181 241
182 // Shipping section. 242 // Shipping section.
183 if ([_dataSource requestShipping]) { 243 [model addSectionWithIdentifier:SectionIdentifierShipping];
184 [model addSectionWithIdentifier:SectionIdentifierShipping];
185 244
186 CollectionViewItem* shippingSectionHeaderItem = 245 PaymentsTextItem* shippingTitle =
187 [_dataSource shippingSectionHeaderItem]; 246 [[PaymentsTextItem alloc] initWithType:ItemTypeShippingTitle];
188 [shippingSectionHeaderItem setType:ItemTypeShippingTitle]; 247 shippingTitle.text =
189 [model setHeader:shippingSectionHeaderItem 248 GetShippingSectionTitle(_paymentRequest->shipping_type());
190 forSectionWithIdentifier:SectionIdentifierShipping]; 249 [model setHeader:shippingTitle
250 forSectionWithIdentifier:SectionIdentifierShipping];
191 251
192 [self populateShippingSection]; 252 CollectionViewItem* shippingAddressItem = nil;
253 if (_paymentRequest->selected_shipping_profile()) {
254 AutofillProfileItem* selectedShippingAddressItem =
255 [[AutofillProfileItem alloc] initWithType:ItemTypeShippingAddress];
256 shippingAddressItem = selectedShippingAddressItem;
257 _selectedShippingAddressItem = selectedShippingAddressItem;
258 [self fillShippingAddressItem:selectedShippingAddressItem
259 withAutofillProfile:_paymentRequest->selected_shipping_profile()];
260 selectedShippingAddressItem.accessoryType =
261 MDCCollectionViewCellAccessoryDisclosureIndicator;
262 selectedShippingAddressItem.accessibilityTraits |=
263 UIAccessibilityTraitButton;
264 } else {
265 CollectionViewDetailItem* addAddressItem = [[CollectionViewDetailItem alloc]
266 initWithType:ItemTypeAddShippingAddress];
267 shippingAddressItem = addAddressItem;
268 addAddressItem.text = SysUTF16ToNSString(
269 GetShippingAddressSectionString(_paymentRequest->shipping_type()));
270 addAddressItem.detailText = [l10n_util::GetNSString(IDS_ADD)
271 uppercaseStringWithLocale:[NSLocale currentLocale]];
272 addAddressItem.accessibilityTraits |= UIAccessibilityTraitButton;
193 } 273 }
274 [model addItem:shippingAddressItem
275 toSectionWithIdentifier:SectionIdentifierShipping];
276
277 CollectionViewItem* shippingOptionItem = nil;
278 if (_paymentRequest->selected_shipping_option()) {
279 PaymentsTextItem* selectedShippingOptionItem =
280 [[PaymentsTextItem alloc] initWithType:ItemTypeShippingOption];
281 shippingOptionItem = selectedShippingOptionItem;
282
283 _selectedShippingOptionItem = selectedShippingOptionItem;
284 [self fillShippingOptionItem:selectedShippingOptionItem
285 withOption:_paymentRequest->selected_shipping_option()];
286 selectedShippingOptionItem.accessoryType =
287 MDCCollectionViewCellAccessoryDisclosureIndicator;
288 selectedShippingOptionItem.accessibilityTraits |=
289 UIAccessibilityTraitButton;
290 } else {
291 CollectionViewDetailItem* selectShippingOptionItem =
292 [[CollectionViewDetailItem alloc]
293 initWithType:ItemTypeSelectShippingOption];
294 shippingOptionItem = selectShippingOptionItem;
295 selectShippingOptionItem.text = base::SysUTF16ToNSString(
296 GetShippingOptionSectionString(_paymentRequest->shipping_type()));
297 selectShippingOptionItem.accessoryType =
298 MDCCollectionViewCellAccessoryDisclosureIndicator;
299 selectShippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton;
300 }
301 [model addItem:shippingOptionItem
302 toSectionWithIdentifier:SectionIdentifierShipping];
194 303
195 // Payment method section. 304 // Payment method section.
196 [model addSectionWithIdentifier:SectionIdentifierPayment]; 305 [model addSectionWithIdentifier:SectionIdentifierPayment];
197 [self populatePaymentMethodSection]; 306
307 CollectionViewItem* paymentMethodItem = nil;
308 if (_paymentRequest->selected_credit_card()) {
309 PaymentsTextItem* paymentTitle =
310 [[PaymentsTextItem alloc] initWithType:ItemTypePaymentTitle];
311 paymentTitle.text =
312 l10n_util::GetNSString(IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME);
313 [model setHeader:paymentTitle
314 forSectionWithIdentifier:SectionIdentifierPayment];
315
316 PaymentMethodItem* selectedPaymentMethodItem =
317 [[PaymentMethodItem alloc] initWithType:ItemTypePaymentMethod];
318 paymentMethodItem = selectedPaymentMethodItem;
319 _selectedPaymentMethodItem = selectedPaymentMethodItem;
320 [self fillPaymentMethodItem:selectedPaymentMethodItem
321 withCreditCard:_paymentRequest->selected_credit_card()];
322 selectedPaymentMethodItem.accessoryType =
323 MDCCollectionViewCellAccessoryDisclosureIndicator;
324 selectedPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
325 } else {
326 CollectionViewDetailItem* addPaymentMethodItem = [
327 [CollectionViewDetailItem alloc] initWithType:ItemTypeAddPaymentMethod];
328 paymentMethodItem = addPaymentMethodItem;
329 addPaymentMethodItem.text =
330 l10n_util::GetNSString(IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME);
331 addPaymentMethodItem.detailText = [l10n_util::GetNSString(IDS_ADD)
332 uppercaseStringWithLocale:[NSLocale currentLocale]];
333 addPaymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
334 }
335 [model addItem:paymentMethodItem
336 toSectionWithIdentifier:SectionIdentifierPayment];
198 337
199 // Contact Info section. 338 // Contact Info section.
200 if ([_dataSource requestContactInfo]) { 339 [model addSectionWithIdentifier:SectionIdentifierContactInfo];
201 [model addSectionWithIdentifier:SectionIdentifierContactInfo]; 340
202 [self populateContactInfoSection]; 341 CollectionViewItem* contactInfoItem = nil;
342 if (_paymentRequest->selected_contact_profile()) {
343 PaymentsTextItem* contactInfoTitle =
344 [[PaymentsTextItem alloc] initWithType:ItemTypeContactInfoTitle];
345 contactInfoTitle.text =
346 l10n_util::GetNSString(IDS_PAYMENTS_CONTACT_DETAILS_LABEL);
347 [model setHeader:contactInfoTitle
348 forSectionWithIdentifier:SectionIdentifierContactInfo];
349
350 AutofillProfileItem* selectedContactInfoItem =
351 [[AutofillProfileItem alloc] initWithType:ItemTypeContactInfo];
352 contactInfoItem = selectedContactInfoItem;
353 _selectedContactInfoItem = selectedContactInfoItem;
354 [self fillContactInfoItem:selectedContactInfoItem
355 withAutofillProfile:_paymentRequest->selected_contact_profile()];
356 selectedContactInfoItem.accessoryType =
357 MDCCollectionViewCellAccessoryDisclosureIndicator;
358
359 } else {
360 CollectionViewDetailItem* addContactInfoItem =
361 [[CollectionViewDetailItem alloc] initWithType:ItemTypeAddContactInfo];
362 contactInfoItem = addContactInfoItem;
363 addContactInfoItem.text =
364 l10n_util::GetNSString(IDS_PAYMENTS_CONTACT_DETAILS_LABEL);
365 addContactInfoItem.detailText = [l10n_util::GetNSString(IDS_ADD)
366 uppercaseStringWithLocale:[NSLocale currentLocale]];
367 addContactInfoItem.accessibilityTraits |= UIAccessibilityTraitButton;
203 } 368 }
369 [model addItem:contactInfoItem
370 toSectionWithIdentifier:SectionIdentifierContactInfo];
204 371
205 // Footer Text section. 372 // Footer Text section.
206 [model addSectionWithIdentifier:SectionIdentifierFooter]; 373 [model addSectionWithIdentifier:SectionIdentifierFooter];
207 374 CollectionViewFooterItem* footer =
208 CollectionViewFooterItem* footerItem = [_dataSource footerItem]; 375 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooterText];
209 [footerItem setType:ItemTypeFooterText]; 376 if (!_showPaymentDataSource) {
210 footerItem.linkDelegate = self; 377 footer.text =
211 [model addItem:footerItem toSectionWithIdentifier:SectionIdentifierFooter]; 378 l10n_util::GetNSString(IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS);
379 } else if ([[_dataSource authenticatedAccountName] length]) {
380 const base::string16 accountName =
381 base::SysNSStringToUTF16([_dataSource authenticatedAccountName]);
382 const std::string formattedString = l10n_util::GetStringFUTF8(
383 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN, accountName);
384 footer.text = base::SysUTF8ToNSString(formattedString);
385 } else {
386 footer.text = l10n_util::GetNSString(
387 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT);
388 }
389 footer.linkURL = GURL(kSettingsURL);
390 footer.linkDelegate = self;
391 [model addItem:footer toSectionWithIdentifier:SectionIdentifierFooter];
212 } 392 }
213 393
214 - (void)viewDidLoad { 394 - (void)viewDidLoad {
215 [super viewDidLoad]; 395 [super viewDidLoad];
216 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID; 396 self.collectionView.accessibilityIdentifier = kPaymentRequestCollectionViewID;
217 397
218 // Customize collection view settings. 398 // Customize collection view settings.
219 self.styler.cellStyle = MDCCollectionViewCellStyleCard; 399 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
220 self.styler.separatorInset = 400 self.styler.separatorInset =
221 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); 401 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
222 } 402 }
223 403
224 - (void)updatePaymentSummaryItem { 404 - (void)updatePaymentSummaryWithTotalValueChanged:(BOOL)totalValueChanged {
225 CollectionViewModel* model = self.collectionViewModel; 405 [self fillPaymentSummaryItem:_paymentSummaryItem
226 406 withPaymentItem:_paymentRequest->payment_details().total
227 [model removeItemWithType:ItemTypeSummaryTotal 407 withTotalValueChanged:totalValueChanged];
228 fromSectionWithIdentifier:SectionIdentifierSummary];
229
230 [self addPaymentSummaryItem];
231
232 // Reload the item.
233 NSIndexPath* indexPath = 408 NSIndexPath* indexPath =
234 [model indexPathForItemType:ItemTypeSummaryTotal 409 [self.collectionViewModel indexPathForItem:_paymentSummaryItem];
235 sectionIdentifier:SectionIdentifierSummary];
236 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]]; 410 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
237 } 411 }
238 412
239 - (void)updateShippingSection { 413 - (void)updateSelectedShippingAddressUI {
240 CollectionViewModel* model = self.collectionViewModel; 414 [self fillShippingAddressItem:_selectedShippingAddressItem
241 415 withAutofillProfile:_paymentRequest->selected_shipping_profile()];
242 [model removeItemWithType:ItemTypeShippingAddress 416 NSIndexPath* indexPath =
243 fromSectionWithIdentifier:SectionIdentifierShipping]; 417 [self.collectionViewModel indexPathForItem:_selectedShippingAddressItem];
244 418 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
245 if ([model hasItemForItemType:ItemTypeShippingOption
246 sectionIdentifier:SectionIdentifierShipping]) {
247 [model removeItemWithType:ItemTypeShippingOption
248 fromSectionWithIdentifier:SectionIdentifierShipping];
249 }
250
251 [self populateShippingSection];
252
253 // Reload the section.
254 NSInteger sectionIndex =
255 [model sectionForSectionIdentifier:SectionIdentifierShipping];
256 [self.collectionView
257 reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
258
259 // Update the pay button.
260 [_payButton setEnabled:[_dataSource canPay]];
261 } 419 }
262 420
263 - (void)updatePaymentMethodSection { 421 - (void)updateSelectedShippingOptionUI {
264 CollectionViewModel* model = self.collectionViewModel; 422 [self fillShippingOptionItem:_selectedShippingOptionItem
265 423 withOption:_paymentRequest->selected_shipping_option()];
266 [model removeItemWithType:ItemTypePaymentMethod 424 NSIndexPath* indexPath =
267 fromSectionWithIdentifier:SectionIdentifierPayment]; 425 [self.collectionViewModel indexPathForItem:_selectedShippingOptionItem];
268 426 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
269 [self populatePaymentMethodSection];
270
271 // Reload the section.
272 NSInteger sectionIndex =
273 [model sectionForSectionIdentifier:SectionIdentifierPayment];
274 [self.collectionView
275 reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
276
277 // Update the pay button.
278 [_payButton setEnabled:[_dataSource canPay]];
279 } 427 }
280 428
281 - (void)updateContactInfoSection { 429 - (void)updateSelectedPaymentMethodUI {
282 CollectionViewModel* model = self.collectionViewModel; 430 [self fillPaymentMethodItem:_selectedPaymentMethodItem
431 withCreditCard:_paymentRequest->selected_credit_card()];
432 NSIndexPath* indexPath =
433 [self.collectionViewModel indexPathForItem:_selectedPaymentMethodItem];
434 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
435 }
283 436
284 [model removeItemWithType:ItemTypeContactInfo 437 - (void)updateSelectedContactInfoUI {
285 fromSectionWithIdentifier:SectionIdentifierContactInfo]; 438 [self fillContactInfoItem:_selectedContactInfoItem
439 withAutofillProfile:_paymentRequest->selected_contact_profile()];
440 NSIndexPath* indexPath =
441 [self.collectionViewModel indexPathForItem:_selectedContactInfoItem];
442 [self.collectionView reloadItemsAtIndexPaths:@[ indexPath ]];
443 }
286 444
287 [self populateContactInfoSection]; 445 #pragma mark - Helper methods
288 446
289 // Reload the section. 447 - (void)fillPaymentSummaryItem:(PriceItem*)item
290 NSInteger sectionIndex = 448 withPaymentItem:(web::PaymentItem)paymentItem
291 [model sectionForSectionIdentifier:SectionIdentifierContactInfo]; 449 withTotalValueChanged:(BOOL)totalValueChanged {
292 [self.collectionView 450 item.item =
293 reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex]]; 451 base::SysUTF16ToNSString(_paymentRequest->payment_details().total.label);
452 payments::CurrencyFormatter* currencyFormatter =
453 _paymentRequest->GetOrCreateCurrencyFormatter();
454 item.price = SysUTF16ToNSString(l10n_util::GetStringFUTF16(
455 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT,
456 base::UTF8ToUTF16(currencyFormatter->formatted_currency_code()),
457 currencyFormatter->Format(base::UTF16ToASCII(paymentItem.amount.value))));
458 item.notification = totalValueChanged
459 ? l10n_util::GetNSString(IDS_PAYMENTS_UPDATED_LABEL)
460 : nil;
461 }
294 462
295 // Update the pay button. 463 - (void)fillShippingAddressItem:(AutofillProfileItem*)item
296 [_payButton setEnabled:[_dataSource canPay]]; 464 withAutofillProfile:(autofill::AutofillProfile*)profile {
465 DCHECK(profile);
466 item.name = GetNameLabelFromAutofillProfile(*profile);
467 item.address = GetShippingAddressLabelFromAutofillProfile(*profile);
468 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(*profile);
469 }
470
471 - (void)fillShippingOptionItem:(PaymentsTextItem*)item
472 withOption:(web::PaymentShippingOption*)option {
473 item.text = base::SysUTF16ToNSString(option->label);
474 payments::CurrencyFormatter* currencyFormatter =
475 _paymentRequest->GetOrCreateCurrencyFormatter();
476 item.detailText = SysUTF16ToNSString(
477 currencyFormatter->Format(base::UTF16ToASCII(option->amount.value)));
478 }
479
480 - (void)fillPaymentMethodItem:(PaymentMethodItem*)item
481 withCreditCard:(autofill::CreditCard*)creditCard {
482 item.methodID =
483 base::SysUTF16ToNSString(creditCard->NetworkAndLastFourDigits());
484 item.methodDetail = base::SysUTF16ToNSString(
485 creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL));
486 int issuerNetworkIconID =
487 autofill::data_util::GetPaymentRequestData(creditCard->network())
488 .icon_resource_id;
489 item.methodTypeIcon = NativeImage(issuerNetworkIconID);
490 }
491
492 - (void)fillContactInfoItem:(AutofillProfileItem*)item
493 withAutofillProfile:(autofill::AutofillProfile*)profile {
494 DCHECK(profile);
495 item.name = GetNameLabelFromAutofillProfile(*profile);
496 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(*profile);
497 item.email = GetEmailLabelFromAutofillProfile(*profile);
297 } 498 }
298 499
299 #pragma mark - CollectionViewFooterLinkDelegate 500 #pragma mark - CollectionViewFooterLinkDelegate
300 501
301 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)url { 502 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)url {
503 DCHECK_EQ(url, GURL(kSettingsURL)) << "Unknown URL tapped";
302 [_delegate paymentRequestViewControllerDidSelectSettings:self]; 504 [_delegate paymentRequestViewControllerDidSelectSettings:self];
303 } 505 }
304 506
305 #pragma mark - UICollectionViewDataSource 507 #pragma mark UICollectionViewDataSource
306 508
307 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView 509 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
308 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { 510 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
309 UICollectionViewCell* cell = 511 UICollectionViewCell* cell =
310 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; 512 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
311 513
312 NSInteger itemType = 514 NSInteger itemType =
313 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 515 [self.collectionViewModel itemTypeForIndexPath:indexPath];
314 switch (itemType) { 516 switch (itemType) {
315 case ItemTypeShippingAddress: 517 case ItemTypeAddShippingAddress: {
316 case ItemTypePaymentMethod: 518 CollectionViewDetailCell* detailCell =
317 case ItemTypeShippingOption: 519 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell);
318 case ItemTypeContactInfo: { 520 detailCell.detailTextLabel.font = [MDCTypography body2Font];
319 if ([cell isKindOfClass:[CollectionViewDetailCell class]]) { 521 detailCell.detailTextLabel.textColor =
320 CollectionViewDetailCell* detailCell = 522 [[MDCPalette cr_bluePalette] tint700];
321 base::mac::ObjCCastStrict<CollectionViewDetailCell>(cell);
322 detailCell.detailTextLabel.font = [MDCTypography body2Font];
323 detailCell.detailTextLabel.textColor =
324 [[MDCPalette cr_bluePalette] tint700];
325 }
326 break; 523 break;
327 } 524 }
328 case ItemTypeFooterText: { 525 case ItemTypeFooterText: {
329 CollectionViewFooterCell* footerCell = 526 CollectionViewFooterCell* footerCell =
330 base::mac::ObjCCastStrict<CollectionViewFooterCell>(cell); 527 base::mac::ObjCCastStrict<CollectionViewFooterCell>(cell);
331 footerCell.textLabel.font = [MDCTypography body2Font]; 528 footerCell.textLabel.font = [MDCTypography body2Font];
332 footerCell.textLabel.textColor = [[MDCPalette greyPalette] tint600]; 529 footerCell.textLabel.textColor = [[MDCPalette greyPalette] tint600];
333 footerCell.textLabel.shadowColor = nil; // No shadow. 530 footerCell.textLabel.shadowColor = nil; // No shadow.
334 footerCell.horizontalPadding = kFooterCellHorizontalPadding; 531 footerCell.horizontalPadding = kFooterCellHorizontalPadding;
335 break; 532 break;
336 } 533 }
337 default: 534 default:
338 break; 535 break;
339 } 536 }
340 return cell; 537 return cell;
341 } 538 }
342 539
343 #pragma mark - UICollectionViewDelegate 540 #pragma mark UICollectionViewDelegate
344 541
345 - (void)collectionView:(UICollectionView*)collectionView 542 - (void)collectionView:(UICollectionView*)collectionView
346 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 543 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
347 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 544 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
348 545
349 NSInteger itemType = 546 NSInteger itemType =
350 [self.collectionViewModel itemTypeForIndexPath:indexPath]; 547 [self.collectionViewModel itemTypeForIndexPath:indexPath];
351 switch (itemType) { 548 switch (itemType) {
352 case ItemTypeSummaryTotal: 549 case ItemTypeSummaryTotal:
550 if (!_paymentRequest->payment_details().display_items.empty())
353 [_delegate 551 [_delegate
354 paymentRequestViewControllerDidSelectPaymentSummaryItem:self]; 552 paymentRequestViewControllerDidSelectPaymentSummaryItem:self];
355 break; 553 break;
356 case ItemTypeShippingAddress: 554 case ItemTypeShippingAddress:
555 case ItemTypeAddShippingAddress:
357 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self]; 556 [_delegate paymentRequestViewControllerDidSelectShippingAddressItem:self];
358 break; 557 break;
359 case ItemTypeShippingOption: 558 case ItemTypeShippingOption:
559 case ItemTypeSelectShippingOption:
360 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self]; 560 [_delegate paymentRequestViewControllerDidSelectShippingOptionItem:self];
361 break; 561 break;
362 case ItemTypePaymentMethod: 562 case ItemTypePaymentMethod:
563 case ItemTypeAddPaymentMethod:
363 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self]; 564 [_delegate paymentRequestViewControllerDidSelectPaymentMethodItem:self];
364 break; 565 break;
365 case ItemTypeContactInfo: 566 case ItemTypeContactInfo:
567 case ItemTypeAddContactInfo:
366 [_delegate paymentRequestViewControllerDidSelectContactInfoItem:self]; 568 [_delegate paymentRequestViewControllerDidSelectContactInfoItem:self];
367 break; 569 break;
368 case ItemTypeFooterText: 570 case ItemTypeFooterText:
369 // Selecting the footer item should not trigger an action, unless the 571 // Selecting the footer item should not trigger an action, unless the
370 // link was clicked, which will call didTapLinkURL:. 572 // link was clicked, which will call didTapLinkURL:.
371 break; 573 break;
372 default: 574 default:
373 NOTREACHED(); 575 NOTREACHED();
374 break; 576 break;
375 } 577 }
376 } 578 }
377 579
378 #pragma mark - MDCCollectionViewStylingDelegate 580 #pragma mark MDCCollectionViewStylingDelegate
379 581
380 - (CGFloat)collectionView:(UICollectionView*)collectionView 582 - (CGFloat)collectionView:(UICollectionView*)collectionView
381 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 583 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
382 CollectionViewItem* item = 584 CollectionViewItem* item =
383 [self.collectionViewModel itemAtIndexPath:indexPath]; 585 [self.collectionViewModel itemAtIndexPath:indexPath];
384 switch (item.type) { 586 switch (item.type) {
385 case ItemTypeSpinner: 587 case ItemTypeSpinner:
386 case ItemTypeShippingAddress: 588 case ItemTypeShippingAddress:
387 case ItemTypeShippingOption:
388 case ItemTypePaymentMethod: 589 case ItemTypePaymentMethod:
389 case ItemTypeContactInfo: 590 case ItemTypeContactInfo:
390 case ItemTypeFooterText: 591 case ItemTypeFooterText:
391 return [MDCCollectionViewCell 592 return [MDCCollectionViewCell
392 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 593 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
393 forItem:item]; 594 forItem:item];
595 case ItemTypeShippingOption:
596 return MDCCellDefaultTwoLineHeight;
394 case ItemTypeSummaryPageInfo: 597 case ItemTypeSummaryPageInfo:
395 case ItemTypeSummaryTotal: 598 case ItemTypeSummaryTotal:
599 case ItemTypeShippingTitle:
600 case ItemTypeAddShippingAddress:
601 case ItemTypeSelectShippingOption:
602 case ItemTypePaymentTitle:
603 case ItemTypeAddPaymentMethod:
604 case ItemTypeContactInfoTitle:
605 case ItemTypeAddContactInfo:
396 return MDCCellDefaultOneLineHeight; 606 return MDCCellDefaultOneLineHeight;
397 default: 607 default:
398 NOTREACHED(); 608 NOTREACHED();
399 return MDCCellDefaultOneLineHeight; 609 return MDCCellDefaultOneLineHeight;
400 } 610 }
401 } 611 }
402 612
403 - (BOOL)collectionView:(UICollectionView*)collectionView 613 - (BOOL)collectionView:(UICollectionView*)collectionView
404 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 614 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
405 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 615 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
406 // If there are no payment items to display, there is no effect from touching 616 // If there are no payment items to display, there is no effect from touching
407 // the total so there should not be an ink ripple. The footer should also not 617 // the total so there should not be an ink ripple. The footer should also not
408 // have a ripple. 618 // have a ripple.
409 if ((type == ItemTypeSummaryTotal && ![_dataSource hasPaymentItems]) || 619 if ((type == ItemTypeSummaryTotal &&
620 _paymentRequest->payment_details().display_items.empty()) ||
410 (type == ItemTypeFooterText)) { 621 (type == ItemTypeFooterText)) {
411 return YES; 622 return YES;
412 } else { 623 } else {
413 return NO; 624 return NO;
414 } 625 }
415 } 626 }
416 627
417 - (BOOL)collectionView:(UICollectionView*)collectionView 628 - (BOOL)collectionView:(UICollectionView*)collectionView
418 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { 629 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
419 // No background on the footer text item. 630 // No background on the footer text item.
420 NSInteger sectionIdentifier = 631 NSInteger sectionIdentifier =
421 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; 632 [self.collectionViewModel sectionIdentifierForSection:indexPath.section];
422 return sectionIdentifier == SectionIdentifierFooter ? YES : NO; 633 return sectionIdentifier == SectionIdentifierFooter ? YES : NO;
423 } 634 }
424 635
425 #pragma mark - Helper methods
426
427 - (void)addPaymentSummaryItem {
428 CollectionViewItem* item = [_dataSource paymentSummaryItem];
429 [item setType:ItemTypeSummaryTotal];
430 if ([_dataSource hasPaymentItems])
431 item.accessibilityTraits |= UIAccessibilityTraitButton;
432 [self.collectionViewModel addItem:item
433 toSectionWithIdentifier:SectionIdentifierSummary];
434 }
435
436 - (void)populateShippingSection {
437 CollectionViewModel* model = self.collectionViewModel;
438
439 CollectionViewItem* shippingAddressItem = [_dataSource shippingAddressItem];
440 [shippingAddressItem setType:ItemTypeShippingAddress];
441 shippingAddressItem.accessibilityTraits |= UIAccessibilityTraitButton;
442 [model addItem:shippingAddressItem
443 toSectionWithIdentifier:SectionIdentifierShipping];
444
445 if ([_dataSource canShip]) {
446 CollectionViewItem* shippingOptionItem = [_dataSource shippingOptionItem];
447 [shippingOptionItem setType:ItemTypeShippingOption];
448 shippingOptionItem.accessibilityTraits |= UIAccessibilityTraitButton;
449 [model addItem:shippingOptionItem
450 toSectionWithIdentifier:SectionIdentifierShipping];
451 }
452 }
453
454 - (void)populatePaymentMethodSection {
455 CollectionViewModel* model = self.collectionViewModel;
456
457 CollectionViewItem* paymentMethodSectionHeaderItem =
458 [_dataSource paymentMethodSectionHeaderItem];
459 if (paymentMethodSectionHeaderItem) {
460 [paymentMethodSectionHeaderItem setType:ItemTypePaymentHeader];
461 [model setHeader:paymentMethodSectionHeaderItem
462 forSectionWithIdentifier:SectionIdentifierPayment];
463 }
464
465 CollectionViewItem* paymentMethodItem = [_dataSource paymentMethodItem];
466 [paymentMethodItem setType:ItemTypePaymentMethod];
467 paymentMethodItem.accessibilityTraits |= UIAccessibilityTraitButton;
468 [model addItem:paymentMethodItem
469 toSectionWithIdentifier:SectionIdentifierPayment];
470 }
471
472 - (void)populateContactInfoSection {
473 CollectionViewModel* model = self.collectionViewModel;
474
475 CollectionViewItem* contactInfoSectionHeaderItem =
476 [_dataSource contactInfoSectionHeaderItem];
477 if (contactInfoSectionHeaderItem) {
478 [contactInfoSectionHeaderItem setType:ItemTypeContactInfoHeader];
479 [model setHeader:contactInfoSectionHeaderItem
480 forSectionWithIdentifier:SectionIdentifierContactInfo];
481 }
482
483 CollectionViewItem* contactInfoItem = [_dataSource contactInfoItem];
484 [contactInfoItem setType:ItemTypeContactInfo];
485 contactInfoItem.accessibilityTraits |= UIAccessibilityTraitButton;
486 [model addItem:contactInfoItem
487 toSectionWithIdentifier:SectionIdentifierContactInfo];
488 }
489
490 @end 636 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698