| 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 |
| 24 NSString* const kShippingAddressSelectionCollectionViewId = | 28 NSString* const kShippingAddressSelectionCollectionViewId = |
| 25 @"kShippingAddressSelectionCollectionViewId"; | 29 @"kShippingAddressSelectionCollectionViewId"; |
| 26 | 30 |
| 27 namespace { | 31 namespace { |
| 28 | 32 |
| 29 const CGFloat kSeparatorEdgeInset = 14; | 33 const CGFloat kSeparatorEdgeInset = 14; |
| 30 | 34 |
| 31 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 35 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 32 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, | 36 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, |
| 33 }; | 37 }; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 - (void)loadModel { | 94 - (void)loadModel { |
| 91 [super loadModel]; | 95 [super loadModel]; |
| 92 CollectionViewModel* model = self.collectionViewModel; | 96 CollectionViewModel* model = self.collectionViewModel; |
| 93 | 97 |
| 94 [model addSectionWithIdentifier:SectionIdentifierShippingAddress]; | 98 [model addSectionWithIdentifier:SectionIdentifierShippingAddress]; |
| 95 | 99 |
| 96 for (size_t i = 0; i < _shippingAddresses.size(); ++i) { | 100 for (size_t i = 0; i < _shippingAddresses.size(); ++i) { |
| 97 autofill::AutofillProfile* shippingAddress = _shippingAddresses[i]; | 101 autofill::AutofillProfile* shippingAddress = _shippingAddresses[i]; |
| 98 ShippingAddressItem* item = [[[ShippingAddressItem alloc] | 102 ShippingAddressItem* item = [[[ShippingAddressItem alloc] |
| 99 initWithType:ItemTypeShippingAddress] autorelease]; | 103 initWithType:ItemTypeShippingAddress] autorelease]; |
| 100 item.name = base::SysUTF16ToNSString( | 104 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 101 shippingAddress->GetRawInfo(autofill::NAME_FULL)); | 105 item.name = NameLabelFromAutofillProfile(shippingAddress); |
| 102 item.address = | 106 item.address = AddressLabelFromAutofillProfile(shippingAddress); |
| 103 payment_request_utils::AddressLabelFromAutofillProfile(shippingAddress); | 107 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress); |
| 104 item.phoneNumber = base::SysUTF16ToNSString( | |
| 105 shippingAddress->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); | |
| 106 if (shippingAddress == _selectedShippingAddress) { | 108 if (shippingAddress == _selectedShippingAddress) { |
| 107 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; | 109 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; |
| 108 _selectedItem = item; | 110 _selectedItem = item; |
| 109 } | 111 } |
| 110 | 112 |
| 111 [model addItem:item | 113 [model addItem:item |
| 112 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 114 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
| 113 } | 115 } |
| 114 | 116 |
| 115 CollectionViewTextItem* addShippingAddress = [[[CollectionViewTextItem alloc] | 117 CollectionViewTextItem* addShippingAddress = [[[CollectionViewTextItem alloc] |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } else { | 183 } else { |
| 182 CollectionViewItem* item = | 184 CollectionViewItem* item = |
| 183 [self.collectionViewModel itemAtIndexPath:indexPath]; | 185 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 184 return [MDCCollectionViewCell | 186 return [MDCCollectionViewCell |
| 185 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 187 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 186 forItem:item]; | 188 forItem:item]; |
| 187 } | 189 } |
| 188 } | 190 } |
| 189 | 191 |
| 190 @end | 192 @end |
| OLD | NEW |