Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
|
please use gerrit instead
2017/02/21 16:37:08
This can be used to get Objective C readability. I
Moe
2017/02/21 22:56:15
I'd wait a bit longer until I'd stop making obviou
| |
| 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/payments/payment_request_error_view_controller_actio ns.h" | |
| 13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | |
| 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | |
| 15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | |
| 16 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | |
| 17 #include "ios/chrome/grit/ios_strings.h" | |
| 18 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 | |
| 21 NSString* const kPaymentRequestErrorCollectionViewID = | |
| 22 @"kPaymentRequestErrorCollectionViewID"; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const CGFloat kSeparatorEdgeInset = 14; | |
| 27 | |
| 28 typedef NS_ENUM(NSInteger, SectionIdentifier) { | |
| 29 SectionIdentifierMessage = kSectionIdentifierEnumZero, | |
| 30 }; | |
| 31 | |
| 32 typedef NS_ENUM(NSInteger, ItemType) { | |
| 33 ItemTypeMessage = kItemTypeEnumZero, | |
| 34 }; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 @interface PaymentRequestErrorViewController ()< | |
| 39 PaymentRequestErrorViewControllerActions> { | |
| 40 base::WeakNSProtocol<id<PaymentRequestErrorViewControllerDelegate>> _delegate; | |
| 41 base::scoped_nsobject<UIBarButtonItem> _okButton; | |
| 42 } | |
| 43 | |
| 44 @end | |
| 45 | |
| 46 @implementation PaymentRequestErrorViewController | |
| 47 | |
| 48 @synthesize errorMessage = _errorMessage; | |
| 49 | |
| 50 - (instancetype)init { | |
| 51 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { | |
| 52 [self setTitle:l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_TITLE)]; | |
| 53 | |
| 54 // Set up trailing (ok) button. | |
| 55 _okButton.reset([[UIBarButtonItem alloc] | |
| 56 initWithTitle:l10n_util::GetNSString( | |
| 57 IDS_IOS_PAYMENT_REQUEST_ERROR_PAGE_OK_BUTTON) | |
| 58 style:UIBarButtonItemStylePlain | |
| 59 target:nil | |
| 60 action:@selector(onOk)]); | |
| 61 [_okButton setTitleTextAttributes:@{ | |
| 62 NSForegroundColorAttributeName : [UIColor lightGrayColor] | |
| 63 } | |
| 64 forState:UIControlStateDisabled]; | |
| 65 [_okButton setAccessibilityLabel:l10n_util::GetNSString(IDS_ACCNAME_OK)]; | |
| 66 [self navigationItem].rightBarButtonItem = _okButton; | |
| 67 } | |
| 68 return self; | |
| 69 } | |
| 70 | |
| 71 - (id<PaymentRequestErrorViewControllerDelegate>)delegate { | |
| 72 return _delegate.get(); | |
| 73 } | |
| 74 | |
| 75 - (void)setDelegate:(id<PaymentRequestErrorViewControllerDelegate>)delegate { | |
| 76 _delegate.reset(delegate); | |
| 77 } | |
| 78 | |
| 79 - (void)onOk { | |
| 80 [_delegate paymentRequestErrorViewControllerDidDismiss:self]; | |
| 81 } | |
| 82 | |
| 83 #pragma mark - CollectionViewController methods | |
| 84 | |
| 85 - (void)loadModel { | |
| 86 [super loadModel]; | |
| 87 CollectionViewModel* model = self.collectionViewModel; | |
| 88 | |
| 89 // Message section. | |
| 90 [model addSectionWithIdentifier:SectionIdentifierMessage]; | |
| 91 | |
| 92 PaymentsTextItem* messageItem = | |
| 93 [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease]; | |
| 94 messageItem.text = _errorMessage; | |
| 95 [model addItem:messageItem toSectionWithIdentifier:SectionIdentifierMessage]; | |
| 96 } | |
| 97 | |
| 98 - (void)viewDidLoad { | |
| 99 [super viewDidLoad]; | |
| 100 self.collectionView.accessibilityIdentifier = | |
| 101 kPaymentRequestErrorCollectionViewID; | |
| 102 | |
| 103 // Customize collection view settings. | |
| 104 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | |
| 105 self.styler.separatorInset = | |
| 106 UIEdgeInsetsMake(0, kSeparatorEdgeInset, 0, kSeparatorEdgeInset); | |
| 107 } | |
| 108 | |
| 109 #pragma mark UICollectionViewDataSource | |
| 110 | |
| 111 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
| 112 cellForItemAtIndexPath:(nonnull NSIndexPath*)indexPath { | |
| 113 UICollectionViewCell* cell = | |
| 114 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | |
| 115 | |
| 116 NSInteger itemType = | |
| 117 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | |
| 118 switch (itemType) { | |
| 119 case ItemTypeMessage: { | |
| 120 PaymentsTextCell* messageCell = | |
| 121 base::mac::ObjCCastStrict<PaymentsTextCell>(cell); | |
| 122 messageCell.textLabel.textColor = [[MDCPalette greyPalette] tint600]; | |
| 123 } | |
| 124 default: | |
| 125 break; | |
| 126 } | |
| 127 return cell; | |
| 128 } | |
| 129 | |
| 130 #pragma mark MDCCollectionViewStylingDelegate | |
| 131 | |
| 132 - (CGFloat)collectionView:(UICollectionView*)collectionView | |
| 133 cellHeightAtIndexPath:(NSIndexPath*)indexPath { | |
| 134 CollectionViewItem* item = | |
| 135 [self.collectionViewModel itemAtIndexPath:indexPath]; | |
| 136 switch (item.type) { | |
| 137 case ItemTypeMessage: | |
| 138 return [MDCCollectionViewCell | |
| 139 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | |
| 140 forItem:item]; | |
| 141 default: | |
| 142 NOTREACHED(); | |
| 143 return MDCCellDefaultOneLineHeight; | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 @end | |
| OLD | NEW |