Index: ios/chrome/browser/payments/payment_request_error_view_controller.mm |
diff --git a/ios/chrome/browser/payments/payment_request_error_view_controller.mm b/ios/chrome/browser/payments/payment_request_error_view_controller.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fb89239750d64aa0920bfbea9ba8218c39b1cae2 |
--- /dev/null |
+++ b/ios/chrome/browser/payments/payment_request_error_view_controller.mm |
@@ -0,0 +1,149 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/chrome/browser/payments/payment_request_error_view_controller.h" |
+ |
+#import "base/ios/weak_nsobject.h" |
+#include "base/mac/foundation_util.h" |
+#include "base/mac/scoped_nsobject.h" |
+#include "components/strings/grit/components_strings.h" |
+#import "ios/chrome/browser/payments/cells/payments_text_item.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h" |
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
+#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
+#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
+#include "ios/chrome/grit/ios_strings.h" |
+#import "ios/third_party/material_components_ios/src/components/Buttons/src/MaterialButtons.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+NSString* const kPaymentRequestErrorCollectionViewId = |
+ @"kPaymentRequestErrorCollectionViewId"; |
+ |
+namespace { |
+ |
+const CGFloat kSeparatorEdgeInset = 14; |
+ |
+typedef NS_ENUM(NSInteger, SectionIdentifier) { |
+ SectionIdentifierMessage = kSectionIdentifierEnumZero, |
+}; |
+ |
+typedef NS_ENUM(NSInteger, ItemType) { |
+ ItemTypeMessage = kItemTypeEnumZero, |
+}; |
+ |
+} // namespace |
+ |
+@interface PaymentRequestErrorViewController () { |
+ base::WeakNSProtocol<id<PaymentRequestErrorViewControllerDelegate>> _delegate; |
+ base::scoped_nsobject<UIBarButtonItem> _okButton; |
+} |
+ |
+// Called when the user presses the ok button. |
+- (void)onOk; |
+ |
+@end |
+ |
+@implementation PaymentRequestErrorViewController |
+ |
+@synthesize errorMessage = _errorMessage; |
+@synthesize callback = _callback; |
+ |
+- (instancetype)init { |
+ if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { |
+ [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; |
+ |
+ // Set up right (ok) button. |
lpromero
2017/02/20 17:14:07
Nit: s/right/trailing
Moe
2017/02/21 05:07:06
Done.
|
+ _okButton.reset([[UIBarButtonItem alloc] |
+ initWithTitle:l10n_util::GetNSString( |
+ IDS_IOS_PAYMENT_REQUEST_ERROR_PAGE_OK_BUTTON) |
+ style:UIBarButtonItemStylePlain |
+ target:nil |
+ action:@selector(onOk)]); |
lpromero
2017/02/20 17:14:07
You should create a protocol for this method. Have
Moe
2017/02/21 05:07:06
I took a look at SuggestionsItemActions. It seems
lpromero
2017/02/21 12:26:22
It also make explicit the ways in for this control
Moe
2017/02/21 15:37:40
Makes sense. Done.
|
+ [_okButton setTitleTextAttributes:@{ |
+ NSForegroundColorAttributeName : [UIColor lightGrayColor] |
+ } |
+ forState:UIControlStateDisabled]; |
+ [_okButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_OK)]; |
+ [self navigationItem].rightBarButtonItem = _okButton; |
+ } |
+ return self; |
+} |
+ |
+- (id<PaymentRequestErrorViewControllerDelegate>)delegate { |
+ return _delegate.get(); |
+} |
+ |
+- (void)setDelegate:(id<PaymentRequestErrorViewControllerDelegate>)delegate { |
+ _delegate.reset(delegate); |
+} |
+ |
+- (void)onOk { |
+ [_delegate paymentRequestErrorViewControllerDidDismiss:self]; |
+} |
+ |
+#pragma mark - CollectionViewController methods |
+ |
+- (void)loadModel { |
+ [super loadModel]; |
+ CollectionViewModel* model = self.collectionViewModel; |
+ |
+ // Message section. |
+ [model addSectionWithIdentifier:SectionIdentifierMessage]; |
+ |
+ PaymentsTextItem* messageItem = |
+ [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease]; |
+ messageItem.text = _errorMessage; |
+ [model addItem:messageItem toSectionWithIdentifier:SectionIdentifierMessage]; |
+} |
+ |
+- (void)viewDidLoad { |
+ [super viewDidLoad]; |
+ self.collectionView.accessibilityIdentifier = |
+ kPaymentRequestErrorCollectionViewId; |
+ |
+ // Customize collection view settings. |
+ self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
+ self.styler.separatorInset = |
+ UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); |
+} |
+ |
+#pragma mark UICollectionViewDataSource |
+ |
+- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
+ cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { |
+ UICollectionViewCell* cell = |
+ [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
+ |
+ NSInteger itemType = |
+ [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
+ switch (itemType) { |
+ case ItemTypeMessage: { |
+ PaymentsTextCell* messageCell = |
+ base::mac::ObjCCastStrict<PaymentsTextCell>(cell); |
+ messageCell.textLabel.textColor = [[MDCPalette greyPalette] tint600]; |
+ } |
+ default: |
+ break; |
+ } |
+ return cell; |
+} |
+ |
+#pragma mark MDCCollectionViewStylingDelegate |
+ |
+- (CGFloat)collectionView:(UICollectionView*)collectionView |
+ cellHeightAtIndexPath:(NSIndexPath*)indexPath { |
+ CollectionViewItem* item = |
+ [self.collectionViewModel itemAtIndexPath:indexPath]; |
+ switch (item.type) { |
+ case ItemTypeMessage: |
+ return [MDCCollectionViewCell |
+ cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
+ forItem:item]; |
+ default: |
+ NOTREACHED(); |
+ return MDCCellDefaultOneLineHeight; |
+ } |
+} |
+ |
+@end |