Commit db28cd76 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds subtitle timestamp to Recent Tabs session headers.

- Adds a subtitle label to table_view_text_header_footer_item
- Sets this label as a timpestamp for RecentTabs sessions headers.

Screenshot:
https://drive.google.com/open?id=1yamLSxBoFXm0la14ZLVxsEqMMcbFu6BC

Bug: 805698
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I2318b02df397d603285034a642fd75c7efb20953
Reviewed-on: https://chromium-review.googlesource.com/963674
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543472}
parent b8d49977
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/web/public/web_state/context_menu_params.h" #import "ios/web/public/web_state/context_menu_params.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -76,6 +77,9 @@ NSString* const kRecentlyClosedCollapsedKey = @"RecentlyClosedCollapsed"; ...@@ -76,6 +77,9 @@ NSString* const kRecentlyClosedCollapsedKey = @"RecentlyClosedCollapsed";
int const kNumberOfSectionsBeforeSessions = 2; int const kNumberOfSectionsBeforeSessions = 2;
// Estimated Table Row height. // Estimated Table Row height.
const CGFloat kEstimatedRowHeight = 56; const CGFloat kEstimatedRowHeight = 56;
// The UI displays relative time for up to this number of hours and then
// switches to absolute values.
const int kRelativeTimeMaxHours = 4;
} // namespace } // namespace
...@@ -271,6 +275,9 @@ const CGFloat kEstimatedRowHeight = 56; ...@@ -271,6 +275,9 @@ const CGFloat kEstimatedRowHeight = 56;
[[TableViewTextHeaderFooterItem alloc] [[TableViewTextHeaderFooterItem alloc]
initWithType:ItemTypeSessionHeader]; initWithType:ItemTypeSessionHeader];
header.text = base::SysUTF8ToNSString(session->name); header.text = base::SysUTF8ToNSString(session->name);
header.subtitleText = l10n_util::GetNSStringF(
IDS_IOS_OPEN_TABS_LAST_USED,
base::SysNSStringToUTF16([self lastSyncStringForSesssion:session]));
[model setHeader:header forSectionWithIdentifier:sessionIdentifier]; [model setHeader:header forSectionWithIdentifier:sessionIdentifier];
[self addItemsForSession:session]; [self addItemsForSession:session];
} }
...@@ -609,6 +616,43 @@ const CGFloat kEstimatedRowHeight = 56; ...@@ -609,6 +616,43 @@ const CGFloat kEstimatedRowHeight = 56;
return session->tabs[indexOfDistantTab].get(); return session->tabs[indexOfDistantTab].get();
} }
- (NSString*)lastSyncStringForSesssion:
(synced_sessions::DistantSession const*)session {
base::Time time = session->modified_time;
NSDate* lastUsedDate = [NSDate dateWithTimeIntervalSince1970:time.ToTimeT()];
NSString* dateString =
[NSDateFormatter localizedStringFromDate:lastUsedDate
dateStyle:NSDateFormatterShortStyle
timeStyle:NSDateFormatterNoStyle];
NSString* timeString;
base::TimeDelta last_used_delta;
if (base::Time::Now() > time)
last_used_delta = base::Time::Now() - time;
if (last_used_delta.InMicroseconds() < base::Time::kMicrosecondsPerMinute) {
timeString = l10n_util::GetNSString(IDS_IOS_OPEN_TABS_RECENTLY_SYNCED);
// This will return something similar to "Seconds ago mm/dd/yy"
return [NSString stringWithFormat:@"%@ %@", timeString, dateString];
}
if (last_used_delta.InHours() < kRelativeTimeMaxHours) {
timeString = base::SysUTF16ToNSString(
ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
ui::TimeFormat::LENGTH_SHORT, last_used_delta));
// This will return something similar to "1 min/hour ago mm/dd/yy"
return [NSString stringWithFormat:@"%@ %@", timeString, dateString];
}
NSDate* date = [NSDate dateWithTimeIntervalSince1970:time.ToTimeT()];
timeString =
[NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterShortStyle];
// This will return something similar to "H:MM mm/dd/yy"
return [NSString stringWithFormat:@"%@ %@", timeString, dateString];
}
#pragma mark - Navigation helpers #pragma mark - Navigation helpers
- (void)dismissRecentTabsModal { - (void)dismissRecentTabsModal {
......
...@@ -12,14 +12,13 @@ ...@@ -12,14 +12,13 @@
// TableViewTextHeaderFooterItem contains the model data for a // TableViewTextHeaderFooterItem contains the model data for a
// UITableViewHeaderFooterView. // UITableViewHeaderFooterView.
@interface TableViewTextHeaderFooterItem : TableViewHeaderFooterItem @interface TableViewTextHeaderFooterItem : TableViewHeaderFooterItem
@property(nonatomic, readwrite, strong) NSString* text; @property(nonatomic, readwrite, strong) NSString* text;
@property(nonatomic, readwrite, strong) NSString* subtitleText;
@end @end
// UITableViewHeaderFooterView that displays a text label. // UITableViewHeaderFooterView that displays a text label.
@interface TableViewTextHeaderFooterView : UITableViewHeaderFooterView @interface TableViewTextHeaderFooterView : UITableViewHeaderFooterView
@property(nonatomic, readwrite, strong) UILabel* subtitleLabel;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_HEADER_FOOTER_ITEM_H_ #endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_HEADER_FOOTER_ITEM_H_
...@@ -14,9 +14,13 @@ ...@@ -14,9 +14,13 @@
namespace { namespace {
// The inner insets of the View content. // The inner insets of the View content.
const CGFloat kMargin = 16; const CGFloat kMargin = 16;
// The vertical spacing between text labels.
const CGFloat kVerticalSpacing = 2.0;
} }
@implementation TableViewTextHeaderFooterItem @implementation TableViewTextHeaderFooterItem
@synthesize subtitleText = _subtitleText;
@synthesize text = _text; @synthesize text = _text;
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
...@@ -37,8 +41,7 @@ const CGFloat kMargin = 16; ...@@ -37,8 +41,7 @@ const CGFloat kMargin = 16;
TableViewTextHeaderFooterView* header = TableViewTextHeaderFooterView* header =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerFooter); base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerFooter);
header.textLabel.text = self.text; header.textLabel.text = self.text;
header.textLabel.font = header.subtitleLabel.text = self.subtitleText;
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
} }
@end @end
...@@ -46,21 +49,33 @@ const CGFloat kMargin = 16; ...@@ -46,21 +49,33 @@ const CGFloat kMargin = 16;
#pragma mark - TableViewTextHeaderFooter #pragma mark - TableViewTextHeaderFooter
@implementation TableViewTextHeaderFooterView @implementation TableViewTextHeaderFooterView
@synthesize subtitleLabel = _subtitleLabel;
@synthesize textLabel = _textLabel; @synthesize textLabel = _textLabel;
- (instancetype)initWithReuseIdentifier:(NSString*)reuseIdentifier { - (instancetype)initWithReuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithReuseIdentifier:reuseIdentifier]; self = [super initWithReuseIdentifier:reuseIdentifier];
if (self) { if (self) {
// Text Label, set font sizes using dynamic type. // Labels, set font sizes using dynamic type.
_textLabel = [[UILabel alloc] init]; _textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO; _textLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
_subtitleLabel = [[UILabel alloc] init];
_subtitleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
// Vertical StackView.
UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ _textLabel, _subtitleLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.spacing = kVerticalSpacing;
verticalStack.translatesAutoresizingMaskIntoConstraints = NO;
// Container View. // Container View.
UIView* containerView = [[UIView alloc] init]; UIView* containerView = [[UIView alloc] init];
containerView.translatesAutoresizingMaskIntoConstraints = NO; containerView.translatesAutoresizingMaskIntoConstraints = NO;
// Add subviews to View Hierarchy. // Add subviews to View Hierarchy.
[containerView addSubview:_textLabel]; [containerView addSubview:verticalStack];
[self.contentView addSubview:containerView]; [self.contentView addSubview:containerView];
// Set and activate constraints. // Set and activate constraints.
...@@ -80,12 +95,14 @@ const CGFloat kMargin = 16; ...@@ -80,12 +95,14 @@ const CGFloat kMargin = 16;
constant:-kMargin], constant:-kMargin],
[containerView.centerYAnchor [containerView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor], constraintEqualToAnchor:self.contentView.centerYAnchor],
// Title Label Constraints. // Vertical StackView Constraints.
[_textLabel.leadingAnchor [verticalStack.leadingAnchor
constraintEqualToAnchor:containerView.leadingAnchor], constraintEqualToAnchor:containerView.leadingAnchor],
[_textLabel.topAnchor constraintEqualToAnchor:containerView.topAnchor], [verticalStack.topAnchor constraintEqualToAnchor:containerView.topAnchor],
[_textLabel.bottomAnchor [verticalStack.bottomAnchor
constraintEqualToAnchor:containerView.bottomAnchor], constraintEqualToAnchor:containerView.bottomAnchor],
[verticalStack.trailingAnchor
constraintEqualToAnchor:containerView.trailingAnchor],
]]; ]];
} }
return self; return self;
......
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