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

Side by Side Diff: ios/chrome/browser/ui/settings/material_cell_catalog_view_controller.mm

Issue 2825143002: [Payment Request] Accepted credit card type icons in the credit card editor (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
« no previous file with comments | « ios/chrome/browser/payments/credit_card_edit_view_controller_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/settings/material_cell_catalog_view_controller.h" 5 #import "ios/chrome/browser/ui/settings/material_cell_catalog_view_controller.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #import "base/mac/foundation_util.h" 9 #import "base/mac/foundation_util.h"
10 #include "components/autofill/core/browser/autofill_data_util.h" 10 #include "components/autofill/core/browser/autofill_data_util.h"
11 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/grit/components_scaled_resources.h" 12 #include "components/grit/components_scaled_resources.h"
13 #import "ios/chrome/browser/payments/cells/accepted_payment_methods_item.h"
13 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h" 14 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h"
14 #import "ios/chrome/browser/payments/cells/payments_text_item.h" 15 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
15 #import "ios/chrome/browser/payments/cells/price_item.h" 16 #import "ios/chrome/browser/payments/cells/price_item.h"
16 #import "ios/chrome/browser/ui/authentication/account_control_item.h" 17 #import "ios/chrome/browser/ui/authentication/account_control_item.h"
17 #import "ios/chrome/browser/ui/authentication/signin_promo_item.h" 18 #import "ios/chrome/browser/ui/authentication/signin_promo_item.h"
18 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h" 19 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h"
19 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h" 20 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
20 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h" 21 #import "ios/chrome/browser/ui/autofill/cells/autofill_edit_item.h"
21 #import "ios/chrome/browser/ui/autofill/cells/cvc_item.h" 22 #import "ios/chrome/browser/ui/autofill/cells/cvc_item.h"
22 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 23 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
(...skipping 26 matching lines...) Expand all
49 50
50 namespace { 51 namespace {
51 52
52 typedef NS_ENUM(NSInteger, SectionIdentifier) { 53 typedef NS_ENUM(NSInteger, SectionIdentifier) {
53 SectionIdentifierTextCell = kSectionIdentifierEnumZero, 54 SectionIdentifierTextCell = kSectionIdentifierEnumZero,
54 SectionIdentifierDetailCell, 55 SectionIdentifierDetailCell,
55 SectionIdentifierSwitchCell, 56 SectionIdentifierSwitchCell,
56 SectionIdentifierNativeAppCell, 57 SectionIdentifierNativeAppCell,
57 SectionIdentifierAutofill, 58 SectionIdentifierAutofill,
58 SectionIdentifierPayments, 59 SectionIdentifierPayments,
60 SectionIdentifierPaymentsNoBackground,
59 SectionIdentifierAccountCell, 61 SectionIdentifierAccountCell,
60 SectionIdentifierAccountControlCell, 62 SectionIdentifierAccountControlCell,
61 SectionIdentifierFooters, 63 SectionIdentifierFooters,
62 SectionIdentifierContentSuggestionsCell, 64 SectionIdentifierContentSuggestionsCell,
63 }; 65 };
64 66
65 typedef NS_ENUM(NSInteger, ItemType) { 67 typedef NS_ENUM(NSInteger, ItemType) {
66 ItemTypeTextCheckmark = kItemTypeEnumZero, 68 ItemTypeTextCheckmark = kItemTypeEnumZero,
67 ItemTypeTextDetail, 69 ItemTypeTextDetail,
68 ItemTypeText, 70 ItemTypeText,
(...skipping 21 matching lines...) Expand all
90 ItemTypeAutofillStatus, 92 ItemTypeAutofillStatus,
91 ItemTypeAutofillStorageSwitch, 93 ItemTypeAutofillStorageSwitch,
92 ItemTypeAccountControlDynamicHeight, 94 ItemTypeAccountControlDynamicHeight,
93 ItemTypeFooter, 95 ItemTypeFooter,
94 ItemTypeContentSuggestions, 96 ItemTypeContentSuggestions,
95 }; 97 };
96 98
97 // Image fixed horizontal size. 99 // Image fixed horizontal size.
98 const CGFloat kHorizontalImageFixedSize = 40; 100 const CGFloat kHorizontalImageFixedSize = 40;
99 101
102 // Credit Card icon size.
103 const CGFloat kCardTypeIconDimension = 25.0;
104
100 } // namespace 105 } // namespace
101 106
102 @implementation MaterialCellCatalogViewController 107 @implementation MaterialCellCatalogViewController
103 108
104 - (instancetype)init { 109 - (instancetype)init {
105 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; 110 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
106 if (self) { 111 if (self) {
107 [self loadModel]; 112 [self loadModel];
108 } 113 }
109 return self; 114 return self;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 toSectionWithIdentifier:SectionIdentifierAutofill]; 256 toSectionWithIdentifier:SectionIdentifierAutofill];
252 [model addItem:[self statusItemError] 257 [model addItem:[self statusItemError]
253 toSectionWithIdentifier:SectionIdentifierAutofill]; 258 toSectionWithIdentifier:SectionIdentifierAutofill];
254 [model addItem:[self storageSwitchItem] 259 [model addItem:[self storageSwitchItem]
255 toSectionWithIdentifier:SectionIdentifierAutofill]; 260 toSectionWithIdentifier:SectionIdentifierAutofill];
256 261
257 // Payments cells. 262 // Payments cells.
258 [model addSectionWithIdentifier:SectionIdentifierPayments]; 263 [model addSectionWithIdentifier:SectionIdentifierPayments];
259 [model addItem:[self paymentsItemWithWrappingTextandOptionalImage] 264 [model addItem:[self paymentsItemWithWrappingTextandOptionalImage]
260 toSectionWithIdentifier:SectionIdentifierPayments]; 265 toSectionWithIdentifier:SectionIdentifierPayments];
266
261 PriceItem* priceItem1 = 267 PriceItem* priceItem1 =
262 [[PriceItem alloc] initWithType:ItemTypePaymentsSingleLine]; 268 [[PriceItem alloc] initWithType:ItemTypePaymentsSingleLine];
263 priceItem1.item = @"Total"; 269 priceItem1.item = @"Total";
264 priceItem1.notification = @"Updated"; 270 priceItem1.notification = @"Updated";
265 priceItem1.price = @"USD $100.00"; 271 priceItem1.price = @"USD $100.00";
266 [model addItem:priceItem1 toSectionWithIdentifier:SectionIdentifierPayments]; 272 [model addItem:priceItem1 toSectionWithIdentifier:SectionIdentifierPayments];
267 PriceItem* priceItem2 = 273 PriceItem* priceItem2 =
268 [[PriceItem alloc] initWithType:ItemTypePaymentsSingleLine]; 274 [[PriceItem alloc] initWithType:ItemTypePaymentsSingleLine];
269 priceItem2.item = @"Price label is long and should get clipped"; 275 priceItem2.item = @"Price label is long and should get clipped";
270 priceItem2.notification = @"Updated"; 276 priceItem2.notification = @"Updated";
(...skipping 28 matching lines...) Expand all
299 profileItem2.notification = @"Some fields are missing"; 305 profileItem2.notification = @"Some fields are missing";
300 [model addItem:profileItem2 306 [model addItem:profileItem2
301 toSectionWithIdentifier:SectionIdentifierPayments]; 307 toSectionWithIdentifier:SectionIdentifierPayments];
302 AutofillProfileItem* profileItem3 = 308 AutofillProfileItem* profileItem3 =
303 [[AutofillProfileItem alloc] initWithType:ItemTypePaymentsDynamicHeight]; 309 [[AutofillProfileItem alloc] initWithType:ItemTypePaymentsDynamicHeight];
304 profileItem3.address = @"All fields are optional"; 310 profileItem3.address = @"All fields are optional";
305 profileItem3.email = @"foo@bar.com"; 311 profileItem3.email = @"foo@bar.com";
306 [model addItem:profileItem3 312 [model addItem:profileItem3
307 toSectionWithIdentifier:SectionIdentifierPayments]; 313 toSectionWithIdentifier:SectionIdentifierPayments];
308 314
315 // Payments cells with no background.
316 [model addSectionWithIdentifier:SectionIdentifierPaymentsNoBackground];
317 [model addItem:[self acceptedPaymentMethodsItem]
318 toSectionWithIdentifier:SectionIdentifierPaymentsNoBackground];
319
309 // Account cells. 320 // Account cells.
310 [model addSectionWithIdentifier:SectionIdentifierAccountCell]; 321 [model addSectionWithIdentifier:SectionIdentifierAccountCell];
311 [model addItem:[self accountItemDetailWithError] 322 [model addItem:[self accountItemDetailWithError]
312 toSectionWithIdentifier:SectionIdentifierAccountCell]; 323 toSectionWithIdentifier:SectionIdentifierAccountCell];
313 [model addItem:[self accountItemCheckMark] 324 [model addItem:[self accountItemCheckMark]
314 toSectionWithIdentifier:SectionIdentifierAccountCell]; 325 toSectionWithIdentifier:SectionIdentifierAccountCell];
315 [model addItem:[self accountSignInItem] 326 [model addItem:[self accountSignInItem]
316 toSectionWithIdentifier:SectionIdentifierAccountCell]; 327 toSectionWithIdentifier:SectionIdentifierAccountCell];
317 [model addItem:[self coldStateSigninPromoItem] 328 [model addItem:[self coldStateSigninPromoItem]
318 toSectionWithIdentifier:SectionIdentifierAccountCell]; 329 toSectionWithIdentifier:SectionIdentifierAccountCell];
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 default: 411 default:
401 return self.styler.cellStyle; 412 return self.styler.cellStyle;
402 } 413 }
403 } 414 }
404 415
405 - (BOOL)collectionView:(UICollectionView*)collectionView 416 - (BOOL)collectionView:(UICollectionView*)collectionView
406 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath { 417 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
407 NSInteger sectionIdentifier = 418 NSInteger sectionIdentifier =
408 [self.collectionViewModel sectionIdentifierForSection:indexPath.section]; 419 [self.collectionViewModel sectionIdentifierForSection:indexPath.section];
409 switch (sectionIdentifier) { 420 switch (sectionIdentifier) {
421 case SectionIdentifierPaymentsNoBackground:
410 case SectionIdentifierFooters: 422 case SectionIdentifierFooters:
411 // Display the Learn More footer without any background image or 423 // Display the Learn More footer without any background image or
412 // shadowing. 424 // shadowing.
413 return YES; 425 return YES;
414 default: 426 default:
415 return NO; 427 return NO;
416 } 428 }
417 } 429 }
418 430
419 - (BOOL)collectionView:(nonnull UICollectionView*)collectionView 431 - (BOOL)collectionView:(nonnull UICollectionView*)collectionView
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 562
551 - (CollectionViewItem*)paymentsItemWithWrappingTextandOptionalImage { 563 - (CollectionViewItem*)paymentsItemWithWrappingTextandOptionalImage {
552 PaymentsTextItem* item = 564 PaymentsTextItem* item =
553 [[PaymentsTextItem alloc] initWithType:ItemTypePaymentsDynamicHeight]; 565 [[PaymentsTextItem alloc] initWithType:ItemTypePaymentsDynamicHeight];
554 item.text = @"If you want to display a long text that wraps to the next line " 566 item.text = @"If you want to display a long text that wraps to the next line "
555 @"and may need to feature an image this is the cell to use."; 567 @"and may need to feature an image this is the cell to use.";
556 item.image = [UIImage imageNamed:@"app_icon_placeholder"]; 568 item.image = [UIImage imageNamed:@"app_icon_placeholder"];
557 return item; 569 return item;
558 } 570 }
559 571
572 - (CollectionViewItem*)acceptedPaymentMethodsItem {
573 AcceptedPaymentMethodsItem* item = [[AcceptedPaymentMethodsItem alloc]
574 initWithType:ItemTypePaymentsDynamicHeight];
575 item.message = @"Cards accepted:";
576
577 NSMutableArray* cardTypeIcons = [NSMutableArray array];
578 const char* cardTypes[]{autofill::kVisaCard,
579 autofill::kMasterCard,
580 autofill::kAmericanExpressCard,
581 autofill::kJCBCard,
582 autofill::kDinersCard,
583 autofill::kDiscoverCard};
584 for (const std::string& cardType : cardTypes) {
585 autofill::data_util::PaymentRequestData data =
586 autofill::data_util::GetPaymentRequestData(cardType);
587 UIImage* cardTypeIcon =
588 ResizeImage(NativeImage(data.icon_resource_id),
589 CGSizeMake(kCardTypeIconDimension, kCardTypeIconDimension),
590 ProjectionMode::kAspectFillNoClipping);
591 [cardTypeIcons addObject:cardTypeIcon];
592 }
593 item.methodTypeIcons = cardTypeIcons;
594 return item;
595 }
596
560 - (CollectionViewItem*)autofillItemWithMainAndTrailingText { 597 - (CollectionViewItem*)autofillItemWithMainAndTrailingText {
561 AutofillDataItem* item = 598 AutofillDataItem* item =
562 [[AutofillDataItem alloc] initWithType:ItemTypeAutofillDynamicHeight]; 599 [[AutofillDataItem alloc] initWithType:ItemTypeAutofillDynamicHeight];
563 item.text = @"Main Text"; 600 item.text = @"Main Text";
564 item.trailingDetailText = @"Trailing Detail Text"; 601 item.trailingDetailText = @"Trailing Detail Text";
565 item.accessoryType = MDCCollectionViewCellAccessoryNone; 602 item.accessoryType = MDCCollectionViewCellAccessoryNone;
566 return item; 603 return item;
567 } 604 }
568 605
569 - (CollectionViewItem*)autofillItemWithLeadingTextOnly { 606 - (CollectionViewItem*)autofillItemWithLeadingTextOnly {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 - (ContentSuggestionsFooterItem*)contentSuggestionsFooterItem { 740 - (ContentSuggestionsFooterItem*)contentSuggestionsFooterItem {
704 ContentSuggestionsFooterItem* footerItem = 741 ContentSuggestionsFooterItem* footerItem =
705 [[ContentSuggestionsFooterItem alloc] 742 [[ContentSuggestionsFooterItem alloc]
706 initWithType:ItemTypeContentSuggestions 743 initWithType:ItemTypeContentSuggestions
707 title:@"Footer title" 744 title:@"Footer title"
708 block:nil]; 745 block:nil];
709 return footerItem; 746 return footerItem;
710 } 747 }
711 748
712 @end 749 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/credit_card_edit_view_controller_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698