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

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

Issue 2938673003: [Payment Request] Selector view edit mode (Closed)
Patch Set: Addressed comments 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 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 #include <vector> 5 #include <vector>
6 6
7 #import "ios/chrome/browser/ui/payments/billing_address_selection_mediator.h" 7 #import "ios/chrome/browser/ui/payments/billing_address_selection_mediator.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 20 matching lines...) Expand all
31 31
32 // The PaymentRequest object owning an instance of web::PaymentRequest as 32 // The PaymentRequest object owning an instance of web::PaymentRequest as
33 // provided by the page invoking the Payment Request API. This is a weak 33 // provided by the page invoking the Payment Request API. This is a weak
34 // pointer and should outlive this class. 34 // pointer and should outlive this class.
35 @property(nonatomic, assign) PaymentRequest* paymentRequest; 35 @property(nonatomic, assign) PaymentRequest* paymentRequest;
36 36
37 // The selected billing address, if any. 37 // The selected billing address, if any.
38 @property(nonatomic, assign) autofill::AutofillProfile* selectedBillingProfile; 38 @property(nonatomic, assign) autofill::AutofillProfile* selectedBillingProfile;
39 39
40 // The selectable items to display in the collection. 40 // The selectable items to display in the collection.
41 @property(nonatomic, strong) NSArray<AutofillProfileItem*>* items; 41 @property(nonatomic, strong) NSMutableArray<AutofillProfileItem*>* items;
42 42
43 @end 43 @end
44 44
45 @implementation BillingAddressSelectionMediator 45 @implementation BillingAddressSelectionMediator
46 46
47 @synthesize state = _state; 47 @synthesize state = _state;
48 @synthesize selectedItemIndex = _selectedItemIndex; 48 @synthesize selectedItemIndex = _selectedItemIndex;
49 @synthesize paymentRequest = _paymentRequest; 49 @synthesize paymentRequest = _paymentRequest;
50 @synthesize selectedBillingProfile = _selectedBillingProfile; 50 @synthesize selectedBillingProfile = _selectedBillingProfile;
51 @synthesize items = _items; 51 @synthesize items = _items;
52 52
53 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest 53 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest
54 selectedBillingProfile: 54 selectedBillingProfile:
55 (autofill::AutofillProfile*)selectedBillingProfile { 55 (autofill::AutofillProfile*)selectedBillingProfile {
56 self = [super init]; 56 self = [super init];
57 if (self) { 57 if (self) {
58 DCHECK(paymentRequest); 58 DCHECK(paymentRequest);
59 _paymentRequest = paymentRequest; 59 _paymentRequest = paymentRequest;
60 _selectedBillingProfile = selectedBillingProfile; 60 _selectedBillingProfile = selectedBillingProfile;
61 _selectedItemIndex = NSUIntegerMax; 61 _selectedItemIndex = NSUIntegerMax;
62 _items = [self createItems]; 62 [self loadItems];
63 } 63 }
64 return self; 64 return self;
65 } 65 }
66 66
67 #pragma mark - PaymentRequestSelectorViewControllerDataSource 67 #pragma mark - PaymentRequestSelectorViewControllerDataSource
68 68
69 - (BOOL)allowsEditMode {
70 return YES;
71 }
72
69 - (CollectionViewItem*)headerItem { 73 - (CollectionViewItem*)headerItem {
70 return nil; 74 return nil;
71 } 75 }
72 76
73 - (NSArray<CollectionViewItem*>*)selectableItems { 77 - (NSArray<CollectionViewItem*>*)selectableItems {
74 return self.items; 78 return self.items;
75 } 79 }
76 80
77 - (CollectionViewItem*)addButtonItem { 81 - (CollectionViewItem*)addButtonItem {
78 PaymentsTextItem* addButtonItem = [[PaymentsTextItem alloc] init]; 82 PaymentsTextItem* addButtonItem = [[PaymentsTextItem alloc] init];
79 addButtonItem.text = l10n_util::GetNSString(IDS_PAYMENTS_ADD_ADDRESS); 83 addButtonItem.text = l10n_util::GetNSString(IDS_PAYMENTS_ADD_ADDRESS);
80 addButtonItem.image = NativeImage(IDR_IOS_PAYMENTS_ADD); 84 addButtonItem.image = NativeImage(IDR_IOS_PAYMENTS_ADD);
81 return addButtonItem; 85 return addButtonItem;
82 } 86 }
83 87
84 #pragma mark - Helper methods 88 #pragma mark - Public methods
85 89
86 - (NSArray<AutofillProfileItem*>*)createItems { 90 - (void)loadItems {
87 const std::vector<autofill::AutofillProfile*>& billingProfiles = 91 const std::vector<autofill::AutofillProfile*>& billingProfiles =
88 _paymentRequest->billing_profiles(); 92 _paymentRequest->billing_profiles();
89 93
90 NSMutableArray<AutofillProfileItem*>* items = 94 _items = [NSMutableArray arrayWithCapacity:billingProfiles.size()];
91 [NSMutableArray arrayWithCapacity:billingProfiles.size()];
92 for (size_t index = 0; index < billingProfiles.size(); ++index) { 95 for (size_t index = 0; index < billingProfiles.size(); ++index) {
93 autofill::AutofillProfile* billingProfile = billingProfiles[index]; 96 autofill::AutofillProfile* billingProfile = billingProfiles[index];
94 DCHECK(billingProfile); 97 DCHECK(billingProfile);
95 AutofillProfileItem* item = [[AutofillProfileItem alloc] init]; 98 AutofillProfileItem* item = [[AutofillProfileItem alloc] init];
96 item.name = GetNameLabelFromAutofillProfile(*billingProfile); 99 item.name = GetNameLabelFromAutofillProfile(*billingProfile);
97 item.address = GetBillingAddressLabelFromAutofillProfile(*billingProfile); 100 item.address = GetBillingAddressLabelFromAutofillProfile(*billingProfile);
98 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(*billingProfile); 101 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(*billingProfile);
99 if (self.selectedBillingProfile == billingProfile) 102 if (self.selectedBillingProfile == billingProfile)
100 _selectedItemIndex = index; 103 _selectedItemIndex = index;
101 104
102 [items addObject:item]; 105 [_items addObject:item];
103 } 106 }
104
105 return items;
106 } 107 }
107 108
108 @end 109 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698