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.
......
...@@ -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