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

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

Issue 2712053003: [Payment Request] Displays Contact Info in the payment summary view (Closed)
Patch Set: Created 3 years, 10 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/payments/shipping_address_selection_view_controller. h" 5 #import "ios/chrome/browser/payments/shipping_address_selection_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" 9 #include "base/strings/sys_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
12 #include "ios/chrome/browser/application_context.h" 12 #include "ios/chrome/browser/application_context.h"
13 #import "ios/chrome/browser/payments/cells/autofill_profile_item.h"
13 #import "ios/chrome/browser/payments/cells/payments_text_item.h" 14 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
14 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
15 #import "ios/chrome/browser/payments/payment_request_util.h" 15 #import "ios/chrome/browser/payments/payment_request_util.h"
16 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller_ actions.h" 16 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller_ actions.h"
17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
23 #import "ios/chrome/browser/ui/icons/chrome_icon.h" 23 #import "ios/chrome/browser/ui/icons/chrome_icon.h"
24 #include "ios/chrome/browser/ui/uikit_ui_util.h" 24 #include "ios/chrome/browser/ui/uikit_ui_util.h"
25 #include "ios/chrome/grit/ios_strings.h" 25 #include "ios/chrome/grit/ios_strings.h"
26 #include "ios/chrome/grit/ios_theme_resources.h" 26 #include "ios/chrome/grit/ios_theme_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 28
29 #if !defined(__has_feature) || !__has_feature(objc_arc) 29 #if !defined(__has_feature) || !__has_feature(objc_arc)
30 #error "This file requires ARC support." 30 #error "This file requires ARC support."
31 #endif 31 #endif
32 32
33 using payment_request_util::NameLabelFromAutofillProfile; 33 using payment_request_util::GetNameLabelFromAutofillProfile;
34 using payment_request_util::AddressLabelFromAutofillProfile; 34 using payment_request_util::GetAddressLabelFromAutofillProfile;
35 using payment_request_util::PhoneNumberLabelFromAutofillProfile; 35 using payment_request_util::GetPhoneNumberLabelFromAutofillProfile;
please use gerrit instead 2017/02/26 01:55:25 Ditto
Moe 2017/02/27 16:43:23 Done.
36 36
37 NSString* const kShippingAddressSelectionCollectionViewID = 37 NSString* const kShippingAddressSelectionCollectionViewID =
38 @"kShippingAddressSelectionCollectionViewID"; 38 @"kShippingAddressSelectionCollectionViewID";
39 39
40 namespace { 40 namespace {
41 41
42 const CGFloat kSeparatorEdgeInset = 14; 42 const CGFloat kSeparatorEdgeInset = 14;
43 43
44 typedef NS_ENUM(NSInteger, SectionIdentifier) { 44 typedef NS_ENUM(NSInteger, SectionIdentifier) {
45 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, 45 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero,
46 }; 46 };
47 47
48 typedef NS_ENUM(NSInteger, ItemType) { 48 typedef NS_ENUM(NSInteger, ItemType) {
49 ItemTypeSpinner = kItemTypeEnumZero, 49 ItemTypeSpinner = kItemTypeEnumZero,
50 ItemTypeMessage, 50 ItemTypeMessage,
51 ItemTypeShippingAddress, // This is a repeated item type. 51 ItemTypeShippingAddress, // This is a repeated item type.
52 ItemTypeAddShippingAddress, 52 ItemTypeAddShippingAddress,
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 @interface ShippingAddressSelectionViewController ()< 57 @interface ShippingAddressSelectionViewController ()<
58 ShippingAddressSelectionViewControllerActions> { 58 ShippingAddressSelectionViewControllerActions> {
59 // The PaymentRequest object owning an instance of web::PaymentRequest as 59 // The PaymentRequest object owning an instance of web::PaymentRequest as
60 // provided by the page invoking the Payment Request API. This is a weak 60 // provided by the page invoking the Payment Request API. This is a weak
61 // pointer and should outlive this class. 61 // pointer and should outlive this class.
62 PaymentRequest* _paymentRequest; 62 PaymentRequest* _paymentRequest;
63 63
64 // The currently selected item. May be nil. 64 // The currently selected item. May be nil.
65 __weak ShippingAddressItem* _selectedItem; 65 __weak AutofillProfileItem* _selectedItem;
66 } 66 }
67 67
68 @end 68 @end
69 69
70 @implementation ShippingAddressSelectionViewController 70 @implementation ShippingAddressSelectionViewController
71 71
72 @synthesize pending = _pending; 72 @synthesize pending = _pending;
73 @synthesize errorMessage = _errorMessage; 73 @synthesize errorMessage = _errorMessage;
74 @synthesize delegate = _delegate; 74 @synthesize delegate = _delegate;
75 75
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING); 121 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING);
122 } else { 122 } else {
123 messageItem.text = 123 messageItem.text =
124 payment_request_util::GetShippingAddressSelectorInfoMessage( 124 payment_request_util::GetShippingAddressSelectorInfoMessage(
125 _paymentRequest); 125 _paymentRequest);
126 } 126 }
127 [model addItem:messageItem 127 [model addItem:messageItem
128 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 128 toSectionWithIdentifier:SectionIdentifierShippingAddress];
129 129
130 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) { 130 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) {
131 ShippingAddressItem* item = 131 AutofillProfileItem* item =
132 [[ShippingAddressItem alloc] initWithType:ItemTypeShippingAddress]; 132 [[AutofillProfileItem alloc] initWithType:ItemTypeShippingAddress];
133 item.accessibilityTraits |= UIAccessibilityTraitButton; 133 item.accessibilityTraits |= UIAccessibilityTraitButton;
134 item.name = NameLabelFromAutofillProfile(shippingAddress); 134 item.name = GetNameLabelFromAutofillProfile(shippingAddress);
135 item.address = AddressLabelFromAutofillProfile(shippingAddress); 135 item.address = GetAddressLabelFromAutofillProfile(shippingAddress);
136 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress); 136 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(shippingAddress);
137 if (_paymentRequest->selected_shipping_profile() == shippingAddress) { 137 if (_paymentRequest->selected_shipping_profile() == shippingAddress) {
138 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 138 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
139 _selectedItem = item; 139 _selectedItem = item;
140 } 140 }
141 [model addItem:item 141 [model addItem:item
142 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 142 toSectionWithIdentifier:SectionIdentifierShippingAddress];
143 } 143 }
144 144
145 PaymentsTextItem* addShippingAddress = 145 PaymentsTextItem* addShippingAddress =
146 [[PaymentsTextItem alloc] initWithType:ItemTypeAddShippingAddress]; 146 [[PaymentsTextItem alloc] initWithType:ItemTypeAddShippingAddress];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 CollectionViewItem* item = [model itemAtIndexPath:indexPath]; 204 CollectionViewItem* item = [model itemAtIndexPath:indexPath];
205 if (item.type == ItemTypeShippingAddress) { 205 if (item.type == ItemTypeShippingAddress) {
206 // Update the currently selected cell, if any. 206 // Update the currently selected cell, if any.
207 if (_selectedItem) { 207 if (_selectedItem) {
208 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; 208 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone;
209 [self reconfigureCellsForItems:@[ _selectedItem ] 209 [self reconfigureCellsForItems:@[ _selectedItem ]
210 inSectionWithIdentifier:SectionIdentifierShippingAddress]; 210 inSectionWithIdentifier:SectionIdentifierShippingAddress];
211 } 211 }
212 212
213 // Update the newly selected cell. 213 // Update the newly selected cell.
214 ShippingAddressItem* newlySelectedItem = 214 AutofillProfileItem* newlySelectedItem =
215 base::mac::ObjCCastStrict<ShippingAddressItem>(item); 215 base::mac::ObjCCastStrict<AutofillProfileItem>(item);
216 newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 216 newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
217 [self reconfigureCellsForItems:@[ newlySelectedItem ] 217 [self reconfigureCellsForItems:@[ newlySelectedItem ]
218 inSectionWithIdentifier:SectionIdentifierShippingAddress]; 218 inSectionWithIdentifier:SectionIdentifierShippingAddress];
219 219
220 // Update the reference to the selected item. 220 // Update the reference to the selected item.
221 _selectedItem = newlySelectedItem; 221 _selectedItem = newlySelectedItem;
222 222
223 // Notify the delegate of the selection. 223 // Notify the delegate of the selection.
224 NSInteger index = [model indexInItemTypeForIndexPath:indexPath]; 224 NSInteger index = [model indexInItemTypeForIndexPath:indexPath];
225 DCHECK(index < (NSInteger)_paymentRequest->shipping_profiles().size()); 225 DCHECK(index < (NSInteger)_paymentRequest->shipping_profiles().size());
(...skipping 29 matching lines...) Expand all
255 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 255 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
256 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 256 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
257 if (type == ItemTypeMessage) { 257 if (type == ItemTypeMessage) {
258 return YES; 258 return YES;
259 } else { 259 } else {
260 return NO; 260 return NO;
261 } 261 }
262 } 262 }
263 263
264 @end 264 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698