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/payments_text_item.h" | 14 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
15 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | 15 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" |
16 #import "ios/chrome/browser/payments/payment_request_util.h" | 16 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 17 #import "ios/chrome/browser/payments/shipping_address_selection_view_controller_
actions.h" |
17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 18 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
18 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 19 #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" | 20 #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
" | 21 #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" | 22 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 23 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
23 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 24 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
24 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 25 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
25 #include "ios/chrome/grit/ios_strings.h" | 26 #include "ios/chrome/grit/ios_strings.h" |
26 #include "ios/chrome/grit/ios_theme_resources.h" | 27 #include "ios/chrome/grit/ios_theme_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 | 29 |
29 using payment_request_util::NameLabelFromAutofillProfile; | 30 using payment_request_util::NameLabelFromAutofillProfile; |
30 using payment_request_util::AddressLabelFromAutofillProfile; | 31 using payment_request_util::AddressLabelFromAutofillProfile; |
31 using payment_request_util::PhoneNumberLabelFromAutofillProfile; | 32 using payment_request_util::PhoneNumberLabelFromAutofillProfile; |
32 | 33 |
33 NSString* const kShippingAddressSelectionCollectionViewId = | 34 NSString* const kShippingAddressSelectionCollectionViewID = |
34 @"kShippingAddressSelectionCollectionViewId"; | 35 @"kShippingAddressSelectionCollectionViewID"; |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 const CGFloat kSeparatorEdgeInset = 14; | 39 const CGFloat kSeparatorEdgeInset = 14; |
39 | 40 |
40 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 41 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
41 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, | 42 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, |
42 }; | 43 }; |
43 | 44 |
44 typedef NS_ENUM(NSInteger, ItemType) { | 45 typedef NS_ENUM(NSInteger, ItemType) { |
45 ItemTypeSpinner = kItemTypeEnumZero, | 46 ItemTypeSpinner = kItemTypeEnumZero, |
46 ItemTypeMessage, | 47 ItemTypeMessage, |
47 ItemTypeShippingAddress, // This is a repeated item type. | 48 ItemTypeShippingAddress, // This is a repeated item type. |
48 ItemTypeAddShippingAddress, | 49 ItemTypeAddShippingAddress, |
49 }; | 50 }; |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
53 @interface ShippingAddressSelectionViewController () { | 54 @interface ShippingAddressSelectionViewController ()< |
| 55 ShippingAddressSelectionViewControllerActions> { |
54 base::WeakNSProtocol<id<ShippingAddressSelectionViewControllerDelegate>> | 56 base::WeakNSProtocol<id<ShippingAddressSelectionViewControllerDelegate>> |
55 _delegate; | 57 _delegate; |
56 | 58 |
57 // The PaymentRequest object owning an instance of web::PaymentRequest as | 59 // The PaymentRequest object owning an instance of web::PaymentRequest as |
58 // 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 |
59 // pointer and should outlive this class. | 61 // pointer and should outlive this class. |
60 PaymentRequest* _paymentRequest; | 62 PaymentRequest* _paymentRequest; |
61 | 63 |
62 // The currently selected item. May be nil. | 64 // The currently selected item. May be nil. |
63 ShippingAddressItem* _selectedItem; | 65 ShippingAddressItem* _selectedItem; |
64 } | 66 } |
65 | 67 |
66 // Called when the user presses the return button. | |
67 - (void)onReturn; | |
68 | |
69 @end | 68 @end |
70 | 69 |
71 @implementation ShippingAddressSelectionViewController | 70 @implementation ShippingAddressSelectionViewController |
72 | 71 |
73 @synthesize isLoading = _isLoading; | 72 @synthesize isLoading = _isLoading; |
74 @synthesize errorMessage = _errorMessage; | 73 @synthesize errorMessage = _errorMessage; |
75 | 74 |
76 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 75 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
77 DCHECK(paymentRequest); | 76 DCHECK(paymentRequest); |
78 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 77 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
79 self.title = l10n_util::GetNSString( | 78 self.title = l10n_util::GetNSString( |
80 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE); | 79 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE); |
81 | 80 |
| 81 // Set up leading (return) button. |
82 UIBarButtonItem* returnButton = | 82 UIBarButtonItem* returnButton = |
83 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 83 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
84 target:nil | 84 target:nil |
85 action:@selector(onReturn)]; | 85 action:@selector(onReturn)]; |
86 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); | 86 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); |
87 self.navigationItem.leftBarButtonItem = returnButton; | 87 self.navigationItem.leftBarButtonItem = returnButton; |
88 | 88 |
89 _paymentRequest = paymentRequest; | 89 _paymentRequest = paymentRequest; |
90 } | 90 } |
91 return self; | 91 return self; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON); | 156 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON); |
157 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD); | 157 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD); |
158 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton; | 158 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton; |
159 [model addItem:addShippingAddress | 159 [model addItem:addShippingAddress |
160 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 160 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
161 } | 161 } |
162 | 162 |
163 - (void)viewDidLoad { | 163 - (void)viewDidLoad { |
164 [super viewDidLoad]; | 164 [super viewDidLoad]; |
165 self.collectionView.accessibilityIdentifier = | 165 self.collectionView.accessibilityIdentifier = |
166 kShippingAddressSelectionCollectionViewId; | 166 kShippingAddressSelectionCollectionViewID; |
167 | 167 |
168 // Customize collection view settings. | 168 // Customize collection view settings. |
169 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 169 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
170 self.styler.separatorInset = | 170 self.styler.separatorInset = |
171 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 171 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
172 } | 172 } |
173 | 173 |
174 #pragma mark UICollectionViewDataSource | 174 #pragma mark UICollectionViewDataSource |
175 | 175 |
176 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 176 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 263 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
264 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 264 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
265 if (type == ItemTypeMessage) { | 265 if (type == ItemTypeMessage) { |
266 return YES; | 266 return YES; |
267 } else { | 267 } else { |
268 return NO; | 268 return NO; |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 @end | 272 @end |
OLD | NEW |