OLD | NEW |
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 namespace { |
34 using payment_request_util::AddressLabelFromAutofillProfile; | 34 using ::payment_request_util::GetNameLabelFromAutofillProfile; |
35 using payment_request_util::PhoneNumberLabelFromAutofillProfile; | 35 using ::payment_request_util::GetAddressLabelFromAutofillProfile; |
| 36 using ::payment_request_util::GetPhoneNumberLabelFromAutofillProfile; |
| 37 } // namespace |
36 | 38 |
37 NSString* const kShippingAddressSelectionCollectionViewID = | 39 NSString* const kShippingAddressSelectionCollectionViewID = |
38 @"kShippingAddressSelectionCollectionViewID"; | 40 @"kShippingAddressSelectionCollectionViewID"; |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 const CGFloat kSeparatorEdgeInset = 14; | 44 const CGFloat kSeparatorEdgeInset = 14; |
43 | 45 |
44 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 46 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
45 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, | 47 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, |
46 }; | 48 }; |
47 | 49 |
48 typedef NS_ENUM(NSInteger, ItemType) { | 50 typedef NS_ENUM(NSInteger, ItemType) { |
49 ItemTypeSpinner = kItemTypeEnumZero, | 51 ItemTypeSpinner = kItemTypeEnumZero, |
50 ItemTypeMessage, | 52 ItemTypeMessage, |
51 ItemTypeShippingAddress, // This is a repeated item type. | 53 ItemTypeShippingAddress, // This is a repeated item type. |
52 ItemTypeAddShippingAddress, | 54 ItemTypeAddShippingAddress, |
53 }; | 55 }; |
54 | 56 |
55 } // namespace | 57 } // namespace |
56 | 58 |
57 @interface ShippingAddressSelectionViewController ()< | 59 @interface ShippingAddressSelectionViewController ()< |
58 ShippingAddressSelectionViewControllerActions> { | 60 ShippingAddressSelectionViewControllerActions> { |
59 // The PaymentRequest object owning an instance of web::PaymentRequest as | 61 // The PaymentRequest object owning an instance of web::PaymentRequest as |
60 // provided by the page invoking the Payment Request API. This is a weak | 62 // provided by the page invoking the Payment Request API. This is a weak |
61 // pointer and should outlive this class. | 63 // pointer and should outlive this class. |
62 PaymentRequest* _paymentRequest; | 64 PaymentRequest* _paymentRequest; |
63 | 65 |
64 // The currently selected item. May be nil. | 66 // The currently selected item. May be nil. |
65 __weak ShippingAddressItem* _selectedItem; | 67 __weak AutofillProfileItem* _selectedItem; |
66 } | 68 } |
67 | 69 |
68 @end | 70 @end |
69 | 71 |
70 @implementation ShippingAddressSelectionViewController | 72 @implementation ShippingAddressSelectionViewController |
71 | 73 |
72 @synthesize pending = _pending; | 74 @synthesize pending = _pending; |
73 @synthesize errorMessage = _errorMessage; | 75 @synthesize errorMessage = _errorMessage; |
74 @synthesize delegate = _delegate; | 76 @synthesize delegate = _delegate; |
75 | 77 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING); | 123 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING); |
122 } else { | 124 } else { |
123 messageItem.text = | 125 messageItem.text = |
124 payment_request_util::GetShippingAddressSelectorInfoMessage( | 126 payment_request_util::GetShippingAddressSelectorInfoMessage( |
125 _paymentRequest); | 127 _paymentRequest); |
126 } | 128 } |
127 [model addItem:messageItem | 129 [model addItem:messageItem |
128 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 130 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
129 | 131 |
130 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) { | 132 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) { |
131 ShippingAddressItem* item = | 133 AutofillProfileItem* item = |
132 [[ShippingAddressItem alloc] initWithType:ItemTypeShippingAddress]; | 134 [[AutofillProfileItem alloc] initWithType:ItemTypeShippingAddress]; |
133 item.accessibilityTraits |= UIAccessibilityTraitButton; | 135 item.accessibilityTraits |= UIAccessibilityTraitButton; |
134 item.name = NameLabelFromAutofillProfile(shippingAddress); | 136 item.name = GetNameLabelFromAutofillProfile(shippingAddress); |
135 item.address = AddressLabelFromAutofillProfile(shippingAddress); | 137 item.address = GetAddressLabelFromAutofillProfile(shippingAddress); |
136 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress); | 138 item.phoneNumber = GetPhoneNumberLabelFromAutofillProfile(shippingAddress); |
137 if (_paymentRequest->selected_shipping_profile() == shippingAddress) { | 139 if (_paymentRequest->selected_shipping_profile() == shippingAddress) { |
138 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 140 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
139 _selectedItem = item; | 141 _selectedItem = item; |
140 } | 142 } |
141 [model addItem:item | 143 [model addItem:item |
142 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 144 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
143 } | 145 } |
144 | 146 |
145 PaymentsTextItem* addShippingAddress = | 147 PaymentsTextItem* addShippingAddress = |
146 [[PaymentsTextItem alloc] initWithType:ItemTypeAddShippingAddress]; | 148 [[PaymentsTextItem alloc] initWithType:ItemTypeAddShippingAddress]; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 CollectionViewItem* item = [model itemAtIndexPath:indexPath]; | 206 CollectionViewItem* item = [model itemAtIndexPath:indexPath]; |
205 if (item.type == ItemTypeShippingAddress) { | 207 if (item.type == ItemTypeShippingAddress) { |
206 // Update the currently selected cell, if any. | 208 // Update the currently selected cell, if any. |
207 if (_selectedItem) { | 209 if (_selectedItem) { |
208 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; | 210 _selectedItem.accessoryType = MDCCollectionViewCellAccessoryNone; |
209 [self reconfigureCellsForItems:@[ _selectedItem ] | 211 [self reconfigureCellsForItems:@[ _selectedItem ] |
210 inSectionWithIdentifier:SectionIdentifierShippingAddress]; | 212 inSectionWithIdentifier:SectionIdentifierShippingAddress]; |
211 } | 213 } |
212 | 214 |
213 // Update the newly selected cell. | 215 // Update the newly selected cell. |
214 ShippingAddressItem* newlySelectedItem = | 216 AutofillProfileItem* newlySelectedItem = |
215 base::mac::ObjCCastStrict<ShippingAddressItem>(item); | 217 base::mac::ObjCCastStrict<AutofillProfileItem>(item); |
216 newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 218 newlySelectedItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
217 [self reconfigureCellsForItems:@[ newlySelectedItem ] | 219 [self reconfigureCellsForItems:@[ newlySelectedItem ] |
218 inSectionWithIdentifier:SectionIdentifierShippingAddress]; | 220 inSectionWithIdentifier:SectionIdentifierShippingAddress]; |
219 | 221 |
220 // Update the reference to the selected item. | 222 // Update the reference to the selected item. |
221 _selectedItem = newlySelectedItem; | 223 _selectedItem = newlySelectedItem; |
222 | 224 |
223 // Notify the delegate of the selection. | 225 // Notify the delegate of the selection. |
224 NSInteger index = [model indexInItemTypeForIndexPath:indexPath]; | 226 NSInteger index = [model indexInItemTypeForIndexPath:indexPath]; |
225 DCHECK(index < (NSInteger)_paymentRequest->shipping_profiles().size()); | 227 DCHECK(index < (NSInteger)_paymentRequest->shipping_profiles().size()); |
(...skipping 29 matching lines...) Expand all Loading... |
255 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 257 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
256 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 258 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
257 if (type == ItemTypeMessage) { | 259 if (type == ItemTypeMessage) { |
258 return YES; | 260 return YES; |
259 } else { | 261 } else { |
260 return NO; | 262 return NO; |
261 } | 263 } |
262 } | 264 } |
263 | 265 |
264 @end | 266 @end |
OLD | NEW |