Introduce message cell footer view.

pull/1/head
Matthew Chen 7 years ago
parent 6626e2ecc3
commit 7d5ad0e165

@ -6,7 +6,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageFooterView : UIView @interface OWSMessageFooterView : UIStackView
- (void)configureWithConversationViewItem:(ConversationViewItem *)viewItem; - (void)configureWithConversationViewItem:(ConversationViewItem *)viewItem;

@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageFooterView () @interface OWSMessageFooterView ()
@property (nonatomic) UILabel *timestampLabel; @property (nonatomic) UILabel *timestampLabel;
@property (nonatomic) UIView *spacerView;
@property (nonatomic) UILabel *statusLabel; @property (nonatomic) UILabel *statusLabel;
@property (nonatomic) UIView *statusIndicatorView; @property (nonatomic) UIView *statusIndicatorView;
@ -35,10 +36,16 @@ NS_ASSUME_NONNULL_BEGIN
self.layoutMargins = UIEdgeInsetsZero; self.layoutMargins = UIEdgeInsetsZero;
self.axis = UILayoutConstraintAxisHorizontal;
self.spacing = self.hSpacing;
self.alignment = UIStackViewAlignmentCenter;
self.timestampLabel = [UILabel new]; self.timestampLabel = [UILabel new];
// TODO: Color // TODO: Color
self.timestampLabel.textColor = [UIColor lightGrayColor]; self.timestampLabel.textColor = [UIColor lightGrayColor];
[self addSubview:self.timestampLabel];
self.spacerView = [UIView new];
[self.spacerView setContentHuggingLow];
self.statusLabel = [UILabel new]; self.statusLabel = [UILabel new];
// TODO: Color // TODO: Color
@ -49,30 +56,30 @@ NS_ASSUME_NONNULL_BEGIN
[self.statusIndicatorView autoSetDimension:ALDimensionHeight toSize:self.statusIndicatorSize]; [self.statusIndicatorView autoSetDimension:ALDimensionHeight toSize:self.statusIndicatorSize];
self.statusIndicatorView.layer.cornerRadius = self.statusIndicatorSize * 0.5f; self.statusIndicatorView.layer.cornerRadius = self.statusIndicatorSize * 0.5f;
// TODO: Review constant with Myles.0 // // TODO: Review constant with Myles.0
UIStackView *statusStackView = [[UIStackView alloc] initWithArrangedSubviews:@[ // UIStackView *statusStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.statusLabel, // self.statusLabel,
self.statusIndicatorView, // self.statusIndicatorView,
]]; // ]];
statusStackView.axis = UILayoutConstraintAxisHorizontal; // statusStackView.axis = UILayoutConstraintAxisHorizontal;
statusStackView.spacing = self.hSpacing; // statusStackView.spacing = self.hSpacing;
[self addSubview:statusStackView]; // [self addSubview:statusStackView];
[self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading]; // [self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading];
[statusStackView autoPinEdgeToSuperviewEdge:ALEdgeTrailing]; // [statusStackView autoPinEdgeToSuperviewEdge:ALEdgeTrailing];
[self.timestampLabel autoVCenterInSuperview]; // [self.timestampLabel autoVCenterInSuperview];
[statusStackView autoVCenterInSuperview]; // [statusStackView autoVCenterInSuperview];
[self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0 relation:NSLayoutRelationGreaterThanOrEqual]; // [self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0
[self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom // relation:NSLayoutRelationGreaterThanOrEqual]; [self.timestampLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom
withInset:0 // withInset:0
relation:NSLayoutRelationGreaterThanOrEqual]; // relation:NSLayoutRelationGreaterThanOrEqual];
[statusStackView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0 relation:NSLayoutRelationGreaterThanOrEqual]; // [statusStackView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:0
[statusStackView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:0 relation:NSLayoutRelationGreaterThanOrEqual]; // relation:NSLayoutRelationGreaterThanOrEqual]; [statusStackView autoPinEdgeToSuperviewEdge:ALEdgeBottom
[statusStackView autoPinEdge:ALEdgeLeading // withInset:0 relation:NSLayoutRelationGreaterThanOrEqual]; [statusStackView autoPinEdge:ALEdgeLeading
toEdge:ALEdgeTrailing // toEdge:ALEdgeTrailing
ofView:self.timestampLabel // ofView:self.timestampLabel
withOffset:self.hSpacing // withOffset:self.hSpacing
relation:NSLayoutRelationGreaterThanOrEqual]; // relation:NSLayoutRelationGreaterThanOrEqual];
} }
- (void)configureFonts - (void)configureFonts
@ -84,13 +91,13 @@ NS_ASSUME_NONNULL_BEGIN
- (CGFloat)statusIndicatorSize - (CGFloat)statusIndicatorSize
{ {
// TODO: Review constant. // TODO: Review constant.
return 16.f; return 12.f;
} }
- (CGFloat)hSpacing - (CGFloat)hSpacing
{ {
// TODO: Review constant. // TODO: Review constant.
return 10.f; return 8.f;
} }
#pragma mark - Load #pragma mark - Load
@ -102,7 +109,23 @@ NS_ASSUME_NONNULL_BEGIN
[self configureLabelsWithConversationViewItem:viewItem]; [self configureLabelsWithConversationViewItem:viewItem];
// TODO: // TODO:
self.statusIndicatorView.backgroundColor = [UIColor redColor]; self.statusIndicatorView.backgroundColor = [UIColor orangeColor];
for (UIView *subview in @[
self.timestampLabel,
self.statusLabel,
self.statusIndicatorView,
]) {
[subview removeFromSuperview];
}
if (viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
[self addArrangedSubview:self.timestampLabel];
[self addArrangedSubview:self.spacerView];
[self addArrangedSubview:self.statusLabel];
[self addArrangedSubview:self.statusIndicatorView];
} else {
[self addArrangedSubview:self.timestampLabel];
}
} }
- (void)configureLabelsWithConversationViewItem:(ConversationViewItem *)viewItem - (void)configureLabelsWithConversationViewItem:(ConversationViewItem *)viewItem
@ -111,9 +134,7 @@ NS_ASSUME_NONNULL_BEGIN
[self configureFonts]; [self configureFonts];
// TODO: Correct text. self.timestampLabel.text = [DateUtil formatTimestampShort:viewItem.interaction.timestamp];
self.timestampLabel.text =
[DateUtil formatPastTimestampRelativeToNow:viewItem.interaction.timestamp isRTL:CurrentAppContext().isRTL];
self.statusLabel.text = [self messageStatusTextForConversationViewItem:viewItem]; self.statusLabel.text = [self messageStatusTextForConversationViewItem:viewItem];
} }
@ -126,8 +147,12 @@ NS_ASSUME_NONNULL_BEGIN
CGSize result = CGSizeZero; CGSize result = CGSizeZero;
result.height result.height
= MAX(self.timestampLabel.font.lineHeight, MAX(self.statusLabel.font.lineHeight, self.statusIndicatorSize)); = MAX(self.timestampLabel.font.lineHeight, MAX(self.statusLabel.font.lineHeight, self.statusIndicatorSize));
if (viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
result.width = ([self.timestampLabel sizeThatFits:CGSizeZero].width + result.width = ([self.timestampLabel sizeThatFits:CGSizeZero].width +
[self.statusLabel sizeThatFits:CGSizeZero].width + self.statusIndicatorSize + self.hSpacing * 2.f); [self.statusLabel sizeThatFits:CGSizeZero].width + self.statusIndicatorSize + self.hSpacing * 3.f);
} else {
result.width = [self.timestampLabel sizeThatFits:CGSizeZero].width;
}
return CGSizeCeil(result); return CGSizeCeil(result);
} }

@ -342,18 +342,7 @@ NS_ASSUME_NONNULL_BEGIN
return @""; return @"";
} }
NSString *dateTimeString; return [DateUtil formatDateShort:date];
if (![DateUtil dateIsThisYear:date]) {
dateTimeString = [[DateUtil dateFormatter] stringFromDate:date];
} else if ([DateUtil dateIsOlderThanOneWeek:date]) {
dateTimeString = [[DateUtil monthAndDayFormatter] stringFromDate:date];
} else if ([DateUtil dateIsOlderThanToday:date]) {
dateTimeString = [[DateUtil shortDayOfWeekFormatter] stringFromDate:date];
} else {
dateTimeString = [[DateUtil timeFormatter] stringFromDate:date];
}
return dateTimeString.uppercaseString;
} }
#pragma mark - Constants #pragma mark - Constants

@ -20,6 +20,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp + (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp
isRTL:(BOOL)isRTL NS_SWIFT_NAME(formatPastTimestampRelativeToNow(_:isRTL:)); isRTL:(BOOL)isRTL NS_SWIFT_NAME(formatPastTimestampRelativeToNow(_:isRTL:));
+ (NSString *)formatTimestampShort:(uint64_t)timestamp;
+ (NSString *)formatDateShort:(NSDate *)date;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -165,6 +165,29 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE";
isRTL:isRTL]; isRTL:isRTL];
} }
+ (NSString *)formatTimestampShort:(uint64_t)timestamp
{
return [self formatDateShort:[NSDate ows_dateWithMillisecondsSince1970:timestamp]];
}
+ (NSString *)formatDateShort:(NSDate *)date
{
OWSAssert(date);
NSString *dateTimeString;
if (![DateUtil dateIsThisYear:date]) {
dateTimeString = [[DateUtil dateFormatter] stringFromDate:date];
} else if ([DateUtil dateIsOlderThanOneWeek:date]) {
dateTimeString = [[DateUtil monthAndDayFormatter] stringFromDate:date];
} else if ([DateUtil dateIsOlderThanToday:date]) {
dateTimeString = [[DateUtil shortDayOfWeekFormatter] stringFromDate:date];
} else {
dateTimeString = [[DateUtil timeFormatter] stringFromDate:date];
}
return dateTimeString.uppercaseString;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save