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

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

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: Addressed comments 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 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/foundation_util.h"
9 #include "base/mac/scoped_nsobject.h"
10 #include "components/strings/grit/components_strings.h"
11 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
12 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
15 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
16 #include "ios/chrome/grit/ios_strings.h"
17 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
18 #include "ui/base/l10n/l10n_util.h"
19
20 NSString* const kPaymentRequestErrorCollectionViewID =
21 @"kPaymentRequestErrorCollectionViewID";
22
23 namespace {
24
25 const CGFloat kSeparatorEdgeInset = 14;
26
27 typedef NS_ENUM(NSInteger, SectionIdentifier) {
28 SectionIdentifierMessage = kSectionIdentifierEnumZero,
29 };
30
31 typedef NS_ENUM(NSInteger, ItemType) {
32 ItemTypeMessage = kItemTypeEnumZero,
33 };
34
35 } // namespace
36
37 @interface PaymentRequestErrorViewController () {
38 base::WeakNSProtocol<id<PaymentRequestErrorViewControllerDelegate>> _delegate;
39 base::scoped_nsobject<UIBarButtonItem> _okButton;
40 }
41
42 // Called when the user presses the ok button.
43 - (void)onOk;
44
45 @end
46
47 @implementation PaymentRequestErrorViewController
48
49 @synthesize errorMessage = _errorMessage;
50
51 - (instancetype)init {
52 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
53 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)];
54
55 // Set up trailing (ok) button.
56 _okButton.reset([[UIBarButtonItem alloc]
57 initWithTitle:l10n_util::GetNSString(
58 IDS_IOS_PAYMENT_REQUEST_ERROR_PAGE_OK_BUTTON)
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 - (id<PaymentRequestErrorViewControllerDelegate>)delegate {
73 return _delegate.get();
74 }
75
76 - (void)setDelegate:(id<PaymentRequestErrorViewControllerDelegate>)delegate {
77 _delegate.reset(delegate);
78 }
79
80 - (void)onOk {
81 [_delegate paymentRequestErrorViewControllerDidDismiss:self];
82 }
83
84 #pragma mark - CollectionViewController methods
85
86 - (void)loadModel {
87 [super loadModel];
88 CollectionViewModel* model = self.collectionViewModel;
89
90 // Message section.
91 [model addSectionWithIdentifier:SectionIdentifierMessage];
92
93 PaymentsTextItem* messageItem =
94 [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease];
95 messageItem.text = _errorMessage;
96 [model addItem:messageItem toSectionWithIdentifier:SectionIdentifierMessage];
97 }
98
99 - (void)viewDidLoad {
100 [super viewDidLoad];
101 self.collectionView.accessibilityIdentifier =
102 kPaymentRequestErrorCollectionViewID;
103
104 // Customize collection view settings.
105 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
106 self.styler.separatorInset =
107 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
108 }
109
110 #pragma mark UICollectionViewDataSource
111
112 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
113 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
114 UICollectionViewCell* cell =
115 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
116
117 NSInteger itemType =
118 [self.collectionViewModel itemTypeForIndexPath:indexPath];
119 switch (itemType) {
120 case ItemTypeMessage: {
121 PaymentsTextCell* messageCell =
122 base::mac::ObjCCastStrict<PaymentsTextCell>(cell);
123 messageCell.textLabel.textColor = [[MDCPalette greyPalette] tint600];
124 }
125 default:
126 break;
127 }
128 return cell;
129 }
130
131 #pragma mark MDCCollectionViewStylingDelegate
132
133 - (CGFloat)collectionView:(UICollectionView*)collectionView
134 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
135 CollectionViewItem* item =
136 [self.collectionViewModel itemAtIndexPath:indexPath];
137 switch (item.type) {
138 case ItemTypeMessage:
139 return [MDCCollectionViewCell
140 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
141 forItem:item];
142 default:
143 NOTREACHED();
144 return MDCCellDefaultOneLineHeight;
145 }
146 }
147
148 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698