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

Side by Side Diff: ios/chrome/browser/ui/suggestions/suggestions_item.mm

Issue 2619963004: Suggestions UI - Add Data Source and Item (Closed)
Patch Set: Cleanup Created 3 years, 11 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 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 @implementation SuggestionsItem {
16 NSString* _title;
17 NSString* _subtitle;
18 }
19
20 - (instancetype)initWithType:(NSInteger)type
21 title:(NSString*)title
22 subtitle:(NSString*)subtitle {
23 self = [super initWithType:type];
24 if (self) {
25 self.cellClass = [SuggestionsCell class];
26 _title = title;
lpromero 2017/01/11 09:47:05 You should [title copy] these. To be more idiomati
marq (ping after 24h) 2017/01/11 13:43:09 +1 to properties, but you shouldn't use this class
gambard 2017/01/11 15:10:38 Acknowledged.
gambard 2017/01/11 15:10:38 Done.
27 _subtitle = subtitle;
28 }
29 return self;
30 }
31
32 - (void)configureCell:(SuggestionsCell*)cell {
33 [super configureCell:cell];
34 cell.title = _title;
35 cell.detailText = _subtitle;
36 }
37
38 @end
39
40 @implementation SuggestionsCell {
41 UIButton* _titleButton;
42 UILabel* _detailTextLabel;
43 }
44
45 @synthesize title = _title;
46 @synthesize detailText = _detailText;
47
48 - (instancetype)initWithFrame:(CGRect)frame {
49 self = [super initWithFrame:frame];
50 if (self) {
51 MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance];
52 _titleButton = [UIButton buttonWithType:UIButtonTypeSystem];
53 _titleButton.titleLabel.font = [fontLoader mediumFontOfSize:16];
54 _titleButton.titleLabel.textColor = [[MDCPalette greyPalette] tint900];
55 [_titleButton addTarget:nil
56 action:@selector(addItem:)
57 forControlEvents:UIControlEventTouchUpInside];
58
59 _detailTextLabel = [[UILabel alloc] init];
60 _detailTextLabel.font = [fontLoader mediumFontOfSize:14];
61 _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500];
62
63 UIStackView* labelsStack = [[UIStackView alloc]
lpromero 2017/01/11 09:47:05 I haven't been always happy with stack views in se
gambard 2017/01/11 15:10:38 Acknowledged.
64 initWithArrangedSubviews:@[ _titleButton, _detailTextLabel ]];
65 labelsStack.axis = UILayoutConstraintAxisVertical;
66
67 [self.contentView addSubview:labelsStack];
68 labelsStack.layoutMarginsRelativeArrangement = YES;
69 labelsStack.layoutMargins = UIEdgeInsetsMake(16, 16, 16, 16);
70 labelsStack.alignment = UIStackViewAlignmentCenter;
71
72 labelsStack.translatesAutoresizingMaskIntoConstraints = NO;
73 [NSLayoutConstraint activateConstraints:@[
74 [self.contentView.leadingAnchor
75 constraintEqualToAnchor:labelsStack.leadingAnchor],
76 [self.contentView.trailingAnchor
77 constraintEqualToAnchor:labelsStack.trailingAnchor],
78 [self.contentView.topAnchor
79 constraintEqualToAnchor:labelsStack.topAnchor],
80 [self.contentView.bottomAnchor
81 constraintEqualToAnchor:labelsStack.bottomAnchor]
82
lpromero 2017/01/11 09:47:05 Remove empty line.
gambard 2017/01/11 15:10:38 Done.
83 ]];
84
85 self.backgroundColor = [UIColor whiteColor];
86 }
87 return self;
88 }
89
90 #pragma mark - Properties
91
92 - (void)setTitle:(NSString*)title {
93 [_titleButton setTitle:title forState:UIControlStateNormal];
lpromero 2017/01/11 09:47:05 Actually, do you need to store a local copy of the
gambard 2017/01/11 15:10:38 Done.
94 _title = title;
lpromero 2017/01/11 09:47:05 Should be [title copy].
gambard 2017/01/11 15:10:38 Removed.
95 }
96
97 - (void)setDetailText:(NSString*)detailText {
98 _detailTextLabel.text = detailText;
99 _detailText = detailText;
lpromero 2017/01/11 09:47:05 Idem, should be [detailText copy].
gambard 2017/01/11 15:10:38 Removed.
100 }
101
102 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698