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 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "components/autofill/core/browser/autofill_profile.h" | 11 #include "components/autofill/core/browser/autofill_profile.h" |
12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
13 #include "ios/chrome/browser/application_context.h" | 13 #include "ios/chrome/browser/application_context.h" |
14 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | 14 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" |
15 #import "ios/chrome/browser/payments/payment_request_utils.h" | 15 #import "ios/chrome/browser/payments/payment_request_utils.h" |
16 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 16 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
20 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 20 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
21 #include "ios/chrome/grit/ios_strings.h" | 21 #include "ios/chrome/grit/ios_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 | 23 |
24 using payment_request_utils::NameLabelFromAutofillProfile; | |
25 using payment_request_utils::AddressLabelFromAutofillProfile; | |
26 using payment_request_utils::PhoneNumberLabelFromAutofillProfile; | |
27 | |
28 NSString* const kShippingAddressSelectionCollectionViewId = | 24 NSString* const kShippingAddressSelectionCollectionViewId = |
29 @"kShippingAddressSelectionCollectionViewId"; | 25 @"kShippingAddressSelectionCollectionViewId"; |
30 | 26 |
31 namespace { | 27 namespace { |
32 | 28 |
33 const CGFloat kSeparatorEdgeInset = 14; | 29 const CGFloat kSeparatorEdgeInset = 14; |
34 | 30 |
35 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 31 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
36 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, | 32 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, |
37 }; | 33 }; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 - (void)loadModel { | 90 - (void)loadModel { |
95 [super loadModel]; | 91 [super loadModel]; |
96 CollectionViewModel* model = self.collectionViewModel; | 92 CollectionViewModel* model = self.collectionViewModel; |
97 | 93 |
98 [model addSectionWithIdentifier:SectionIdentifierShippingAddress]; | 94 [model addSectionWithIdentifier:SectionIdentifierShippingAddress]; |
99 | 95 |
100 for (size_t i = 0; i < _shippingAddresses.size(); ++i) { | 96 for (size_t i = 0; i < _shippingAddresses.size(); ++i) { |
101 autofill::AutofillProfile* shippingAddress = _shippingAddresses[i]; | 97 autofill::AutofillProfile* shippingAddress = _shippingAddresses[i]; |
102 ShippingAddressItem* item = [[[ShippingAddressItem alloc] | 98 ShippingAddressItem* item = [[[ShippingAddressItem alloc] |
103 initWithType:ItemTypeShippingAddress] autorelease]; | 99 initWithType:ItemTypeShippingAddress] autorelease]; |
104 item.accessibilityTraits |= UIAccessibilityTraitButton; | 100 item.name = base::SysUTF16ToNSString( |
105 item.name = NameLabelFromAutofillProfile(shippingAddress); | 101 shippingAddress->GetRawInfo(autofill::NAME_FULL)); |
106 item.address = AddressLabelFromAutofillProfile(shippingAddress); | 102 item.address = |
107 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress); | 103 payment_request_utils::AddressLabelFromAutofillProfile(shippingAddress); |
| 104 item.phoneNumber = base::SysUTF16ToNSString( |
| 105 shippingAddress->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
108 if (shippingAddress == _selectedShippingAddress) { | 106 if (shippingAddress == _selectedShippingAddress) { |
109 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 107 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
110 _selectedItem = item; | 108 _selectedItem = item; |
111 } | 109 } |
112 | 110 |
113 [model addItem:item | 111 [model addItem:item |
114 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 112 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
115 } | 113 } |
116 | 114 |
117 CollectionViewTextItem* addShippingAddress = [[[CollectionViewTextItem alloc] | 115 CollectionViewTextItem* addShippingAddress = [[[CollectionViewTextItem alloc] |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } else { | 181 } else { |
184 CollectionViewItem* item = | 182 CollectionViewItem* item = |
185 [self.collectionViewModel itemAtIndexPath:indexPath]; | 183 [self.collectionViewModel itemAtIndexPath:indexPath]; |
186 return [MDCCollectionViewCell | 184 return [MDCCollectionViewCell |
187 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 185 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
188 forItem:item]; | 186 forItem:item]; |
189 } | 187 } |
190 } | 188 } |
191 | 189 |
192 @end | 190 @end |
OLD | NEW |