Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm |
| index 7b956b32badfa2fda7a8d295565277f5ac262c51..b71fe4d3f25c5c57492e38b5aade9ef77739dfa9 100644 |
| --- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm |
| @@ -4,6 +4,7 @@ |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.h" |
| +#include "base/time/time.h" |
| #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| @@ -29,6 +30,8 @@ const CGFloat kStandardSpacing = 8; |
| @synthesize subtitle = _subtitle; |
| @synthesize image = _image; |
| @synthesize articleURL = _articleURL; |
| +@synthesize publisher = _publisher; |
| +@synthesize publishDate = _publishDate; |
| - (instancetype)initWithType:(NSInteger)type |
| title:(NSString*)title |
| @@ -49,19 +52,29 @@ const CGFloat kStandardSpacing = 8; |
| - (void)configureCell:(ContentSuggestionsArticleCell*)cell { |
| [super configureCell:cell]; |
| cell.titleLabel.text = _title; |
| - cell.subtitleLabel.text = _subtitle; |
| + cell.subtitleLabel.text = [_subtitle |
| + stringByTrimmingCharactersInSet:[NSCharacterSet |
|
jif
2017/02/20 16:01:00
IMO stringByTrimmingCharactersInSet should be done
gambard
2017/02/21 08:49:46
This is a typo. I removed it.
|
| + whitespaceAndNewlineCharacterSet]]; |
| cell.imageView.image = _image; |
| + [cell setPublisherName:self.publisher date:self.publishDate]; |
| } |
| @end |
| #pragma mark - ContentSuggestionsArticleCell |
| +@interface ContentSuggestionsArticleCell () |
| + |
| +@property(nonatomic, strong) UILabel* publisherLabel; |
| + |
| +@end |
| + |
| @implementation ContentSuggestionsArticleCell |
| @synthesize titleLabel = _titleLabel; |
| @synthesize subtitleLabel = _subtitleLabel; |
| @synthesize imageView = _imageView; |
| +@synthesize publisherLabel = _publisherLabel; |
| - (instancetype)initWithFrame:(CGRect)frame { |
| self = [super initWithFrame:frame]; |
| @@ -69,45 +82,67 @@ const CGFloat kStandardSpacing = 8; |
| _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| + _publisherLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| _subtitleLabel.numberOfLines = 0; |
| + [_subtitleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh |
| + forAxis:UILayoutConstraintAxisVertical]; |
| + [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh |
| + forAxis:UILayoutConstraintAxisVertical]; |
| _imageView.contentMode = UIViewContentModeScaleAspectFit; |
| _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| + _publisherLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| [self.contentView addSubview:_imageView]; |
| [self.contentView addSubview:_titleLabel]; |
| [self.contentView addSubview:_subtitleLabel]; |
| + [self.contentView addSubview:_publisherLabel]; |
| [NSLayoutConstraint activateConstraints:@[ |
| - [self.contentView.bottomAnchor |
| + [_imageView.widthAnchor constraintLessThanOrEqualToConstant:kImageSize], |
| + [_imageView.heightAnchor constraintLessThanOrEqualToConstant:kImageSize], |
| + [_publisherLabel.topAnchor |
| constraintGreaterThanOrEqualToAnchor:_imageView.bottomAnchor |
| constant:kStandardSpacing], |
| - [self.contentView.bottomAnchor |
| + [_publisherLabel.topAnchor |
| constraintGreaterThanOrEqualToAnchor:_subtitleLabel.bottomAnchor |
| constant:kStandardSpacing], |
| - [_imageView.widthAnchor constraintLessThanOrEqualToConstant:kImageSize], |
| - [_imageView.heightAnchor constraintLessThanOrEqualToConstant:kImageSize] |
| ]]; |
| ApplyVisualConstraints( |
| @[ |
| @"H:|-[title]-[image]-|", |
| @"H:|-[text]-[image]", |
| - @"V:|-[title]-[text]-|", |
| + @"V:|-[title]-[text]", |
| @"V:|-[image]", |
| + @"H:|-[publish]-|", |
| + @"V:[publish]-|", |
| ], |
| @{ |
| @"image" : _imageView, |
| @"title" : _titleLabel, |
| - @"text" : _subtitleLabel |
| + @"text" : _subtitleLabel, |
| + @"publish" : _publisherLabel, |
| }); |
| } |
| return self; |
| } |
| +- (void)setPublisherName:(NSString*)publisherName |
| + date:(const base::Time&)publishDate { |
| + NSDate* date = [NSDate dateWithTimeIntervalSince1970:publishDate.ToDoubleT()]; |
| + NSString* dateString = |
| + [NSDateFormatter localizedStringFromDate:date |
| + dateStyle:NSDateFormatterMediumStyle |
| + timeStyle:NSDateFormatterNoStyle]; |
| + |
| + self.publisherLabel.text = |
| + [NSString stringWithFormat:@"%@ - %@.", publisherName, dateString]; |
|
jif
2017/02/20 16:01:00
not RTL friendly :'(
gambard
2017/02/21 08:49:46
I added a TODO.
|
| +} |
| + |
| #pragma mark - UIView |
| // Implements -layoutSubviews as per instructions in documentation for |
| @@ -118,7 +153,8 @@ const CGFloat kStandardSpacing = 8; |
| // Adjust the text label preferredMaxLayoutWidth when the parent's width |
| // changes, for instance on screen rotation. |
| CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
| - self.subtitleLabel.preferredMaxLayoutWidth = parentWidth - kImageSize - 3 * 8; |
| + self.subtitleLabel.preferredMaxLayoutWidth = |
| + parentWidth - self.imageView.bounds.size.width - 3 * 8; |
| // Re-layout with the new preferred width to allow the label to adjust its |
| // height. |