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) {
distilled_state_ = distilled_state;
distilled_path_ = base::FilePath();
distilled_url_ = GURL::EmptyGURL();
distillation_size_ = 0;
distillation_time_us_ = 0;
}
int64_t ReadingListEntry::UpdateTime() const {
......
......@@ -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]">
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 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]">
Mark All…
</message>
......
......@@ -53,10 +53,8 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
};
typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeUnreadHeader = kItemTypeEnumZero,
ItemTypeUnread,
ItemTypeReadHeader,
ItemTypeRead,
ItemTypeHeader = kItemTypeEnumZero,
ItemTypeItem,
};
// Typedef for a block taking a GURL as parameter and returning nothing.
......@@ -319,7 +317,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
- (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath {
NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
if (type == ItemTypeUnread || type == ItemTypeRead)
if (type == ItemTypeItem)
return MDCCellDefaultTwoLineHeight;
else
return MDCCellDefaultOneLineHeight;
......@@ -593,9 +591,11 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
ReadingListCollectionViewItem* newItem = iterator->second;
if (oldItem.url == newItem.url) {
if (![oldItem isEqual:newItem]) {
oldItem.text = newItem.text;
oldItem.detailText = newItem.detailText;
oldItem.title = newItem.title;
oldItem.subtitle = newItem.subtitle;
oldItem.distillationState = newItem.distillationState;
oldItem.distillationDate = newItem.distillationDate;
oldItem.distillationSize = newItem.distillationSize;
[itemsToReconfigure addObject:oldItem];
}
if (oldItem.faviconPageURL != newItem.faviconPageURL) {
......@@ -616,20 +616,27 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
(const ReadingListEntry&)entry {
GURL url = entry.URL();
ReadingListCollectionViewItem* item = [[ReadingListCollectionViewItem alloc]
initWithType:entry.IsRead() ? ItemTypeRead : ItemTypeUnread
initWithType:ItemTypeItem
url:url
distillationState:entry.DistilledState()];
[self setItem:item
faviconURL:entry.DistilledURL().is_valid() ? entry.DistilledURL() : url];
BOOL has_distillation_details =
entry.DistilledState() == ReadingListEntry::PROCESSED &&
entry.DistillationSize() != 0 && entry.DistillationTime() != 0;
NSString* fullUrlString =
base::SysUTF16ToNSString(url_formatter::FormatUrl(url));
NSString* urlString =
base::SysUTF16ToNSString(url_formatter::FormatUrl(url.GetOrigin()));
NSString* title = base::SysUTF8ToNSString(entry.Title());
item.text = [title length] ? title : fullUrlString;
item.detailText = urlString;
item.title = [title length] ? title : fullUrlString;
item.subtitle = urlString;
item.distillationDate =
has_distillation_details ? entry.DistillationTime() : 0;
item.distillationSize =
has_distillation_details ? entry.DistillationSize() : 0;
return item;
}
......@@ -1165,17 +1172,14 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
- (CollectionViewTextItem*)headerForSection:
(SectionIdentifier)sectionIdentifier {
CollectionViewTextItem* header = nil;
CollectionViewTextItem* header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeHeader];
switch (sectionIdentifier) {
case SectionIdentifierRead:
header = [[CollectionViewTextItem alloc] initWithType:ItemTypeReadHeader];
header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_READ_HEADER);
break;
case SectionIdentifierUnread:
header =
[[CollectionViewTextItem alloc] initWithType:ItemTypeUnreadHeader];
header.text = l10n_util::GetNSString(IDS_IOS_READING_LIST_UNREAD_HEADER);
break;
}
......
......@@ -171,9 +171,9 @@ TEST_F(ReadingListCollectionViewControllerTest,
base::mac::ObjCCastStrict<ReadingListCollectionViewItem>(
[[reading_list_view_controller_ collectionViewModel]
itemAtIndexPath:indexPath]);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem title]), title);
EXPECT_EQ([readingListItem url], url);
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]),
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem subtitle]),
url_formatter::FormatUrl(url));
EXPECT_EQ([readingListItem faviconPageURL], url);
EXPECT_EQ([readingListItem distillationState], ReadingListEntry::WAITING);
......@@ -203,9 +203,9 @@ TEST_F(ReadingListCollectionViewControllerTest,
base::mac::ObjCCastStrict<ReadingListCollectionViewItem>(
[[reading_list_view_controller_ collectionViewModel]
itemAtIndexPath:indexPath]);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem text]), title);
EXPECT_EQ(base::SysNSStringToUTF8([readingListItem title]), title);
EXPECT_EQ([readingListItem url], url);
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem detailText]),
EXPECT_EQ(base::SysNSStringToUTF16([readingListItem subtitle]),
url_formatter::FormatUrl(url));
EXPECT_EQ([readingListItem faviconPageURL], distilled_url);
EXPECT_EQ([readingListItem distillationState], ReadingListEntry::PROCESSED);
......
......@@ -16,10 +16,10 @@ class GURL;
// Collection view item for representing a ReadingListEntry.
@interface ReadingListCollectionViewItem : CollectionViewItem
// The main text to display.
@property(nonatomic, copy) NSString* text;
// The secondary text to display.
@property(nonatomic, copy) NSString* detailText;
// The title to display.
@property(nonatomic, copy) NSString* title;
// The subtitle to display. This is often the |url|'s origin.
@property(nonatomic, copy) NSString* subtitle;
// The URL of the Reading List entry.
@property(nonatomic, readonly) const GURL& url;
// The URL of the page presenting the favicon to display.
......@@ -27,6 +27,10 @@ class GURL;
// Status of the offline version.
@property(nonatomic, assign)
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.
@property(nonatomic, weak)
id<ReadingListCollectionViewItemAccessibilityDelegate>
......@@ -51,9 +55,13 @@ class GURL;
@interface ReadingListCell : MDCCollectionViewCell
// Title label.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Detail label.
@property(nonatomic, readonly, strong) UILabel* detailTextLabel;
@property(nonatomic, readonly, strong) UILabel* titleLabel;
// Subtitle label.
@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.
@property(nonatomic, readonly, strong) FaviconViewNew* faviconView;
// Status of the offline version. Updates the visual indicator when updated.
......
......@@ -153,8 +153,8 @@ enum UMAContextMenuAction {
_alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:self.containerViewController
title:readingListItem.text
message:readingListItem.detailText
title:readingListItem.title
message:readingListItem.subtitle
rect:CGRectMake(menuLocation.x, menuLocation.y, 0,
0)
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