From a4703cec76b8322c07a5a54015c8a8f4e9c66b5d Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 26 Jun 2018 13:53:35 -0400 Subject: [PATCH] Breaks: unread indicators and date headers. --- .../ConversationView/Cells/OWSMessageCell.m | 5 +- .../Cells/OWSUnreadIndicatorCell.m | 55 ++++++++++++++++++- .../translations/en.lproj/Localizable.strings | 4 +- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m index 0875e5ecf..82d2e0983 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageCell.m @@ -73,8 +73,7 @@ NS_ASSUME_NONNULL_BEGIN [self.dateStrokeView autoSetDimension:ALDimensionHeight toSize:1.f]; [self.dateHeaderLabel autoPinWidthToSuperview]; [self.dateHeaderLabel autoVCenterInSuperview]; - // TODO: offset. - [self.dateStrokeView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.dateHeaderLabel withOffset:0.f]; + [self.dateStrokeView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.dateHeaderLabel]; self.avatarView = [[AvatarImageView alloc] init]; [self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize]; @@ -232,7 +231,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *timeString = [dateHeaderTimeFormatter stringFromDate:date]; NSAttributedString *attributedText = [NSAttributedString new]; - attributedText = [attributedText rtlSafeAppend:dateString + attributedText = [attributedText rtlSafeAppend:dateString.uppercaseString attributes:@{ NSFontAttributeName : self.dateHeaderDateFont, NSForegroundColorAttributeName : [UIColor lightGrayColor], diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m index eed8a6ee5..a10569713 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSUnreadIndicatorCell.m @@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable) TSUnreadIndicatorInteraction *interaction; @property (nonatomic) UILabel *titleLabel; +@property (nonatomic) UILabel *subtitleLabel; @property (nonatomic) UIView *strokeView; @property (nonatomic) NSArray *layoutConstraints; @@ -54,6 +55,15 @@ NS_ASSUME_NONNULL_BEGIN self.titleLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.titleLabel]; + self.subtitleLabel = [UILabel new]; + // TODO: color. + self.subtitleLabel.textColor = [UIColor lightGrayColor]; + // The subtitle may wrap to a second line. + self.subtitleLabel.numberOfLines = 0; + self.subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping; + self.subtitleLabel.textAlignment = NSTextAlignmentCenter; + [self.contentView addSubview:self.subtitleLabel]; + [self configureFonts]; } @@ -62,7 +72,8 @@ NS_ASSUME_NONNULL_BEGIN // Update cell to reflect changes in dynamic text. // // TODO: Font size. - self.titleLabel.font = UIFont.ows_dynamicTypeCaption1Font.ows_bold; + self.titleLabel.font = UIFont.ows_dynamicTypeCaption1Font.ows_mediumWeight; + self.subtitleLabel.font = UIFont.ows_dynamicTypeCaption1Font; } + (NSString *)cellReuseIdentifier @@ -81,6 +92,7 @@ NS_ASSUME_NONNULL_BEGIN TSUnreadIndicatorInteraction *interaction = (TSUnreadIndicatorInteraction *)self.viewItem.interaction; self.titleLabel.text = [self titleForInteraction:interaction]; + self.subtitleLabel.text = [self subtitleForInteraction:interaction]; self.backgroundColor = [UIColor whiteColor]; @@ -90,11 +102,17 @@ NS_ASSUME_NONNULL_BEGIN [self.titleLabel autoPinLeadingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterLeading], [self.titleLabel autoPinTrailingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterTrailing], - // TODO: offset. - [self.strokeView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.titleLabel withOffset:0.f], + [self.strokeView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.titleLabel], [self.strokeView autoPinLeadingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterLeading], [self.strokeView autoPinTrailingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterTrailing], [self.strokeView autoSetDimension:ALDimensionHeight toSize:1.f], + + [self.subtitleLabel autoPinEdge:ALEdgeTop + toEdge:ALEdgeBottom + ofView:self.titleLabel + withOffset:self.subtitleVSpacing], + [self.subtitleLabel autoPinLeadingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterLeading], + [self.subtitleLabel autoPinTrailingToSuperviewMarginWithInset:self.conversationStyle.fullWidthGutterTrailing], ]; } @@ -104,6 +122,28 @@ NS_ASSUME_NONNULL_BEGIN .uppercaseString; } +- (NSString *)subtitleForInteraction:(TSUnreadIndicatorInteraction *)interaction +{ + if (!interaction.hasMoreUnseenMessages) { + return nil; + } + return (interaction.missingUnseenSafetyNumberChangeCount > 0 + ? NSLocalizedString(@"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES", + @"Messages that indicates that there are more unseen messages.") + : NSLocalizedString(@"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES", + @"Messages that indicates that there are more unseen messages including safety number changes.")); +} + +- (CGFloat)subtitleHMargin +{ + return 20.f; +} + +- (CGFloat)subtitleVSpacing +{ + return 3.f; +} + - (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssert(self.conversationStyle); @@ -117,6 +157,15 @@ NS_ASSUME_NONNULL_BEGIN CGSize result = CGSizeMake(self.conversationStyle.fullWidthContentWidth, self.titleLabel.font.lineHeight + vOffset * 2); + TSUnreadIndicatorInteraction *interaction = (TSUnreadIndicatorInteraction *)self.viewItem.interaction; + self.subtitleLabel.text = [self subtitleForInteraction:interaction]; + if (self.subtitleLabel.text.length > 0) { + result.height += self.subtitleVSpacing; + result.height += ceil( + [self.subtitleLabel sizeThatFits:CGSizeMake(self.conversationStyle.fullWidthContentWidth, CGFLOAT_MAX)] + .height); + } + return CGSizeCeil(result); } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 1fe891a60..c7c73a7c5 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1260,10 +1260,10 @@ "MESSAGES_VIEW_UNREAD_INDICATOR" = "New Messages"; /* Messages that indicates that there are more unseen messages including safety number changes that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}}. */ -"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES_FORMAT" = "There are more unread messages (including safety number changes) above. Tap \"%@\" to see them."; +"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_AND_SAFETY_NUMBER_CHANGES" = "There are more unread messages (including safety number changes)."; /* Messages that indicates that there are more unseen messages that be revealed by tapping the 'load earlier messages' button. Embeds {{the name of the 'load earlier messages' button}} */ -"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES_FORMAT" = "There are more unread messages above. Tap \"%@\" to see them."; +"MESSAGES_VIEW_UNREAD_INDICATOR_HAS_MORE_UNSEEN_MESSAGES" = "There are more unread messages."; /* notification title */ "MISSED_CALL" = "Missed call";