| 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 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" | 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 11 #include "ios/chrome/browser/application_context.h" | 12 #include "ios/chrome/browser/application_context.h" |
| 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | 13 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
| 13 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" | 14 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" |
| 14 #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" |
| 15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" | 17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" |
| 16 #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" |
| 17 #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" |
| 18 #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
" |
| 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 21 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 23 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 22 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 24 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
| 23 #include "ios/chrome/grit/ios_strings.h" | 25 #include "ios/chrome/grit/ios_strings.h" |
| 24 #include "ios/chrome/grit/ios_theme_resources.h" | 26 #include "ios/chrome/grit/ios_theme_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 26 | 28 |
| 27 #if !defined(__has_feature) || !__has_feature(objc_arc) | 29 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 28 #error "This file requires ARC support." | 30 #error "This file requires ARC support." |
| 29 #endif | 31 #endif |
| 30 | 32 |
| 31 using payment_request_util::NameLabelFromAutofillProfile; | 33 using payment_request_util::NameLabelFromAutofillProfile; |
| 32 using payment_request_util::AddressLabelFromAutofillProfile; | 34 using payment_request_util::AddressLabelFromAutofillProfile; |
| 33 using payment_request_util::PhoneNumberLabelFromAutofillProfile; | 35 using payment_request_util::PhoneNumberLabelFromAutofillProfile; |
| 34 | 36 |
| 35 NSString* const kShippingAddressSelectionCollectionViewId = | 37 NSString* const kShippingAddressSelectionCollectionViewID = |
| 36 @"kShippingAddressSelectionCollectionViewId"; | 38 @"kShippingAddressSelectionCollectionViewID"; |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 const CGFloat kSeparatorEdgeInset = 14; | 42 const CGFloat kSeparatorEdgeInset = 14; |
| 41 | 43 |
| 42 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 44 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 43 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, | 45 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 typedef NS_ENUM(NSInteger, ItemType) { | 48 typedef NS_ENUM(NSInteger, ItemType) { |
| 47 ItemTypeSpinner = kItemTypeEnumZero, | 49 ItemTypeSpinner = kItemTypeEnumZero, |
| 48 ItemTypeMessage, | 50 ItemTypeMessage, |
| 49 ItemTypeShippingAddress, // This is a repeated item type. | 51 ItemTypeShippingAddress, // This is a repeated item type. |
| 50 ItemTypeAddShippingAddress, | 52 ItemTypeAddShippingAddress, |
| 51 }; | 53 }; |
| 52 | 54 |
| 53 } // namespace | 55 } // namespace |
| 54 | 56 |
| 55 @interface ShippingAddressSelectionViewController () { | 57 @interface ShippingAddressSelectionViewController ()< |
| 58 ShippingAddressSelectionViewControllerActions> { |
| 56 // The PaymentRequest object owning an instance of web::PaymentRequest as | 59 // The PaymentRequest object owning an instance of web::PaymentRequest as |
| 57 // 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 |
| 58 // pointer and should outlive this class. | 61 // pointer and should outlive this class. |
| 59 PaymentRequest* _paymentRequest; | 62 PaymentRequest* _paymentRequest; |
| 60 | 63 |
| 61 // The currently selected item. May be nil. | 64 // The currently selected item. May be nil. |
| 62 __weak ShippingAddressItem* _selectedItem; | 65 __weak ShippingAddressItem* _selectedItem; |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Called when the user presses the return button. | |
| 66 - (void)onReturn; | |
| 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 |
| 76 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 76 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
| 77 DCHECK(paymentRequest); | 77 DCHECK(paymentRequest); |
| 78 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 78 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
| 79 self.title = | 79 self.title = |
| 80 payment_request_util::GetShippingAddressSelectorTitle(paymentRequest); | 80 payment_request_util::GetShippingAddressSelectorTitle(paymentRequest); |
| 81 | 81 |
| 82 // Set up leading (return) button. |
| 82 UIBarButtonItem* returnButton = | 83 UIBarButtonItem* returnButton = |
| 83 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 84 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
| 84 target:nil | 85 target:nil |
| 85 action:@selector(onReturn)]; | 86 action:@selector(onReturn)]; |
| 86 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); | 87 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); |
| 87 self.navigationItem.leftBarButtonItem = returnButton; | 88 self.navigationItem.leftBarButtonItem = returnButton; |
| 88 | 89 |
| 89 _paymentRequest = paymentRequest; | 90 _paymentRequest = paymentRequest; |
| 90 } | 91 } |
| 91 return self; | 92 return self; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON); | 148 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON); |
| 148 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD); | 149 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD); |
| 149 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton; | 150 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton; |
| 150 [model addItem:addShippingAddress | 151 [model addItem:addShippingAddress |
| 151 toSectionWithIdentifier:SectionIdentifierShippingAddress]; | 152 toSectionWithIdentifier:SectionIdentifierShippingAddress]; |
| 152 } | 153 } |
| 153 | 154 |
| 154 - (void)viewDidLoad { | 155 - (void)viewDidLoad { |
| 155 [super viewDidLoad]; | 156 [super viewDidLoad]; |
| 156 self.collectionView.accessibilityIdentifier = | 157 self.collectionView.accessibilityIdentifier = |
| 157 kShippingAddressSelectionCollectionViewId; | 158 kShippingAddressSelectionCollectionViewID; |
| 158 | 159 |
| 159 // Customize collection view settings. | 160 // Customize collection view settings. |
| 160 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 161 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 161 self.styler.separatorInset = | 162 self.styler.separatorInset = |
| 162 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 163 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 163 } | 164 } |
| 164 | 165 |
| 165 #pragma mark UICollectionViewDataSource | 166 #pragma mark UICollectionViewDataSource |
| 166 | 167 |
| 167 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 168 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { | 255 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { |
| 255 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 256 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 256 if (type == ItemTypeMessage) { | 257 if (type == ItemTypeMessage) { |
| 257 return YES; | 258 return YES; |
| 258 } else { | 259 } else { |
| 259 return NO; | 260 return NO; |
| 260 } | 261 } |
| 261 } | 262 } |
| 262 | 263 |
| 263 @end | 264 @end |
| OLD | NEW |