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

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

Issue 2826593005: [Payment Request] Sever card summary section in the credit card edit form (Closed)
Patch Set: Addressed comments Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/credit_card_edit_view_controller.h" 5 #import "ios/chrome/browser/payments/credit_card_edit_view_controller.h"
6 6
7 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/payments/payment_request_edit_view_controller+intern al.h" 10 #import "ios/chrome/browser/payments/payment_request_edit_view_controller+intern al.h"
11 #import "ios/chrome/browser/payments/payment_request_edit_view_controller_action s.h" 11 #import "ios/chrome/browser/payments/payment_request_edit_view_controller_action s.h"
12 #import "ios/chrome/browser/payments/payment_request_editor_field.h" 12 #import "ios/chrome/browser/payments/payment_request_editor_field.h"
13 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" 13 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h"
14 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" 14 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h" 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item .h"
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item+collec tion_view_controller.h"
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h" 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item .h"
18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
19 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
20 #import "ios/chrome/browser/ui/uikit_ui_util.h" 21 #import "ios/chrome/browser/ui/uikit_ui_util.h"
21 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 22 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
25 #error "This file requires ARC support." 26 #error "This file requires ARC support."
26 #endif 27 #endif
27 28
28 namespace { 29 namespace {
29 30
30 NSString* const kCreditCardEditCollectionViewId = 31 NSString* const kCreditCardEditCollectionViewId =
31 @"kCreditCardEditCollectionViewId"; 32 @"kCreditCardEditCollectionViewId";
32 33
33 typedef NS_ENUM(NSInteger, SectionIdentifier) { 34 typedef NS_ENUM(NSInteger, SectionIdentifier) {
34 SectionIdentifierBillingAddress = kSectionIdentifierEnumStart, 35 SectionIdentifierCardSummary = kSectionIdentifierEnumStart,
36 SectionIdentifierBillingAddress,
35 SectionIdentifierSaveCard, 37 SectionIdentifierSaveCard,
36 }; 38 };
37 39
38 typedef NS_ENUM(NSInteger, ItemType) { 40 typedef NS_ENUM(NSInteger, ItemType) {
39 ItemTypeBillingAddress = kItemTypeEnumStart, 41 ItemTypeCardSummary = kItemTypeEnumStart,
42 ItemTypeBillingAddress,
40 ItemTypeSaveCard, 43 ItemTypeSaveCard,
41 }; 44 };
42 45
43 } // namespace 46 } // namespace
44 47
45 @interface CreditCardEditViewController () { 48 @interface CreditCardEditViewController () {
46 NSArray<EditorField*>* _fields; 49 NSArray<EditorField*>* _fields;
47 50
48 // Indicates whether the credit card being created should be saved locally. 51 // Indicates whether the credit card being created should be saved locally.
49 BOOL _saveCreditCard; 52 BOOL _saveCreditCard;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 for (EditorField* field in _fields) { 151 for (EditorField* field in _fields) {
149 AutofillEditItem* item = field.item; 152 AutofillEditItem* item = field.item;
150 if (field.autofillUIType == AutofillUITypeCreditCardNumber) { 153 if (field.autofillUIType == AutofillUITypeCreditCardNumber) {
151 item.cardTypeIcon = 154 item.cardTypeIcon =
152 [_dataSource cardTypeIconFromCardNumber:field.value]; 155 [_dataSource cardTypeIconFromCardNumber:field.value];
153 } 156 }
154 } 157 }
155 } 158 }
156 } 159 }
157 160
161 - (void)loadHeaderItems {
162 [super loadHeaderItems];
163 CollectionViewModel* model = self.collectionViewModel;
164
165 // Server card summary section.
166 CollectionViewItem* serverCardSummaryItem =
167 [_dataSource serverCardSummaryItem];
168 if (serverCardSummaryItem) {
169 [model addSectionWithIdentifier:SectionIdentifierCardSummary];
170 serverCardSummaryItem.type = ItemTypeCardSummary;
171 [model addItem:serverCardSummaryItem
172 toSectionWithIdentifier:SectionIdentifierCardSummary];
173 }
174 }
175
158 - (void)loadFooterItems { 176 - (void)loadFooterItems {
159 CollectionViewModel* model = self.collectionViewModel; 177 CollectionViewModel* model = self.collectionViewModel;
160 178
161 // Billing Address section. 179 // Billing Address section.
162 [model addSectionWithIdentifier:SectionIdentifierBillingAddress]; 180 [model addSectionWithIdentifier:SectionIdentifierBillingAddress];
163 CollectionViewDetailItem* billingAddressItem = 181 CollectionViewDetailItem* billingAddressItem =
164 [[CollectionViewDetailItem alloc] initWithType:ItemTypeBillingAddress]; 182 [[CollectionViewDetailItem alloc] initWithType:ItemTypeBillingAddress];
165 billingAddressItem.text = [NSString 183 billingAddressItem.text = [NSString
166 stringWithFormat:@"%@*", 184 stringWithFormat:@"%@*",
167 l10n_util::GetNSString(IDS_PAYMENTS_BILLING_ADDRESS)]; 185 l10n_util::GetNSString(IDS_PAYMENTS_BILLING_ADDRESS)];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 278
261 #pragma mark UICollectionViewDelegate 279 #pragma mark UICollectionViewDelegate
262 280
263 - (void)collectionView:(UICollectionView*)collectionView 281 - (void)collectionView:(UICollectionView*)collectionView
264 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 282 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
265 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 283 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
266 284
267 CollectionViewItem* item = 285 CollectionViewItem* item =
268 [self.collectionViewModel itemAtIndexPath:indexPath]; 286 [self.collectionViewModel itemAtIndexPath:indexPath];
269 switch (item.type) { 287 switch (item.type) {
288 case ItemTypeCardSummary:
270 case ItemTypeSaveCard: 289 case ItemTypeSaveCard:
271 break; 290 break;
272 case ItemTypeBillingAddress: { 291 case ItemTypeBillingAddress: {
273 // TODO(crbug.com/602666): Display a list of billing addresses. 292 // TODO(crbug.com/602666): Display a list of billing addresses.
274 break; 293 break;
275 } 294 }
276 default: 295 default:
277 break; 296 break;
278 } 297 }
279 } 298 }
280 299
281 #pragma mark MDCCollectionViewStylingDelegate 300 #pragma mark MDCCollectionViewStylingDelegate
282 301
283 - (CGFloat)collectionView:(UICollectionView*)collectionView 302 - (CGFloat)collectionView:(UICollectionView*)collectionView
284 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 303 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
285 CollectionViewItem* item = 304 CollectionViewItem* item =
286 [self.collectionViewModel itemAtIndexPath:indexPath]; 305 [self.collectionViewModel itemAtIndexPath:indexPath];
287 switch (item.type) { 306 switch (item.type) {
288 case ItemTypeBillingAddress: 307 case ItemTypeBillingAddress:
289 return MDCCellDefaultOneLineHeight; 308 return MDCCellDefaultOneLineHeight;
309 case ItemTypeCardSummary:
290 case ItemTypeSaveCard: 310 case ItemTypeSaveCard:
291 return [MDCCollectionViewCell 311 return [MDCCollectionViewCell
292 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 312 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
293 forItem:item]; 313 forItem:item];
294 default: 314 default:
295 return 315 return
296 [super collectionView:collectionView cellHeightAtIndexPath:indexPath]; 316 [super collectionView:collectionView cellHeightAtIndexPath:indexPath];
297 } 317 }
298 } 318 }
299 319
300 - (BOOL)collectionView:(UICollectionView*)collectionView 320 - (BOOL)collectionView:(UICollectionView*)collectionView
301 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 321 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
302 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 322 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
303 switch (type) { 323 switch (type) {
324 case ItemTypeCardSummary:
304 case ItemTypeSaveCard: 325 case ItemTypeSaveCard:
305 return YES; 326 return YES;
306 default: 327 default:
307 return [super collectionView:collectionView 328 return [super collectionView:collectionView
308 hidesInkViewAtIndexPath:indexPath]; 329 hidesInkViewAtIndexPath:indexPath];
309 } 330 }
310 } 331 }
311 332
312 #pragma mark Switch Actions 333 #pragma mark Switch Actions
313 334
314 - (void)saveCardSwitchToggled:(UISwitch*)sender { 335 - (void)saveCardSwitchToggled:(UISwitch*)sender {
315 _saveCreditCard = sender.isOn; 336 _saveCreditCard = sender.isOn;
316 } 337 }
317 338
318 @end 339 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698