2018-08-08 16:10:09 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
2016-08-29 16:28:40 +02:00
|
|
|
|
|
|
|
#import "OWSDeviceTableViewCell.h"
|
|
|
|
#import "DateUtil.h"
|
2018-08-08 16:10:09 +02:00
|
|
|
#import <SignalMessaging/OWSTableViewController.h>
|
|
|
|
#import <SignalMessaging/Theme.h>
|
2016-08-29 16:28:40 +02:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@implementation OWSDeviceTableViewCell
|
|
|
|
|
|
|
|
- (void)configureWithDevice:(OWSDevice *)device
|
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(device);
|
2018-08-08 16:10:09 +02:00
|
|
|
|
|
|
|
[OWSTableItem configureCell:self];
|
|
|
|
|
|
|
|
self.nameLabel.textColor = Theme.primaryColor;
|
|
|
|
self.linkedLabel.textColor = Theme.secondaryColor;
|
|
|
|
self.lastSeenLabel.textColor = Theme.secondaryColor;
|
|
|
|
|
2016-09-02 21:50:36 +02:00
|
|
|
self.nameLabel.text = device.displayName;
|
2016-08-29 16:28:40 +02:00
|
|
|
|
2016-09-09 17:55:07 +02:00
|
|
|
NSString *linkedFormatString
|
|
|
|
= NSLocalizedString(@"DEVICE_LINKED_AT_LABEL", @"{{Short Date}} when device was linked.");
|
2016-08-29 16:28:40 +02:00
|
|
|
self.linkedLabel.text =
|
|
|
|
[NSString stringWithFormat:linkedFormatString, [DateUtil.dateFormatter stringFromDate:device.createdAt]];
|
|
|
|
|
2016-09-09 17:55:07 +02:00
|
|
|
NSString *lastSeenFormatString = NSLocalizedString(
|
|
|
|
@"DEVICE_LAST_ACTIVE_AT_LABEL", @"{{Short Date}} when device last communicated with Signal Server.");
|
2016-09-21 18:35:56 +02:00
|
|
|
|
|
|
|
NSDate *displayedLastSeenAt;
|
|
|
|
// lastSeenAt is stored at day granularity. At midnight UTC.
|
|
|
|
// Making it likely that when you first link a device it will
|
|
|
|
// be "last seen" the day before it was created, which looks broken.
|
|
|
|
if ([device.lastSeenAt compare:device.createdAt] == NSOrderedDescending) {
|
|
|
|
displayedLastSeenAt = device.lastSeenAt;
|
|
|
|
} else {
|
|
|
|
displayedLastSeenAt = device.createdAt;
|
|
|
|
}
|
|
|
|
|
2016-08-29 16:28:40 +02:00
|
|
|
self.lastSeenLabel.text =
|
2016-09-21 18:35:56 +02:00
|
|
|
[NSString stringWithFormat:lastSeenFormatString, [DateUtil.dateFormatter stringFromDate:displayedLastSeenAt]];
|
2016-08-29 16:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|