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

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

Issue 2701923003: [Payment Request] Error message screen (Closed)
Patch Set: 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 @synthesize callback = _callback;
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 right (ok) button.
lpromero 2017/02/20 17:14:07 Nit: s/right/trailing
Moe 2017/02/21 05:07:06 Done.
57 _okButton.reset([[UIBarButtonItem alloc]
58 initWithTitle:l10n_util::GetNSString(
59 IDS_IOS_PAYMENT_REQUEST_ERROR_PAGE_OK_BUTTON)
60 style:UIBarButtonItemStylePlain
61 target:nil
62 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.
63 [_okButton setTitleTextAttributes:@{
64 NSForegroundColorAttributeName : [UIColor lightGrayColor]
65 }
66 forState:UIControlStateDisabled];
67 [_okButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_OK)];
68 [self navigationItem].rightBarButtonItem = _okButton;
69 }
70 return self;
71 }
72
73 - (id<PaymentRequestErrorViewControllerDelegate>)delegate {
74 return _delegate.get();
75 }
76
77 - (void)setDelegate:(id<PaymentRequestErrorViewControllerDelegate>)delegate {
78 _delegate.reset(delegate);
79 }
80
81 - (void)onOk {
82 [_delegate paymentRequestErrorViewControllerDidDismiss:self];
83 }
84
85 #pragma mark - CollectionViewController methods
86
87 - (void)loadModel {
88 [super loadModel];
89 CollectionViewModel* model = self.collectionViewModel;
90
91 // Message section.
92 [model addSectionWithIdentifier:SectionIdentifierMessage];
93
94 PaymentsTextItem* messageItem =
95 [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease];
96 messageItem.text = _errorMessage;
97 [model addItem:messageItem toSectionWithIdentifier:SectionIdentifierMessage];
98 }
99
100 - (void)viewDidLoad {
101 [super viewDidLoad];
102 self.collectionView.accessibilityIdentifier =
103 kPaymentRequestErrorCollectionViewId;
104
105 // Customize collection view settings.
106 self.styler.cellStyle = MDCCollectionViewCellStyleCard;
107 self.styler.separatorInset =
108 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset);
109 }
110
111 #pragma mark UICollectionViewDataSource
112
113 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
114 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath {
115 UICollectionViewCell* cell =
116 [super collectionView:collectionView cellForItemAtIndexPath:indexPath];
117
118 NSInteger itemType =
119 [self.collectionViewModel itemTypeForIndexPath:indexPath];
120 switch (itemType) {
121 case ItemTypeMessage: {
122 PaymentsTextCell* messageCell =
123 base::mac::ObjCCastStrict<PaymentsTextCell>(cell);
124 messageCell.textLabel.textColor = [[MDCPalette greyPalette] tint600];
125 }
126 default:
127 break;
128 }
129 return cell;
130 }
131
132 #pragma mark MDCCollectionViewStylingDelegate
133
134 - (CGFloat)collectionView:(UICollectionView*)collectionView
135 cellHeightAtIndexPath:(NSIndexPath*)indexPath {
136 CollectionViewItem* item =
137 [self.collectionViewModel itemAtIndexPath:indexPath];
138 switch (item.type) {
139 case ItemTypeMessage:
140 return [MDCCollectionViewCell
141 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
142 forItem:item];
143 default:
144 NOTREACHED();
145 return MDCCellDefaultOneLineHeight;
146 }
147 }
148
149 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698