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

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.mm

Issue 2706083002: Add publisher information on ContentSuggestionsArticles (Closed)
Patch Set: Fix compilation Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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..8bfb2525996765231fa6292ae2ca7ebe6359aafe 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
@@ -51,17 +54,25 @@ const CGFloat kStandardSpacing = 8;
cell.titleLabel.text = _title;
cell.subtitleLabel.text = _subtitle;
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 +80,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:(base::Time)publishDate {
+ NSDate* date = [NSDate dateWithTimeIntervalSince1970:publishDate.ToDoubleT()];
+ NSString* dateString =
+ [NSDateFormatter localizedStringFromDate:date
+ dateStyle:NSDateFormatterMediumStyle
+ timeStyle:NSDateFormatterNoStyle];
+
+ // TODO(crbug.com/694423): Make it RTL friendly.
+ self.publisherLabel.text =
+ [NSString stringWithFormat:@"%@ - %@.", publisherName, dateString];
+}
+
#pragma mark - UIView
// Implements -layoutSubviews as per instructions in documentation for
@@ -118,7 +151,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.

Powered by Google App Engine
This is Rietveld 408576698