Commit 0ac7ceb1 authored by olivierrobin's avatar olivierrobin Committed by Commit bot

Add Distillation info to Reading List view.

If page is distilled, show
- Date of distillation in relative format (1 hour ago, 2 days ago).
- The size of distillation files in human readable format.

BUG=694451

Review-Url: https://codereview.chromium.org/2751833005
Cr-Commit-Position: refs/heads/master@{#460426}
parent f2cdf464
...@@ -247,6 +247,8 @@ void ReadingListEntry::SetDistilledState(DistillationState distilled_state) { ...@@ -247,6 +247,8 @@ void ReadingListEntry::SetDistilledState(DistillationState distilled_state) {
distilled_state_ = distilled_state; distilled_state_ = distilled_state;
distilled_path_ = base::FilePath(); distilled_path_ = base::FilePath();
distilled_url_ = GURL::EmptyGURL(); distilled_url_ = GURL::EmptyGURL();
distillation_size_ = 0;
distillation_time_us_ = 0;
} }
int64_t ReadingListEntry::UpdateTime() const { int64_t ReadingListEntry::UpdateTime() const {
......
...@@ -1023,6 +1023,9 @@ Handoff must also be enabled in the General section of Settings, and your device ...@@ -1023,6 +1023,9 @@ Handoff must also be enabled in the General section of Settings, and your device
<message name="IDS_IOS_READING_LIST_EMPTY_MESSAGE" desc="Message to explain to the user how to add entries to the reading list" meaning="[Length: unlimited]"> <message name="IDS_IOS_READING_LIST_EMPTY_MESSAGE" desc="Message to explain to the user how to add entries to the reading list" meaning="[Length: unlimited]">
Your reading list is available offline. To add a page to your reading list, tap <ph name="SHARE_OPENING_ICON">SHARE_OPENING_ICON<ex>Menu > Share > Read Later</ex></ph>. Your reading list is available offline. To add a page to your reading list, tap <ph name="SHARE_OPENING_ICON">SHARE_OPENING_ICON<ex>Menu > Share > Read Later</ex></ph>.
</message> </message>
<message name="IDS_IOS_READING_LIST_JUST_NOW" desc="String indicating that an event (adding item, distillation) happened less than one minute ago. [Length: 25em]">
Just now
</message>
<message name="IDS_IOS_READING_LIST_MARK_ALL_BUTTON" desc="Label of the button to suggest options to mark all reading list entries read or unread [Length: 25em]" meaning="Display options letting the user mark all the entries as read or as unread. [Length: 25em]"> <message name="IDS_IOS_READING_LIST_MARK_ALL_BUTTON" desc="Label of the button to suggest options to mark all reading list entries read or unread [Length: 25em]" meaning="Display options letting the user mark all the entries as read or as unread. [Length: 25em]">
Mark All… Mark All…
</message> </message>
......
...@@ -53,10 +53,8 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -53,10 +53,8 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
}; };
typedef NS_ENUM(NSInteger, ItemType) { typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeUnreadHeader = kItemTypeEnumZero, ItemTypeHeader = kItemTypeEnumZero,
ItemTypeUnread, ItemTypeItem,
ItemTypeReadHeader,
ItemTypeRead,
}; };
// Typedef for a block taking a GURL as parameter and returning nothing. // Typedef for a block taking a GURL as parameter and returning nothing.
...@@ -319,7 +317,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>; ...@@ -319,7 +317,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
- (CGFloat)collectionView:(UICollectionView*)collectionView - (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath { cellHeightAtIndexPath:(NSIndexPath*)indexPath {
NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
if (type == ItemTypeUnread || type == ItemTypeRead) if (type == ItemTypeItem)
return MDCCellDefaultTwoLineHeight; return MDCCellDefaultTwoLineHeight;
else else
return MDCCellDefaultOneLineHeight; return MDCCellDefaultOneLineHeight;
...@@ -593,9 +591,11 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>; ...@@ -593,9 +591,11 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
ReadingListCollectionViewItem* newItem = iterator->second; ReadingListCollectionViewItem* newItem = iterator->second;
if (oldItem.url == newItem.url) { if (oldItem.url == newItem.url) {
if (![oldItem isEqual:newItem]) { if (![oldItem isEqual:newItem]) {
oldItem.text = newItem.text; oldItem.title = newItem.title;
oldItem.detailText = newItem.detailText; oldItem.subtitle = newItem.subtitle;
oldItem.distillationState = newItem.distillationState; oldItem.distillationState = newItem.distillationState;
oldItem.distillationDate = newItem.distillationDate;
oldItem.distillationSize = newItem.distillationSize;
[itemsToReconfigure addObject:oldItem]; [itemsToReconfigure addObject:oldItem];
} }
if (oldItem.faviconPageURL != newItem.faviconPageURL) { if (oldItem.faviconPageURL != newItem.faviconPageURL) {
...@@ -616,20 +616,27 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>; ...@@ -616,20 +616,27 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
(const ReadingListEntry&)entry { (const ReadingListEntry&)entry {
GURL url = entry.URL(); GURL url = entry.URL();
ReadingListCollectionViewItem* item = [[ReadingListCollectionViewItem alloc] ReadingListCollectionViewItem* item = [[ReadingListCollectionViewItem alloc]
initWithType:entry.IsRead() ? ItemTypeRead : ItemTypeUnread initWithType:ItemTypeItem
url:url url:url
distillationState:entry.DistilledState()]; distillationState:entry.DistilledState()];
[self setItem:item [self setItem:item
faviconURL:entry.DistilledURL().is_valid() ? entry.DistilledURL() : url]; faviconURL:entry.DistilledURL().is_valid() ? entry.DistilledURL() : url];
BOOL has_distillation_details =
entry.DistilledState() == ReadingListEntry::PROCESSED &&
entry.DistillationSize() != 0 && entry.DistillationTime() != 0;
NSString* fullUrlString = NSString* fullUrlString =
base::SysUTF16ToNSString(url_formatter::FormatUrl(url)); base::SysUTF16ToNSString(url_formatter::FormatUrl(url));
NSString* urlString = NSString* urlString =
base::SysUTF16ToNSString(url_formatter::FormatUrl(url.GetOrigin())); base::SysUTF16ToNSString(url_formatter::FormatUrl(url.GetOrigin()));
NSString* title = base::SysUTF8ToNSString(entry.Title()); NSString* title = base::SysUTF8ToNSString(entry.Title());
item.text = [title length] ? title : fullUrlString; item.title = [title length] ? title : fullUrlString;
item.detailText = urlString; item.subtitle = urlString;
item.distillationDate =
has_distillation_details ? entry.DistillationTime() : 0;
item.distillationSize =
has_distillation_details ? entry.DistillationSize() : 0;
return item; return item;
} }
...@@ -1165,17 +1172,14 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>; ...@@ -1165,17 +1172,14 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
- (CollectionViewTextItem*)headerForSection: - (CollectionViewTextItem*)headerForSection:
(SectionIdentifier)sectionIdentifier { (SectionIdentifier)sectionIdentifier {
CollectionViewTextItem* header = nil; CollectionViewTextItem* header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
switch (sectionIdentifier) { switch (sectionIdentifier) {
case SectionIdentifierRead: case SectionIdentifierRead:
header = [[CollectionViewTextItem alloc] initWithType:ItemTypeReadHeader];
header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_READ_HEADER); header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_READ_HEADER);
break; break;
case SectionIdentifierUnread: case SectionIdentifierUnread:
header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeUnreadHeader];
header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_UNREAD_HEADER); header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_UNREAD_HEADER);
break; break;
} }
......
...@@ -171,9 +171,9 @@ TEST_F(ReadingListCollectionViewControllerTest, ...@@ -171,9 +171,9 @@ TEST_F(ReadingListCollectionViewControllerTest,
base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( base::mac::ObjCCastStrict<ReadingListCollectionViewItem>(
[[reading_list_view_controller_ collectionViewModel] [[reading_list_view_controller_ collectionViewModel]
itemAtIndexPath:indexPath]); itemAtIndexPath:indexPath]);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); EXPECT_EQ(base::SysNSStringToUTF8([readingListItem title]), title);
EXPECT_EQ([readingListItem url], url); EXPECT_EQ([readingListItem url], url);
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), EXPECT_EQ(base::SysNSStringToUTF16([readingListItem subtitle]),
url_formatter::FormatUrl(url)); url_formatter::FormatUrl(url));
EXPECT_EQ([readingListItem faviconPageURL], url); EXPECT_EQ([readingListItem faviconPageURL], url);
EXPECT_EQ([readingListItem distillationState], ReadingListEntry::WAITING); EXPECT_EQ([readingListItem distillationState], ReadingListEntry::WAITING);
...@@ -203,9 +203,9 @@ TEST_F(ReadingListCollectionViewControllerTest, ...@@ -203,9 +203,9 @@ TEST_F(ReadingListCollectionViewControllerTest,
base::mac::ObjCCastStrict<ReadingListCollectionViewItem>( base::mac::ObjCCastStrict<ReadingListCollectionViewItem>(
[[reading_list_view_controller_ collectionViewModel] [[reading_list_view_controller_ collectionViewModel]
itemAtIndexPath:indexPath]); itemAtIndexPath:indexPath]);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title); EXPECT_EQ(base::SysNSStringToUTF8([readingListItem title]), title);
EXPECT_EQ([readingListItem url], url); EXPECT_EQ([readingListItem url], url);
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]), EXPECT_EQ(base::SysNSStringToUTF16([readingListItem subtitle]),
url_formatter::FormatUrl(url)); url_formatter::FormatUrl(url));
EXPECT_EQ([readingListItem faviconPageURL], distilled_url); EXPECT_EQ([readingListItem faviconPageURL], distilled_url);
EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED); EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED);
......
...@@ -16,10 +16,10 @@ class GURL; ...@@ -16,10 +16,10 @@ class GURL;
// Collection view item for representing a ReadingListEntry. // Collection view item for representing a ReadingListEntry.
@interface ReadingListCollectionViewItem : CollectionViewItem @interface ReadingListCollectionViewItem : CollectionViewItem
// The main text to display. // The title to display.
@property(nonatomic, copy) NSString* text; @property(nonatomic, copy) NSString* title;
// The secondary text to display. // The subtitle to display. This is often the |url|'s origin.
@property(nonatomic, copy) NSString* detailText; @property(nonatomic, copy) NSString* subtitle;
// The URL of the Reading List entry. // The URL of the Reading List entry.
@property(nonatomic, readonly) const GURL& url; @property(nonatomic, readonly) const GURL& url;
// The URL of the page presenting the favicon to display. // The URL of the page presenting the favicon to display.
...@@ -27,6 +27,10 @@ class GURL; ...@@ -27,6 +27,10 @@ class GURL;
// Status of the offline version. // Status of the offline version.
@property(nonatomic, assign) @property(nonatomic, assign)
ReadingListEntry::DistillationState distillationState; ReadingListEntry::DistillationState distillationState;
// Size of the distilled files.
@property(nonatomic, assign) int64_t distillationSize;
// Timestamp of the distillation in microseconds since Jan 1st 1970.
@property(nonatomic, assign) int64_t distillationDate;
// Delegate for the accessibility actions. // Delegate for the accessibility actions.
@property(nonatomic, weak) @property(nonatomic, weak)
id<ReadingListCollectionViewItemAccessibilityDelegate> id<ReadingListCollectionViewItemAccessibilityDelegate>
...@@ -51,9 +55,13 @@ class GURL; ...@@ -51,9 +55,13 @@ class GURL;
@interface ReadingListCell : MDCCollectionViewCell @interface ReadingListCell : MDCCollectionViewCell
// Title label. // Title label.
@property(nonatomic, readonly, strong) UILabel* textLabel; @property(nonatomic, readonly, strong) UILabel* titleLabel;
// Detail label. // Subtitle label.
@property(nonatomic, readonly, strong) UILabel* detailTextLabel; @property(nonatomic, readonly, strong) UILabel* subtitleLabel;
// Timestamp of the distillation in microseconds since Jan 1st 1970.
@property(nonatomic, assign) int64_t distillationDate;
// Size of the distilled files.
@property(nonatomic, assign) int64_t distillationSize;
// View for displaying the favicon for the reading list entry. // View for displaying the favicon for the reading list entry.
@property(nonatomic, readonly, strong) FaviconViewNew* faviconView; @property(nonatomic, readonly, strong) FaviconViewNew* faviconView;
// Status of the offline version. Updates the visual indicator when updated. // Status of the offline version. Updates the visual indicator when updated.
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" #import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h" #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#import "url/gurl.h" #import "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -28,6 +29,9 @@ const CGFloat kDistillationIndicatorSize = 18; ...@@ -28,6 +29,9 @@ const CGFloat kDistillationIndicatorSize = 18;
// Margin for the elements displayed in the cell. // Margin for the elements displayed in the cell.
const CGFloat kMargin = 16; const CGFloat kMargin = 16;
// Transparency of the distillation size and date.
const CGFloat kInfoTextTransparency = 0.38;
} // namespace } // namespace
#pragma mark - ReadingListCollectionViewItem #pragma mark - ReadingListCollectionViewItem
...@@ -43,11 +47,13 @@ const CGFloat kMargin = 16; ...@@ -43,11 +47,13 @@ const CGFloat kMargin = 16;
@implementation ReadingListCollectionViewItem @implementation ReadingListCollectionViewItem
@synthesize attributes = _attributes; @synthesize attributes = _attributes;
@synthesize text = _text; @synthesize title = _title;
@synthesize detailText = _detailText; @synthesize subtitle = _subtitle;
@synthesize url = _url; @synthesize url = _url;
@synthesize faviconPageURL = _faviconPageURL; @synthesize faviconPageURL = _faviconPageURL;
@synthesize distillationState = _distillationState; @synthesize distillationState = _distillationState;
@synthesize distillationDate = _distillationDate;
@synthesize distillationSize = _distillationSize;
@synthesize accessibilityDelegate = _accessibilityDelegate; @synthesize accessibilityDelegate = _accessibilityDelegate;
- (instancetype)initWithType:(NSInteger)type - (instancetype)initWithType:(NSInteger)type
...@@ -69,9 +75,11 @@ const CGFloat kMargin = 16; ...@@ -69,9 +75,11 @@ const CGFloat kMargin = 16;
if (self.attributes) { if (self.attributes) {
[cell.faviconView configureWithAttributes:self.attributes]; [cell.faviconView configureWithAttributes:self.attributes];
} }
cell.textLabel.text = self.text; cell.titleLabel.text = self.title;
cell.detailTextLabel.text = self.detailText; cell.subtitleLabel.text = self.subtitle;
cell.distillationState = _distillationState; cell.distillationState = _distillationState;
cell.distillationSize = _distillationSize;
cell.distillationDate = _distillationDate;
cell.isAccessibilityElement = YES; cell.isAccessibilityElement = YES;
cell.accessibilityLabel = [self accessibilityLabel]; cell.accessibilityLabel = [self accessibilityLabel];
cell.accessibilityCustomActions = [self customActions]; cell.accessibilityCustomActions = [self customActions];
...@@ -90,9 +98,9 @@ const CGFloat kMargin = 16; ...@@ -90,9 +98,9 @@ const CGFloat kMargin = 16;
} }
return l10n_util::GetNSStringF(IDS_IOS_READING_LIST_ENTRY_ACCESSIBILITY_LABEL, return l10n_util::GetNSStringF(IDS_IOS_READING_LIST_ENTRY_ACCESSIBILITY_LABEL,
base::SysNSStringToUTF16(self.text), base::SysNSStringToUTF16(self.title),
base::SysNSStringToUTF16(accessibilityState), base::SysNSStringToUTF16(accessibilityState),
base::SysNSStringToUTF16(self.detailText)); base::SysNSStringToUTF16(self.subtitle));
} }
#pragma mark - AccessibilityCustomAction #pragma mark - AccessibilityCustomAction
...@@ -195,7 +203,7 @@ const CGFloat kMargin = 16; ...@@ -195,7 +203,7 @@ const CGFloat kMargin = 16;
- (NSString*)description { - (NSString*)description {
return [NSString stringWithFormat:@"Reading List item \"%@\" for url %@", return [NSString stringWithFormat:@"Reading List item \"%@\" for url %@",
self.text, self.detailText]; self.title, self.subtitle];
} }
- (BOOL)isEqual:(id)other { - (BOOL)isEqual:(id)other {
...@@ -205,9 +213,11 @@ const CGFloat kMargin = 16; ...@@ -205,9 +213,11 @@ const CGFloat kMargin = 16;
return NO; return NO;
ReadingListCollectionViewItem* otherItem = ReadingListCollectionViewItem* otherItem =
static_cast<ReadingListCollectionViewItem*>(other); static_cast<ReadingListCollectionViewItem*>(other);
return [self.text isEqualToString:otherItem.text] && return [self.title isEqualToString:otherItem.title] &&
[self.detailText isEqualToString:otherItem.detailText] && [self.subtitle isEqualToString:otherItem.subtitle] &&
self.distillationState == otherItem.distillationState; self.distillationState == otherItem.distillationState &&
self.distillationSize == otherItem.distillationSize &&
self.distillationDate == otherItem.distillationDate;
} }
@end @end
...@@ -216,10 +226,22 @@ const CGFloat kMargin = 16; ...@@ -216,10 +226,22 @@ const CGFloat kMargin = 16;
@implementation ReadingListCell { @implementation ReadingListCell {
UIImageView* _downloadIndicator; UIImageView* _downloadIndicator;
UILayoutGuide* _textGuide;
UILabel* _distillationSizeLabel;
UILabel* _distillationDateLabel;
// View containing |_distillationSizeLabel| and |_distillationDateLabel|.
UIView* _infoView;
// Whether |_infoView| is visible.
BOOL _showInfo;
} }
@synthesize faviconView = _faviconView; @synthesize faviconView = _faviconView;
@synthesize textLabel = _textLabel; @synthesize titleLabel = _titleLabel;
@synthesize detailTextLabel = _detailTextLabel; @synthesize subtitleLabel = _subtitleLabel;
@synthesize distillationDate = _distillationDate;
@synthesize distillationSize = _distillationSize;
@synthesize distillationState = _distillationState; @synthesize distillationState = _distillationState;
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
...@@ -227,15 +249,33 @@ const CGFloat kMargin = 16; ...@@ -227,15 +249,33 @@ const CGFloat kMargin = 16;
if (self) { if (self) {
MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance]; MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance];
CGFloat faviconSize = kFaviconPreferredSize; CGFloat faviconSize = kFaviconPreferredSize;
_textLabel = [[UILabel alloc] init]; _titleLabel = [[UILabel alloc] init];
_textLabel.font = [fontLoader mediumFontOfSize:16]; _titleLabel.font = [fontLoader mediumFontOfSize:16];
_textLabel.textColor = [[MDCPalette greyPalette] tint900]; _titleLabel.textColor = [[MDCPalette greyPalette] tint900];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO; _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_detailTextLabel = [[UILabel alloc] init]; _subtitleLabel = [[UILabel alloc] init];
_detailTextLabel.font = [fontLoader mediumFontOfSize:14]; _subtitleLabel.font = [fontLoader mediumFontOfSize:14];
_detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; _subtitleLabel.textColor = [[MDCPalette greyPalette] tint500];
_detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO; _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_distillationDateLabel = [[UILabel alloc] init];
_distillationDateLabel.font = [fontLoader mediumFontOfSize:12];
[_distillationDateLabel
setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
_distillationDateLabel.textColor =
[UIColor colorWithWhite:0 alpha:kInfoTextTransparency];
_distillationDateLabel.translatesAutoresizingMaskIntoConstraints = NO;
_distillationSizeLabel = [[UILabel alloc] init];
_distillationSizeLabel.font = [fontLoader mediumFontOfSize:12];
[_distillationSizeLabel
setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
_distillationSizeLabel.textColor =
[UIColor colorWithWhite:0 alpha:kInfoTextTransparency];
_distillationSizeLabel.translatesAutoresizingMaskIntoConstraints = NO;
_faviconView = [[FaviconViewNew alloc] init]; _faviconView = [[FaviconViewNew alloc] init];
CGFloat fontSize = floorf(faviconSize / 2); CGFloat fontSize = floorf(faviconSize / 2);
...@@ -246,29 +286,58 @@ const CGFloat kMargin = 16; ...@@ -246,29 +286,58 @@ const CGFloat kMargin = 16;
[_downloadIndicator setTranslatesAutoresizingMaskIntoConstraints:NO]; [_downloadIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];
[_faviconView addSubview:_downloadIndicator]; [_faviconView addSubview:_downloadIndicator];
[self.contentView addSubview:_textLabel];
[self.contentView addSubview:_detailTextLabel];
[self.contentView addSubview:_faviconView]; [self.contentView addSubview:_faviconView];
[self.contentView addSubview:_titleLabel];
[self.contentView addSubview:_subtitleLabel];
_infoView = [[UIView alloc] initWithFrame:CGRectZero];
[_infoView addSubview:_distillationDateLabel];
[_infoView addSubview:_distillationSizeLabel];
_infoView.translatesAutoresizingMaskIntoConstraints = NO;
_textGuide = [[UILayoutGuide alloc] init];
[self.contentView addLayoutGuide:_textGuide];
ApplyVisualConstraintsWithMetrics( ApplyVisualConstraintsWithMetrics(
@[ @[
@"V:|-(margin)-[title][text]-(margin)-|", @"H:|[date]-(>=margin)-[size]|",
@"V:[title][subtitle]",
@"H:|-(margin)-[favicon]-(margin)-[title]-(>=margin)-|", @"H:|-(margin)-[favicon]-(margin)-[title]-(>=margin)-|",
@"H:[favicon]-(margin)-[text]-(>=margin)-|" @"H:[favicon]-(margin)-[subtitle]-(>=margin)-|",
@"V:|[date]|",
@"V:|[size]|",
], ],
@{ @{
@"title" : _textLabel, @"favicon" : _faviconView,
@"text" : _detailTextLabel, @"title" : _titleLabel,
@"favicon" : _faviconView @"subtitle" : _subtitleLabel,
@"date" : _distillationDateLabel,
@"size" : _distillationSizeLabel,
}, },
@{ @"margin" : @(kMargin) }); @{
@"margin" : @(kMargin),
});
// Sets the bottom of the text. Lower the priority so we can add the details
// later.
NSLayoutConstraint* bottomTextConstraint = [_textGuide.bottomAnchor
constraintEqualToAnchor:_subtitleLabel.bottomAnchor];
bottomTextConstraint.priority = UILayoutPriorityDefaultHigh;
NSLayoutConstraint* topTextConstraint =
[_textGuide.topAnchor constraintEqualToAnchor:_titleLabel.topAnchor];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
topTextConstraint,
bottomTextConstraint,
// Favicons are always the same size. // Favicons are always the same size.
[_faviconView.widthAnchor constraintEqualToConstant:faviconSize], [_faviconView.widthAnchor constraintEqualToConstant:faviconSize],
[_faviconView.heightAnchor constraintEqualToConstant:faviconSize], [_faviconView.heightAnchor constraintEqualToConstant:faviconSize],
// Center the content (favicon and text) vertically.
[_faviconView.centerYAnchor [_faviconView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor], constraintEqualToAnchor:self.contentView.centerYAnchor],
[_textGuide.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
// Place the download indicator in the bottom right corner of the favicon. // Place the download indicator in the bottom right corner of the favicon.
[[_downloadIndicator centerXAnchor] [[_downloadIndicator centerXAnchor]
constraintEqualToAnchor:_faviconView.trailingAnchor], constraintEqualToAnchor:_faviconView.trailingAnchor],
...@@ -309,12 +378,72 @@ const CGFloat kMargin = 16; ...@@ -309,12 +378,72 @@ const CGFloat kMargin = 16;
} }
} }
- (void)setShowInfo:(BOOL)show {
if (_showInfo == show) {
return;
}
_showInfo = show;
if (!show) {
[_infoView removeFromSuperview];
return;
}
[self.contentView addSubview:_infoView];
ApplyVisualConstraintsWithMetrics(
@[
@"H:|-(margin)-[favicon]-(margin)-[detail]-(margin)-|",
],
@{
@"favicon" : _faviconView,
@"detail" : _infoView,
},
@{
@"margin" : @(kMargin),
});
[NSLayoutConstraint activateConstraints:@[
[_infoView.topAnchor constraintEqualToAnchor:_subtitleLabel.bottomAnchor],
[_infoView.bottomAnchor constraintEqualToAnchor:_textGuide.bottomAnchor],
]];
}
- (void)setDistillationSize:(int64_t)distillationSize {
[_distillationSizeLabel
setText:[NSByteCountFormatter
stringFromByteCount:distillationSize
countStyle:NSByteCountFormatterCountStyleFile]];
_distillationSize = distillationSize;
BOOL showInfo = _distillationSize != 0 && _distillationDate != 0;
[self setShowInfo:showInfo];
}
- (void)setDistillationDate:(int64_t)distillationDate {
int64_t now = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
int64_t elapsed = now - distillationDate;
NSString* text;
if (elapsed < base::Time::kMicrosecondsPerMinute) {
// This will also catch items added in the future. In that case, show the
// "just now" string.
text = l10n_util::GetNSString(IDS_IOS_READING_LIST_JUST_NOW);
} else {
text = base::SysUTF16ToNSString(ui::TimeFormat::Simple(
ui::TimeFormat::FORMAT_ELAPSED, ui::TimeFormat::LENGTH_LONG,
base::TimeDelta::FromMicroseconds(elapsed)));
}
[_distillationDateLabel setText:text];
_distillationDate = distillationDate;
BOOL showInfo = _distillationSize != 0 && _distillationDate != 0;
[self setShowInfo:showInfo];
}
#pragma mark - UICollectionViewCell #pragma mark - UICollectionViewCell
- (void)prepareForReuse { - (void)prepareForReuse {
self.textLabel.text = nil; self.titleLabel.text = nil;
self.detailTextLabel.text = nil; self.subtitleLabel.text = nil;
self.distillationState = ReadingListEntry::WAITING; self.distillationState = ReadingListEntry::WAITING;
self.distillationDate = 0;
self.distillationSize = 0;
[self setShowInfo:NO];
self.accessibilityCustomActions = nil; self.accessibilityCustomActions = nil;
[super prepareForReuse]; [super prepareForReuse];
} }
......
...@@ -153,8 +153,8 @@ enum UMAContextMenuAction { ...@@ -153,8 +153,8 @@ enum UMAContextMenuAction {
_alertCoordinator = [[ActionSheetCoordinator alloc] _alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:self.containerViewController initWithBaseViewController:self.containerViewController
title:readingListItem.text title:readingListItem.title
message:readingListItem.detailText message:readingListItem.subtitle
rect:CGRectMake(menuLocation.x, menuLocation.y, 0, rect:CGRectMake(menuLocation.x, menuLocation.y, 0,
0) 0)
view:readingListCollectionViewController view:readingListCollectionViewController
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment