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

Side by Side Diff: ios/chrome/browser/payments/credit_card_edit_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
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"
(...skipping 14 matching lines...) Expand all
25 #if !defined(__has_feature) || !__has_feature(objc_arc) 25 #if !defined(__has_feature) || !__has_feature(objc_arc)
26 #error "This file requires ARC support." 26 #error "This file requires ARC support."
27 #endif 27 #endif
28 28
29 namespace { 29 namespace {
30 30
31 NSString* const kCreditCardEditCollectionViewId = 31 NSString* const kCreditCardEditCollectionViewId =
32 @"kCreditCardEditCollectionViewId"; 32 @"kCreditCardEditCollectionViewId";
33 33
34 typedef NS_ENUM(NSInteger, SectionIdentifier) { 34 typedef NS_ENUM(NSInteger, SectionIdentifier) {
35 SectionIdentifierCardSummary = kSectionIdentifierEnumStart, 35 SectionIdentifierAcceptedMethods = kSectionIdentifierEnumStart,
36 SectionIdentifierCardSummary,
36 SectionIdentifierBillingAddress, 37 SectionIdentifierBillingAddress,
37 SectionIdentifierSaveCard, 38 SectionIdentifierSaveCard,
38 }; 39 };
39 40
40 typedef NS_ENUM(NSInteger, ItemType) { 41 typedef NS_ENUM(NSInteger, ItemType) {
41 ItemTypeCardSummary = kItemTypeEnumStart, 42 ItemTypeAcceptedMethods = kItemTypeEnumStart,
43 ItemTypeCardSummary,
42 ItemTypeBillingAddress, 44 ItemTypeBillingAddress,
43 ItemTypeSaveCard, 45 ItemTypeSaveCard,
44 }; 46 };
45 47
46 } // namespace 48 } // namespace
47 49
48 @interface CreditCardEditViewController () { 50 @interface CreditCardEditViewController () {
49 NSArray<EditorField*>* _fields; 51 NSArray<EditorField*>* _fields;
50 52
51 // Indicates whether the credit card being created should be saved locally. 53 // Indicates whether the credit card being created should be saved locally.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 166
165 // Server card summary section. 167 // Server card summary section.
166 CollectionViewItem* serverCardSummaryItem = 168 CollectionViewItem* serverCardSummaryItem =
167 [_dataSource serverCardSummaryItem]; 169 [_dataSource serverCardSummaryItem];
168 if (serverCardSummaryItem) { 170 if (serverCardSummaryItem) {
169 [model addSectionWithIdentifier:SectionIdentifierCardSummary]; 171 [model addSectionWithIdentifier:SectionIdentifierCardSummary];
170 serverCardSummaryItem.type = ItemTypeCardSummary; 172 serverCardSummaryItem.type = ItemTypeCardSummary;
171 [model addItem:serverCardSummaryItem 173 [model addItem:serverCardSummaryItem
172 toSectionWithIdentifier:SectionIdentifierCardSummary]; 174 toSectionWithIdentifier:SectionIdentifierCardSummary];
173 } 175 }
176
177 // Accepted payment methods section.
178 CollectionViewItem* acceptedMethodsItem =
179 [_dataSource acceptedPaymentMethodsItem];
180 if (acceptedMethodsItem) {
181 [model addSectionWithIdentifier:SectionIdentifierAcceptedMethods];
182 acceptedMethodsItem.type = ItemTypeAcceptedMethods;
183 [model addItem:acceptedMethodsItem
184 toSectionWithIdentifier:SectionIdentifierAcceptedMethods];
185 }
174 } 186 }
175 187
176 - (void)loadFooterItems { 188 - (void)loadFooterItems {
177 CollectionViewModel* model = self.collectionViewModel; 189 CollectionViewModel* model = self.collectionViewModel;
178 190
179 // Billing Address section. 191 // Billing Address section.
180 [model addSectionWithIdentifier:SectionIdentifierBillingAddress]; 192 [model addSectionWithIdentifier:SectionIdentifierBillingAddress];
181 CollectionViewDetailItem* billingAddressItem = 193 CollectionViewDetailItem* billingAddressItem =
182 [[CollectionViewDetailItem alloc] initWithType:ItemTypeBillingAddress]; 194 [[CollectionViewDetailItem alloc] initWithType:ItemTypeBillingAddress];
183 billingAddressItem.text = [NSString 195 billingAddressItem.text = [NSString
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 290
279 #pragma mark UICollectionViewDelegate 291 #pragma mark UICollectionViewDelegate
280 292
281 - (void)collectionView:(UICollectionView*)collectionView 293 - (void)collectionView:(UICollectionView*)collectionView
282 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 294 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
283 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 295 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
284 296
285 CollectionViewItem* item = 297 CollectionViewItem* item =
286 [self.collectionViewModel itemAtIndexPath:indexPath]; 298 [self.collectionViewModel itemAtIndexPath:indexPath];
287 switch (item.type) { 299 switch (item.type) {
300 case ItemTypeAcceptedMethods:
288 case ItemTypeCardSummary: 301 case ItemTypeCardSummary:
289 case ItemTypeSaveCard: 302 case ItemTypeSaveCard:
290 break; 303 break;
291 case ItemTypeBillingAddress: { 304 case ItemTypeBillingAddress: {
292 // TODO(crbug.com/602666): Display a list of billing addresses. 305 // TODO(crbug.com/602666): Display a list of billing addresses.
293 break; 306 break;
294 } 307 }
295 default: 308 default:
296 break; 309 break;
297 } 310 }
298 } 311 }
299 312
300 #pragma mark MDCCollectionViewStylingDelegate 313 #pragma mark MDCCollectionViewStylingDelegate
301 314
302 - (CGFloat)collectionView:(UICollectionView*)collectionView 315 - (CGFloat)collectionView:(UICollectionView*)collectionView
303 cellHeightAtIndexPath:(NSIndexPath*)indexPath { 316 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
304 CollectionViewItem* item = 317 CollectionViewItem* item =
305 [self.collectionViewModel itemAtIndexPath:indexPath]; 318 [self.collectionViewModel itemAtIndexPath:indexPath];
306 switch (item.type) { 319 switch (item.type) {
307 case ItemTypeBillingAddress: 320 case ItemTypeBillingAddress:
308 return MDCCellDefaultOneLineHeight; 321 return MDCCellDefaultOneLineHeight;
322 case ItemTypeAcceptedMethods:
309 case ItemTypeCardSummary: 323 case ItemTypeCardSummary:
310 case ItemTypeSaveCard: 324 case ItemTypeSaveCard:
311 return [MDCCollectionViewCell 325 return [MDCCollectionViewCell
312 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) 326 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
313 forItem:item]; 327 forItem:item];
314 default: 328 default:
315 return 329 return
316 [super collectionView:collectionView cellHeightAtIndexPath:indexPath]; 330 [super collectionView:collectionView cellHeightAtIndexPath:indexPath];
317 } 331 }
318 } 332 }
319 333
320 - (BOOL)collectionView:(UICollectionView*)collectionView 334 - (BOOL)collectionView:(UICollectionView*)collectionView
321 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 335 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
322 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 336 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
323 switch (type) { 337 switch (type) {
338 case ItemTypeAcceptedMethods:
324 case ItemTypeCardSummary: 339 case ItemTypeCardSummary:
325 case ItemTypeSaveCard: 340 case ItemTypeSaveCard:
326 return YES; 341 return YES;
327 default: 342 default:
328 return [super collectionView:collectionView 343 return [super collectionView:collectionView
329 hidesInkViewAtIndexPath:indexPath]; 344 hidesInkViewAtIndexPath:indexPath];
330 } 345 }
331 } 346 }
332 347
348 - (BOOL)collectionView:(UICollectionView*)collectionView
349 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
350 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
351 switch (type) {
352 case ItemTypeAcceptedMethods:
353 return YES;
354 default:
355 return [super collectionView:collectionView
356 shouldHideItemBackgroundAtIndexPath:indexPath];
357 }
358 }
359
333 #pragma mark Switch Actions 360 #pragma mark Switch Actions
334 361
335 - (void)saveCardSwitchToggled:(UISwitch*)sender { 362 - (void)saveCardSwitchToggled:(UISwitch*)sender {
336 _saveCreditCard = sender.isOn; 363 _saveCreditCard = sender.isOn;
337 } 364 }
338 365
339 @end 366 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698