Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: ios/chrome/browser/payments/payment_request_error_view_controller.mm

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: ARCified Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/payments/payment_request_error_view_controller.h"
6
7 #include "base/mac/foundation_util.h"
8 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
10 #import "ios/chrome/browser/payments/payment_request_error_view_controller_actio ns.h"
11 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
13 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
14 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
15 #include "ios/chrome/grit/ios_strings.h"
16 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support."
21 #endif
22
23 NSString* const kPaymentRequestErrorCollectionViewID =
24 @"kPaymentRequestErrorCollectionViewID";
25
26 namespace {
27
28 const CGFloat kSeparatorEdgeInset = 14;
29
30 typedef NS_ENUM(NSInteger, SectionIdentifier) {
31 SectionIdentifierMessage = kSectionIdentifierEnumZero,
32 };
33
34 typedef NS_ENUM(NSInteger, ItemType) {
35 ItemTypeMessage = kItemTypeEnumZero,
36 };
37
38 } // namespace
39
40 @interface PaymentRequestErrorViewController ()<
41 PaymentRequestErrorViewControllerActions> {
42 UIBarButtonItem* _okButton;
43 }
44
45 @end
46
47 @implementation PaymentRequestErrorViewController
48
49 @synthesize errorMessage = _errorMessage;
50 @synthesize delegate = _delegate;
51
52 - (instancetype)init {
53 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
54 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
55
56 // Set up trailing (ok) button.
57 _okButton =
58 [[UIBarButtonItem alloc] initWithTitle:l10n_util::GetNSString(IDS_OK)
59 style:UIBarButtonItemStylePlain
60 target:nil
61 action:@selector(onOk)];
62 [_okButton setTitleTextAttributes:@{
63 NSForegroundColorAttributeName : [UIColor lightGrayColor]
64 }
65 forState:UIControlStateDisabled];
66 [_okButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_OK)];
67 [self navigationItem].rightBarButtonItem = _okButton;
68 }
69 return self;
70 }
71
72 - (void)onOk {
73 [_delegate paymentRequestErrorViewControllerDidDismiss:self];
74 }
75
76 #pragma mark - CollectionViewController methods
77
78 - (void)loadModel {
79 [super loadModel];
80 CollectionViewModel* model = self.collectionViewModel;
81
82 // Message section.
83 [model addSectionWithIdentifier:SectionIdentifierMessage];
84
85 PaymentsTextItem* messageItem =
86 [[PaymentsTextItem alloc] initWithType:ItemTypeMessage];
87 messageItem.text = _errorMessage;
88 [model addItem:messageItem toSectionWithIdentifier:SectionIdentifierMessage];
89 }
90
91 - (void)viewDidLoad {
92 [super viewDidLoad];
93 self.collectionView.accessibilityIdentifier =
94 kPaymentRequestErrorCollectionViewID;
95
96 // Customize collection view settings.
97 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
98 self.styler.separatorInset =
99 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
100 }
101
102 #pragma mark UICollectionViewDataSource
103
104 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
105 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
106 UICollectionViewCell* cell =
107 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
108
109 NSInteger itemType =
110 [self.collectionViewModel itemTypeForIndexPath:indexPath];
111 switch (itemType) {
112 case ItemTypeMessage: {
113 PaymentsTextCell* messageCell =
114 base::mac::ObjCCastStrict<PaymentsTextCell>(cell);
115 messageCell.textLabel.textColor = [[MDCPalette greyPalette] tint600];
116 }
117 default:
118 break;
119 }
120 return cell;
121 }
122
123 #pragma mark MDCCollectionViewStylingDelegate
124
125 - (CGFloat)collectionView:(UICollectionView*)collectionView
126 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
127 CollectionViewItem* item =
128 [self.collectionViewModel itemAtIndexPath:indexPath];
129 switch (item.type) {
130 case ItemTypeMessage:
131 return [MDCCollectionViewCell
132 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
133 forItem:item];
134 default:
135 NOTREACHED();
136 return MDCCellDefaultOneLineHeight;
137 }
138 }
139
140 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698