| 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/payment_method_selection_view_controller.h" | 5 #import "ios/chrome/browser/payments/payment_method_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_data_util.h" | 11 #include "components/autofill/core/browser/autofill_data_util.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/strings/grit/components_strings.h" | 13 #include "components/strings/grit/components_strings.h" |
| 14 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | 14 #import "ios/chrome/browser/payments/cells/payment_method_item.h" |
| 15 #import "ios/chrome/browser/payments/cells/payments_text_item.h" | 15 #import "ios/chrome/browser/payments/cells/payments_text_item.h" |
| 16 #import "ios/chrome/browser/payments/payment_method_selection_view_controller_ac
tions.h" |
| 16 #include "ios/chrome/browser/payments/payment_request.h" | 17 #include "ios/chrome/browser/payments/payment_request.h" |
| 17 #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" |
| 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_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_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 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 29 | 30 |
| 30 NSString* const kPaymentMethodSelectionCollectionViewId = | 31 NSString* const kPaymentMethodSelectionCollectionViewID = |
| 31 @"kPaymentMethodSelectionCollectionViewId"; | 32 @"kPaymentMethodSelectionCollectionViewID"; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const CGFloat kSeparatorEdgeInset = 14; | 36 const CGFloat kSeparatorEdgeInset = 14; |
| 36 | 37 |
| 37 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 38 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 38 SectionIdentifierPayment = kSectionIdentifierEnumZero, | 39 SectionIdentifierPayment = kSectionIdentifierEnumZero, |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 typedef NS_ENUM(NSInteger, ItemType) { | 42 typedef NS_ENUM(NSInteger, ItemType) { |
| 42 ItemTypePaymentMethod = kItemTypeEnumZero, // This is a repeated item type. | 43 ItemTypePaymentMethod = kItemTypeEnumZero, // This is a repeated item type. |
| 43 ItemTypeAddMethod, | 44 ItemTypeAddMethod, |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 } // namespace | 47 } // namespace |
| 47 | 48 |
| 48 @interface PaymentMethodSelectionViewController () { | 49 @interface PaymentMethodSelectionViewController ()< |
| 50 PaymentMethodSelectionViewControllerActions> { |
| 49 base::WeakNSProtocol<id<PaymentMethodSelectionViewControllerDelegate>> | 51 base::WeakNSProtocol<id<PaymentMethodSelectionViewControllerDelegate>> |
| 50 _delegate; | 52 _delegate; |
| 51 | 53 |
| 52 // The PaymentRequest object owning an instance of web::PaymentRequest as | 54 // The PaymentRequest object owning an instance of web::PaymentRequest as |
| 53 // provided by the page invoking the Payment Request API. This is a weak | 55 // provided by the page invoking the Payment Request API. This is a weak |
| 54 // pointer and should outlive this class. | 56 // pointer and should outlive this class. |
| 55 PaymentRequest* _paymentRequest; | 57 PaymentRequest* _paymentRequest; |
| 56 | 58 |
| 57 // The currently selected item. May be nil. | 59 // The currently selected item. May be nil. |
| 58 PaymentMethodItem* _selectedItem; | 60 PaymentMethodItem* _selectedItem; |
| 59 } | 61 } |
| 60 | 62 |
| 61 // Called when the user presses the return button. | |
| 62 - (void)onReturn; | |
| 63 | |
| 64 @end | 63 @end |
| 65 | 64 |
| 66 @implementation PaymentMethodSelectionViewController | 65 @implementation PaymentMethodSelectionViewController |
| 67 | 66 |
| 68 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { | 67 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { |
| 69 DCHECK(paymentRequest); | 68 DCHECK(paymentRequest); |
| 70 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | 69 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
| 71 [self setTitle:l10n_util::GetNSString( | 70 [self setTitle:l10n_util::GetNSString( |
| 72 IDS_IOS_PAYMENT_REQUEST_METHOD_SELECTION_TITLE)]; | 71 IDS_IOS_PAYMENT_REQUEST_METHOD_SELECTION_TITLE)]; |
| 73 | 72 |
| 73 // Set up leading (return) button. |
| 74 UIBarButtonItem* returnButton = | 74 UIBarButtonItem* returnButton = |
| 75 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] | 75 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] |
| 76 target:nil | 76 target:nil |
| 77 action:@selector(onReturn)]; | 77 action:@selector(onReturn)]; |
| 78 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); | 78 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); |
| 79 [self navigationItem].leftBarButtonItem = returnButton; | 79 [self navigationItem].leftBarButtonItem = returnButton; |
| 80 | 80 |
| 81 _paymentRequest = paymentRequest; | 81 _paymentRequest = paymentRequest; |
| 82 } | 82 } |
| 83 return self; | 83 return self; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_ADD_METHOD_BUTTON); | 131 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_ADD_METHOD_BUTTON); |
| 132 addPaymentMethod.image = NativeImage(IDR_IOS_PAYMENTS_ADD); | 132 addPaymentMethod.image = NativeImage(IDR_IOS_PAYMENTS_ADD); |
| 133 addPaymentMethod.accessibilityTraits |= UIAccessibilityTraitButton; | 133 addPaymentMethod.accessibilityTraits |= UIAccessibilityTraitButton; |
| 134 [model addItem:addPaymentMethod | 134 [model addItem:addPaymentMethod |
| 135 toSectionWithIdentifier:SectionIdentifierPayment]; | 135 toSectionWithIdentifier:SectionIdentifierPayment]; |
| 136 } | 136 } |
| 137 | 137 |
| 138 - (void)viewDidLoad { | 138 - (void)viewDidLoad { |
| 139 [super viewDidLoad]; | 139 [super viewDidLoad]; |
| 140 self.collectionView.accessibilityIdentifier = | 140 self.collectionView.accessibilityIdentifier = |
| 141 kPaymentMethodSelectionCollectionViewId; | 141 kPaymentMethodSelectionCollectionViewID; |
| 142 | 142 |
| 143 // Customize collection view settings. | 143 // Customize collection view settings. |
| 144 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 144 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 145 self.styler.separatorInset = | 145 self.styler.separatorInset = |
| 146 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | 146 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
| 147 } | 147 } |
| 148 | 148 |
| 149 #pragma mark UICollectionViewDelegate | 149 #pragma mark UICollectionViewDelegate |
| 150 | 150 |
| 151 - (void)collectionView:(UICollectionView*)collectionView | 151 - (void)collectionView:(UICollectionView*)collectionView |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return [MDCCollectionViewCell | 198 return [MDCCollectionViewCell |
| 199 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 199 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
| 200 forItem:item]; | 200 forItem:item]; |
| 201 default: | 201 default: |
| 202 NOTREACHED(); | 202 NOTREACHED(); |
| 203 return MDCCellDefaultOneLineHeight; | 203 return MDCCellDefaultOneLineHeight; |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 @end | 207 @end |
| OLD | NEW |