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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm

Issue 2734763003: Default background for not suggested article images (Closed)
Patch Set: Fix tests Created 3 years, 9 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
« no previous file with comments | « no previous file | ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i tem.h" 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_i tem.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
9 #import "ios/chrome/browser/ui/uikit_ui_util.h" 9 #import "ios/chrome/browser/ui/uikit_ui_util.h"
10 #import "ios/chrome/browser/ui/util/i18n_string.h" 10 #import "ios/chrome/browser/ui/util/i18n_string.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 subtitle:(NSString*)subtitle 49 subtitle:(NSString*)subtitle
50 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate 50 delegate:(id<ContentSuggestionsArticleItemDelegate>)delegate
51 url:(const GURL&)url { 51 url:(const GURL&)url {
52 self = [super initWithType:type]; 52 self = [super initWithType:type];
53 if (self) { 53 if (self) {
54 self.cellClass = [ContentSuggestionsArticleCell class]; 54 self.cellClass = [ContentSuggestionsArticleCell class];
55 _title = [title copy]; 55 _title = [title copy];
56 _subtitle = [subtitle copy]; 56 _subtitle = [subtitle copy];
57 _articleURL = url; 57 _articleURL = url;
58 _delegate = delegate; 58 _delegate = delegate;
59 _image = [self emptyImageBackground];
59 } 60 }
60 return self; 61 return self;
61 } 62 }
62 63
63 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { 64 - (void)configureCell:(ContentSuggestionsArticleCell*)cell {
64 [super configureCell:cell]; 65 [super configureCell:cell];
65 if (!self.image && !self.imageFetched) { 66 if (!self.imageFetched) {
66 self.imageFetched = YES; 67 self.imageFetched = YES;
67 // Fetch the image. During the fetch the cell's image should still be set to 68 // Fetch the image. During the fetch the cell's image should still be set.
68 // nil.
69 [self.delegate loadImageForArticleItem:self]; 69 [self.delegate loadImageForArticleItem:self];
70 } 70 }
71 cell.titleLabel.text = self.title; 71 cell.titleLabel.text = self.title;
72 cell.subtitleLabel.text = self.subtitle; 72 cell.subtitleLabel.text = self.subtitle;
73 cell.imageView.image = self.image; 73 cell.imageView.image = self.image;
74 [cell setPublisherName:self.publisher date:self.publishDate]; 74 [cell setPublisherName:self.publisher date:self.publishDate];
75 } 75 }
76 76
77 #pragma mark - Private
78
79 - (UIImage*)emptyImageBackground {
80 // TODO(crbug.com/698171): Remove this function once we have real background
81 // image.
82 UIColor* color = [UIColor lightGrayColor];
83 CGRect rect = CGRectMake(0, 0, 1, 1);
84 UIGraphicsBeginImageContext(rect.size);
85 [color setFill];
86 UIRectFill(rect);
87 UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
88 UIGraphicsEndImageContext();
89 return image;
90 }
91
77 @end 92 @end
78 93
79 #pragma mark - ContentSuggestionsArticleCell 94 #pragma mark - ContentSuggestionsArticleCell
80 95
81 @interface ContentSuggestionsArticleCell () 96 @interface ContentSuggestionsArticleCell ()
82 97
83 @property(nonatomic, strong) UILabel* publisherLabel; 98 @property(nonatomic, strong) UILabel* publisherLabel;
84 99
85 // Applies the constraints on the elements. Called in the init. 100 // Applies the constraints on the elements. Called in the init.
86 - (void)applyConstraints; 101 - (void)applyConstraints;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Implements -layoutSubviews as per instructions in documentation for 164 // Implements -layoutSubviews as per instructions in documentation for
150 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. 165 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
151 - (void)layoutSubviews { 166 - (void)layoutSubviews {
152 [super layoutSubviews]; 167 [super layoutSubviews];
153 168
154 // Adjust the text label preferredMaxLayoutWidth when the parent's width 169 // Adjust the text label preferredMaxLayoutWidth when the parent's width
155 // changes, for instance on screen rotation. 170 // changes, for instance on screen rotation.
156 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); 171 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
157 172
158 self.titleLabel.preferredMaxLayoutWidth = 173 self.titleLabel.preferredMaxLayoutWidth =
159 parentWidth - self.imageView.bounds.size.width - 3 * kStandardSpacing; 174 parentWidth - kImageSize - 3 * kStandardSpacing;
160 self.subtitleLabel.preferredMaxLayoutWidth = 175 self.subtitleLabel.preferredMaxLayoutWidth =
161 parentWidth - self.imageView.bounds.size.width - 3 * kStandardSpacing; 176 parentWidth - kImageSize - 3 * kStandardSpacing;
162 177
163 // Re-layout with the new preferred width to allow the label to adjust its 178 // Re-layout with the new preferred width to allow the label to adjust its
164 // height. 179 // height.
165 [super layoutSubviews]; 180 [super layoutSubviews];
166 } 181 }
167 182
168 #pragma mark - Private 183 #pragma mark - Private
169 184
170 - (void)applyConstraints { 185 - (void)applyConstraints {
171 [NSLayoutConstraint activateConstraints:@[ 186 [NSLayoutConstraint activateConstraints:@[
(...skipping 19 matching lines...) Expand all
191 @{ 206 @{
192 @"image" : _imageView, 207 @"image" : _imageView,
193 @"title" : _titleLabel, 208 @"title" : _titleLabel,
194 @"text" : _subtitleLabel, 209 @"text" : _subtitleLabel,
195 @"publish" : _publisherLabel, 210 @"publish" : _publisherLabel,
196 }, 211 },
197 @{ @"space" : @(kStandardSpacing) }); 212 @{ @"space" : @(kStandardSpacing) });
198 } 213 }
199 214
200 @end 215 @end
OLDNEW
« no previous file with comments | « no previous file | ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698