Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
| 64 - (UIImage*)emptyImageBackground { | |
| 65 // TODO(crbug.com/698171): Remove this function once we have real background | |
| 66 // image. | |
| 67 UIColor* color = [UIColor lightGrayColor]; | |
| 68 CGRect rect = CGRectMake(0, 0, 1, 1); | |
| 69 UIGraphicsBeginImageContext(rect.size); | |
| 70 [color setFill]; | |
| 71 UIRectFill(rect); | |
| 72 UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); | |
| 73 UIGraphicsEndImageContext(); | |
| 74 return image; | |
|
lpromero
2017/03/06 10:29:00
No action needed: This seems orthogonal to the ini
gambard
2017/03/06 12:16:00
It should have been removed before sending for rev
lpromero
2017/03/06 13:02:30
No problem :)
| |
| 75 } | |
| 76 | |
| 63 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { | 77 - (void)configureCell:(ContentSuggestionsArticleCell*)cell { |
| 64 [super configureCell:cell]; | 78 [super configureCell:cell]; |
| 65 if (!self.image && !self.imageFetched) { | 79 if (!self.imageFetched) { |
| 66 self.imageFetched = YES; | 80 self.imageFetched = YES; |
| 67 // Fetch the image. During the fetch the cell's image should still be set to | 81 // Fetch the image. During the fetch the cell's image should still be set. |
| 68 // nil. | |
| 69 [self.delegate loadImageForArticleItem:self]; | 82 [self.delegate loadImageForArticleItem:self]; |
| 70 } | 83 } |
| 71 cell.titleLabel.text = self.title; | 84 cell.titleLabel.text = self.title; |
| 72 cell.subtitleLabel.text = self.subtitle; | 85 cell.subtitleLabel.text = self.subtitle; |
| 73 cell.imageView.image = self.image; | 86 cell.imageView.image = self.image; |
| 74 [cell setPublisherName:self.publisher date:self.publishDate]; | 87 [cell setPublisherName:self.publisher date:self.publishDate]; |
| 75 } | 88 } |
| 76 | 89 |
| 77 @end | 90 @end |
| 78 | 91 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 // Implements -layoutSubviews as per instructions in documentation for | 162 // Implements -layoutSubviews as per instructions in documentation for |
| 150 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. | 163 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:]. |
| 151 - (void)layoutSubviews { | 164 - (void)layoutSubviews { |
| 152 [super layoutSubviews]; | 165 [super layoutSubviews]; |
| 153 | 166 |
| 154 // Adjust the text label preferredMaxLayoutWidth when the parent's width | 167 // Adjust the text label preferredMaxLayoutWidth when the parent's width |
| 155 // changes, for instance on screen rotation. | 168 // changes, for instance on screen rotation. |
| 156 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); | 169 CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
| 157 | 170 |
| 158 self.titleLabel.preferredMaxLayoutWidth = | 171 self.titleLabel.preferredMaxLayoutWidth = |
| 159 parentWidth - self.imageView.bounds.size.width - 3 * kStandardSpacing; | 172 parentWidth - kImageSize - 3 * kStandardSpacing; |
| 160 self.subtitleLabel.preferredMaxLayoutWidth = | 173 self.subtitleLabel.preferredMaxLayoutWidth = |
| 161 parentWidth - self.imageView.bounds.size.width - 3 * kStandardSpacing; | 174 parentWidth - kImageSize - 3 * kStandardSpacing; |
|
lpromero
2017/03/06 10:29:00
No action needed: Idem, was this related to deleti
gambard
2017/03/06 12:16:00
Same.
| |
| 162 | 175 |
| 163 // Re-layout with the new preferred width to allow the label to adjust its | 176 // Re-layout with the new preferred width to allow the label to adjust its |
| 164 // height. | 177 // height. |
| 165 [super layoutSubviews]; | 178 [super layoutSubviews]; |
| 166 } | 179 } |
| 167 | 180 |
| 168 #pragma mark - Private | 181 #pragma mark - Private |
| 169 | 182 |
| 170 - (void)applyConstraints { | 183 - (void)applyConstraints { |
| 171 [NSLayoutConstraint activateConstraints:@[ | 184 [NSLayoutConstraint activateConstraints:@[ |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 191 @{ | 204 @{ |
| 192 @"image" : _imageView, | 205 @"image" : _imageView, |
| 193 @"title" : _titleLabel, | 206 @"title" : _titleLabel, |
| 194 @"text" : _subtitleLabel, | 207 @"text" : _subtitleLabel, |
| 195 @"publish" : _publisherLabel, | 208 @"publish" : _publisherLabel, |
| 196 }, | 209 }, |
| 197 @{ @"space" : @(kStandardSpacing) }); | 210 @{ @"space" : @(kStandardSpacing) }); |
| 198 } | 211 } |
| 199 | 212 |
| 200 @end | 213 @end |
| OLD | NEW |