From 3996fbcb887114e8adc5a5eb897a7b838ce00795 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Tue, 12 Jun 2018 16:23:05 +0200 Subject: [PATCH] Add imid indicator in UIChatCell. Remove name from outgoing message snapshot. Bold name of incomming message snapshot. --- Classes/LinphoneUI/Base.lproj/UIChatCell.xib | 47 +++++++++----- Classes/LinphoneUI/UIChatCell.h | 1 + Classes/LinphoneUI/UIChatCell.m | 65 +++++++++++++++++--- 3 files changed, 89 insertions(+), 24 deletions(-) diff --git a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib index fe2cac6ad..1a9c2b747 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -11,6 +15,7 @@ + @@ -29,7 +34,7 @@ - + - - + - + + + + + + + + + @@ -77,7 +89,8 @@ - - + + + diff --git a/Classes/LinphoneUI/UIChatCell.h b/Classes/LinphoneUI/UIChatCell.h index 083119004..75cc7e7d4 100644 --- a/Classes/LinphoneUI/UIChatCell.h +++ b/Classes/LinphoneUI/UIChatCell.h @@ -35,6 +35,7 @@ @property(weak, nonatomic) IBOutlet UILabel *chatLatestTimeLabel; @property(weak, nonatomic) IBOutlet UIBouncingView *unreadCountView; @property(weak, nonatomic) IBOutlet UILabel *unreadCountLabel; +@property (weak, nonatomic) IBOutlet UIImageView *imdmIcon; - (id)initWithIdentifier:(NSString*)identifier; diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index dea80e4f9..e86307d89 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -85,17 +85,52 @@ LinphoneChatMessage *last_msg = linphone_chat_room_get_last_message_in_history(chatRoom); if (last_msg) { - NSString *text = [[FastAddressBook displayNameForAddress:linphone_chat_message_get_from_address(last_msg)] - stringByAppendingFormat:@" : %@", [UIChatBubbleTextCell TextMessageForChat:last_msg]]; - // shorten long messages - if ([text length] > 50) - text = [[text substringToIndex:50] stringByAppendingString:@"[...]"]; + BOOL outgoing = linphone_chat_message_is_outgoing(last_msg); + NSString *text = [UIChatBubbleTextCell TextMessageForChat:last_msg]; + if (outgoing) { + // shorten long messages + if ([text length] > 50) + text = [[text substringToIndex:50] stringByAppendingString:@"[...]"]; + _chatContentLabel.attributedText = nil; + _chatContentLabel.text = text; + } + else { + NSString *name = [FastAddressBook displayNameForAddress:linphone_chat_message_get_from_address(last_msg)]; + if ([name length] > 25) { + name = [[name substringToIndex:25] stringByAppendingString:@"[...]"]; + } + CGFloat fontSize = _chatContentLabel.font.pointSize; + UIFont *boldFont = [UIFont boldSystemFontOfSize:fontSize]; + NSMutableAttributedString *boldText = [[NSMutableAttributedString alloc] initWithString:name attributes:@{ NSFontAttributeName : boldFont }]; + text = [@" : " stringByAppendingString:text]; + NSString *fullText = [name stringByAppendingString:text]; + if ([fullText length] > 50) { + text = [[text substringToIndex: (50 - [name length])] stringByAppendingString:@"[...]"]; + } + [boldText appendAttributedString:[[NSAttributedString alloc] initWithString:text]]; + _chatContentLabel.text = nil; + _chatContentLabel.attributedText = boldText; + } - _chatContentLabel.text = text; + + LinphoneChatMessageState state = linphone_chat_message_get_state(last_msg); + if (outgoing && (state == LinphoneChatMessageStateDeliveredToUser || state == LinphoneChatMessageStateDisplayed || state == LinphoneChatMessageStateNotDelivered || state == LinphoneChatMessageStateFileTransferError)) { + [self displayImdmStatus:state]; + CGRect newFrame = _chatContentLabel.frame; + newFrame.origin.x = 80; + _chatContentLabel.frame = newFrame; + } else { + // We displace the message 20 pixels to the left + [_imdmIcon setHidden:TRUE]; + CGRect newFrame = _chatContentLabel.frame; + newFrame.origin.x = 60; + _chatContentLabel.frame = newFrame; + } + linphone_chat_message_unref(last_msg); } else _chatContentLabel.text = nil; - + [self updateUnreadBadge]; } @@ -142,4 +177,20 @@ } } + +- (void)displayImdmStatus:(LinphoneChatMessageState)state { + if (state == LinphoneChatMessageStateDeliveredToUser) { + [_imdmIcon setImage:[UIImage imageNamed:@"chat_delivered"]]; + [_imdmIcon setHidden:FALSE]; + } else if (state == LinphoneChatMessageStateDisplayed) { + [_imdmIcon setImage:[UIImage imageNamed:@"chat_read"]]; + [_imdmIcon setHidden:FALSE]; + } else if (state == LinphoneChatMessageStateNotDelivered || state == LinphoneChatMessageStateFileTransferError) { + [_imdmIcon setImage:[UIImage imageNamed:@"chat_error"]]; + [_imdmIcon setHidden:FALSE]; + } else { + [_imdmIcon setHidden:TRUE]; + } +} + @end