| 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..5b9e0cb3d041675a6d4d713724787b0cf9419214
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/payments/payment_request_error_view_controller.mm
|
| @@ -0,0 +1,148 @@
|
| +// 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;
|
| +
|
| +- (instancetype)init {
|
| + if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
|
| + [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
|
| +
|
| + // Set up trailing (ok) button.
|
| + _okButton.reset([[UIBarButtonItem alloc]
|
| + initWithTitle:l10n_util::GetNSString(
|
| + IDS_IOS_PAYMENT_REQUEST_ERROR_PAGE_OK_BUTTON)
|
| + style:UIBarButtonItemStylePlain
|
| + target:nil
|
| + action:@selector(onOk)]);
|
| + [_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
|
|
|