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

Unified Diff: ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm

Issue 2751833005: Add Distillation info to Reading List view. (Closed)
Patch Set: clean 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm
diff --git a/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm b/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm
index b488546cf267024fce3f1af47b04206769bea237..88f1e5f78bff67c085a1f8bfeb2faf4210629342 100644
--- a/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm
+++ b/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm
@@ -13,6 +13,7 @@
#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"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/l10n/time_format.h"
#import "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -28,6 +29,8 @@ const CGFloat kDistillationIndicatorSize = 18;
// Margin for the elements displayed in the cell.
gambard 2017/03/16 07:50:23 Update the comment
Olivier 2017/03/16 09:20:15 Done.
const CGFloat kMargin = 16;
+// Margin for the elements displayed in the cell.
gambard 2017/03/16 07:50:24 Change this comment (this is the margin between th
Olivier 2017/03/16 09:20:15 Done.
+const CGFloat kDetailsMargin = 7;
} // namespace
#pragma mark - ReadingListCell Private interface
@@ -45,6 +48,11 @@ const CGFloat kMargin = 16;
@property(nonatomic, assign)
ReadingListEntry::DistillationState distillationState;
+// 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;
+
@end
#pragma mark - ReadingListCollectionViewItem
@@ -69,12 +77,14 @@ const CGFloat kMargin = 16;
@implementation ReadingListCollectionViewItem
@synthesize faviconAttributesProvider = _faviconAttributesProvider;
@synthesize attributes = _attributes;
-@synthesize text = _text;
-@synthesize detailText = _detailText;
+@synthesize title = _title;
+@synthesize subtitle = _subtitle;
@synthesize url = _url;
@synthesize faviconPageURL = _faviconPageURL;
@synthesize displayedCell = _displayedCell;
@synthesize distillationState = _distillationState;
+@synthesize distillationDate = _distillationDate;
+@synthesize distillationSize = _distillationSize;
@synthesize accessibilityDelegate = _accessibilityDelegate;
- (instancetype)initWithType:(NSInteger)type
@@ -121,6 +131,16 @@ const CGFloat kMargin = 16;
_distillationState = distillationState;
}
+- (void)setDistillationSize:(int64_t)distillationSize {
+ self.displayedCell.distillationSize = distillationSize;
+ _distillationSize = distillationSize;
+}
+
+- (void)setDistillationDate:(int64_t)distillationDate {
+ self.displayedCell.distillationDate = distillationDate;
+ _distillationDate = distillationDate;
+}
+
#pragma mark - CollectionViewTextItem
- (void)configureCell:(ReadingListCell*)cell {
@@ -128,11 +148,13 @@ const CGFloat kMargin = 16;
if (self.attributes) {
[cell.faviconView configureWithAttributes:self.attributes];
}
- cell.textLabel.text = self.text;
- cell.detailTextLabel.text = self.detailText;
+ cell.titleLabel.text = self.title;
+ cell.subtitleLabel.text = self.subtitle;
self.displayedCell = cell;
cell.delegate = self;
cell.distillationState = _distillationState;
+ cell.distillationSize = _distillationSize;
+ cell.distillationDate = _distillationDate;
cell.isAccessibilityElement = YES;
cell.accessibilityLabel = [self accessibilityLabel];
cell.accessibilityCustomActions = [self customActions];
@@ -157,9 +179,9 @@ const CGFloat kMargin = 16;
}
return l10n_util::GetNSStringF(IDS_IOS_READING_LIST_ENTRY_ACCESSIBILITY_LABEL,
- base::SysNSStringToUTF16(self.text),
+ base::SysNSStringToUTF16(self.title),
base::SysNSStringToUTF16(accessibilityState),
- base::SysNSStringToUTF16(self.detailText));
+ base::SysNSStringToUTF16(self.subtitle));
}
#pragma mark - AccessibilityCustomAction
@@ -262,7 +284,7 @@ const CGFloat kMargin = 16;
- (NSString*)description {
return [NSString stringWithFormat:@"Reading List item \"%@\" for url %@",
- self.text, self.detailText];
+ self.title, self.subtitle];
}
- (BOOL)isEqual:(id)other {
@@ -272,9 +294,12 @@ const CGFloat kMargin = 16;
return NO;
ReadingListCollectionViewItem* otherItem =
static_cast<ReadingListCollectionViewItem*>(other);
- return [self.text isEqualToString:otherItem.text] &&
- [self.detailText isEqualToString:otherItem.detailText] &&
- self.distillationState == otherItem.distillationState;
+ return self.type == otherItem.type &&
+ [self.title isEqualToString:otherItem.title] &&
+ [self.subtitle isEqualToString:otherItem.subtitle] &&
+ self.distillationState == otherItem.distillationState &&
+ self.distillationSize == otherItem.distillationSize &&
+ self.distillationDate == otherItem.distillationDate;
}
@end
@@ -285,8 +310,12 @@ const CGFloat kMargin = 16;
UIImageView* _downloadIndicator;
}
@synthesize faviconView = _faviconView;
-@synthesize textLabel = _textLabel;
-@synthesize detailTextLabel = _detailTextLabel;
+@synthesize titleLabel = _titleLabel;
+@synthesize subtitleLabel = _subtitleLabel;
+@synthesize distillationDateLabel = _distillationDateLabel;
+@synthesize distillationDate = _distillationDate;
+@synthesize distillationSizeLabel = _distillationSizeLabel;
+@synthesize distillationSize = _distillationSize;
@synthesize distillationState = _distillationState;
@synthesize delegate = _delegate;
@@ -295,15 +324,25 @@ const CGFloat kMargin = 16;
if (self) {
MDFRobotoFontLoader* fontLoader = [MDFRobotoFontLoader sharedInstance];
CGFloat faviconSize = kFaviconPreferredSize;
- _textLabel = [[UILabel alloc] init];
- _textLabel.font = [fontLoader mediumFontOfSize:16];
- _textLabel.textColor = [[MDCPalette greyPalette] tint900];
- _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
-
- _detailTextLabel = [[UILabel alloc] init];
- _detailTextLabel.font = [fontLoader mediumFontOfSize:14];
- _detailTextLabel.textColor = [[MDCPalette greyPalette] tint500];
- _detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
+ _titleLabel = [[UILabel alloc] init];
+ _titleLabel.font = [fontLoader mediumFontOfSize:16];
+ _titleLabel.textColor = [[MDCPalette greyPalette] tint900];
+ _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
+
+ _subtitleLabel = [[UILabel alloc] init];
+ _subtitleLabel.font = [fontLoader mediumFontOfSize:14];
+ _subtitleLabel.textColor = [[MDCPalette greyPalette] tint500];
+ _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO;
+
+ _distillationDateLabel = [[UILabel alloc] init];
+ _distillationDateLabel.font = [fontLoader mediumFontOfSize:12];
+ _distillationDateLabel.textColor = [UIColor colorWithWhite:0 alpha:0.38];
+ _distillationDateLabel.translatesAutoresizingMaskIntoConstraints = NO;
+
+ _distillationSizeLabel = [[UILabel alloc] init];
+ _distillationSizeLabel.font = [fontLoader mediumFontOfSize:12];
+ _distillationSizeLabel.textColor = [UIColor colorWithWhite:0 alpha:0.38];
+ _distillationSizeLabel.translatesAutoresizingMaskIntoConstraints = NO;
_faviconView = [[FaviconViewNew alloc] init];
CGFloat fontSize = floorf(faviconSize / 2);
@@ -314,30 +353,42 @@ const CGFloat kMargin = 16;
[_downloadIndicator setTranslatesAutoresizingMaskIntoConstraints:NO];
[_faviconView addSubview:_downloadIndicator];
- [self.contentView addSubview:_textLabel];
- [self.contentView addSubview:_detailTextLabel];
+ [self.contentView addSubview:_titleLabel];
+ [self.contentView addSubview:_subtitleLabel];
[self.contentView addSubview:_faviconView];
+ [self.contentView addSubview:_distillationDateLabel];
+ [self.contentView addSubview:_distillationSizeLabel];
+ NSString* dateSizeFormat =
+ @"H:|-(margin)-[favicon]-(margin)-[date]-(>=margin)-[size]-(margin)-|";
ApplyVisualConstraintsWithMetrics(
@[
- @"V:|-(margin)-[title][text]-(margin)-|",
+ @"V:|-(margin)-[favicon]", @"V:|-(margin)-[title][subtitle]",
@"H:|-(margin)-[favicon]-(margin)-[title]-(>=margin)-|",
- @"H:[favicon]-(margin)-[text]-(>=margin)-|"
+ dateSizeFormat, @"H:[favicon]-(margin)-[subtitle]-(>=margin)-|"
],
@{
- @"title" : _textLabel,
- @"text" : _detailTextLabel,
- @"favicon" : _faviconView
+ @"title" : _titleLabel,
+ @"subtitle" : _subtitleLabel,
+ @"favicon" : _faviconView,
+ @"date" : _distillationDateLabel,
+ @"size" : _distillationSizeLabel,
},
- @{ @"margin" : @(kMargin) });
+ @{
+ @"margin" : @(kMargin),
+ });
[NSLayoutConstraint activateConstraints:@[
// Favicons are always the same size.
[_faviconView.widthAnchor constraintEqualToConstant:faviconSize],
[_faviconView.heightAnchor constraintEqualToConstant:faviconSize],
- [_faviconView.centerYAnchor
- constraintEqualToAnchor:self.contentView.centerYAnchor],
// Place the download indicator in the bottom right corner of the favicon.
gambard 2017/03/16 07:50:24 This comment should be below the added constraints
Olivier 2017/03/16 09:20:14 Done.
+ [_distillationDateLabel.topAnchor
gambard 2017/03/16 07:50:23 Add a comment for the constraints
Olivier 2017/03/16 09:20:15 Done.
+ constraintEqualToAnchor:_subtitleLabel.bottomAnchor
+ constant:kDetailsMargin],
+ [_distillationSizeLabel.topAnchor
+ constraintEqualToAnchor:_subtitleLabel.bottomAnchor
+ constant:kDetailsMargin],
[[_downloadIndicator centerXAnchor]
constraintEqualToAnchor:_faviconView.trailingAnchor],
[[_downloadIndicator centerYAnchor]
@@ -377,13 +428,42 @@ const CGFloat kMargin = 16;
}
}
+- (void)setDistillationSize:(int64_t)distillationSize {
+ self.distillationSizeLabel.hidden = distillationSize == 0;
+ [self.distillationSizeLabel
+ setText:[NSByteCountFormatter
+ stringFromByteCount:distillationSize
+ countStyle:NSByteCountFormatterCountStyleFile]];
+ _distillationSize = distillationSize;
+}
+
+- (void)setDistillationDate:(int64_t)distillationDate {
+ self.distillationDateLabel.hidden = distillationDate == 0;
+ int64_t now = (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
+ // Ellapsed is negative as required by TimeFormat.
gambard 2017/03/16 07:50:23 Are you sure it is negative? |now| should be > |di
gambard 2017/03/16 07:50:24 s/Ellapsed/Elapsed
Olivier 2017/03/16 09:20:15 No, you are right, it is positive.
+ 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)));
+ }
+
+ [self.distillationDateLabel setText:text];
+ _distillationDate = distillationDate;
+}
+
#pragma mark - UICollectionViewCell
- (void)prepareForReuse {
[self.delegate readingListCellWillPrepareForReload:self];
self.delegate = nil;
- self.textLabel.text = nil;
- self.detailTextLabel.text = nil;
+ self.titleLabel.text = nil;
+ self.subtitleLabel.text = nil;
gambard 2017/03/16 07:50:24 You should probably set the date and size to zero
Olivier 2017/03/16 09:20:15 Done.
self.distillationState = ReadingListEntry::WAITING;
self.accessibilityCustomActions = nil;
[super prepareForReuse];

Powered by Google App Engine
This is Rietveld 408576698