OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/ui/suggestions/suggestions_item.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h" |
| 8 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
| 15 @interface SuggestionsItem () |
| 16 |
| 17 @property(nonatomic, copy) NSString* title; |
| 18 @property(nonatomic, copy) NSString* subtitle; |
| 19 |
| 20 @end |
| 21 |
| 22 @implementation SuggestionsItem |
| 23 |
| 24 @synthesize title = _title; |
| 25 @synthesize subtitle = _subtitle; |
| 26 |
| 27 - (instancetype)initWithType:(NSInteger)type |
| 28 title:(NSString*)title |
| 29 subtitle:(NSString*)subtitle { |
| 30 self = [super initWithType:type]; |
| 31 if (self) { |
| 32 self.cellClass = [SuggestionsCell class]; |
| 33 _title = [title copy]; |
| 34 _subtitle = [subtitle copy]; |
| 35 } |
| 36 return self; |
| 37 } |
| 38 |
| 39 #pragma mark - CollectionViewItem |
| 40 |
| 41 - (void)configureCell:(SuggestionsCell*)cell { |
| 42 [super configureCell:cell]; |
| 43 [cell.titleButton setTitle:self.title forState:UIControlStateNormal]; |
| 44 cell.detailTextLabel.text = self.subtitle; |
| 45 } |
| 46 |
| 47 @end |
| 48 |
| 49 #pragma mark - SuggestionsCell |
| 50 |
| 51 @implementation SuggestionsCell |
| 52 |
| 53 @synthesize titleButton = _titleButton; |
| 54 @synthesize detailTextLabel = _detailTextLabel; |
| 55 |
| 56 - (instancetype)initWithFrame:(CGRect)frame { |
| 57 self = [super initWithFrame:frame]; |
| 58 if (self) { |
| 59 MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance]; |
| 60 _titleButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
| 61 _titleButton.titleLabel.font = [fontLoader mediumFontOfSize:16]; |
| 62 _titleButton.titleLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 63 [_titleButton addTarget:nil |
| 64 action:@selector(addNewItem:) |
| 65 forControlEvents:UIControlEventTouchUpInside]; |
| 66 |
| 67 _detailTextLabel = [[UILabel alloc] init]; |
| 68 _detailTextLabel.font = [fontLoader mediumFontOfSize:14]; |
| 69 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 70 |
| 71 UIStackView* labelsStack = [[UIStackView alloc] |
| 72 initWithArrangedSubviews:@[ _titleButton, _detailTextLabel ]]; |
| 73 labelsStack.axis = UILayoutConstraintAxisVertical; |
| 74 |
| 75 [self.contentView addSubview:labelsStack]; |
| 76 labelsStack.layoutMarginsRelativeArrangement = YES; |
| 77 labelsStack.layoutMargins = UIEdgeInsetsMake(16, 16, 16, 16); |
| 78 labelsStack.alignment = UIStackViewAlignmentCenter; |
| 79 |
| 80 labelsStack.translatesAutoresizingMaskIntoConstraints = NO; |
| 81 [NSLayoutConstraint activateConstraints:@[ |
| 82 [self.contentView.leadingAnchor |
| 83 constraintEqualToAnchor:labelsStack.leadingAnchor], |
| 84 [self.contentView.trailingAnchor |
| 85 constraintEqualToAnchor:labelsStack.trailingAnchor], |
| 86 [self.contentView.topAnchor |
| 87 constraintEqualToAnchor:labelsStack.topAnchor], |
| 88 [self.contentView.bottomAnchor |
| 89 constraintEqualToAnchor:labelsStack.bottomAnchor] |
| 90 ]]; |
| 91 |
| 92 self.backgroundColor = [UIColor whiteColor]; |
| 93 } |
| 94 return self; |
| 95 } |
| 96 |
| 97 @end |
OLD | NEW |