| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- //
- // TUIMessageCell.m
- // UIKit
- //
- // Created by kennethmiao on 2018/9/17.
- // Copyright © 2018 Tencent. All rights reserved.
- //
- #import "TUIMessageCell.h"
- #import <TIMCommon/TIMDefine.h>
- #import <TUICore/TUIThemeManager.h>
- #import <TUICore/TUITool.h>
- #import "NSString+TUIEmoji.h"
- #import "TUISystemMessageCellData.h"
- #import <TUICore/TUICore.h>
- #import <TIMCommon/MOHeadNormalView.h>
- @interface TUIMessageCell () <CAAnimationDelegate>
- @property(nonatomic, strong) TUIMessageCellData *messageData;
- @property (nonatomic, strong) MOHeadNormalView *headBgView;//头像框
- @end
- @implementation TUIMessageCell
- #pragma mark - Life cycle
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self setupSubViews];
- [self setupRAC];
- }
- return self;
- }
- - (void)setupSubViews {
- // head
- _avatarView = [[UIImageView alloc] init];
- _avatarView.contentMode = UIViewContentModeScaleAspectFit;
- [self.contentView addSubview:_avatarView];
- UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSelectMessageAvatar:)];
- [_avatarView addGestureRecognizer:tap1];
- UILongPressGestureRecognizer *tap2 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongSelectMessageAvatar:)];
- [_avatarView addGestureRecognizer:tap2];
- [_avatarView setUserInteractionEnabled:YES];
-
- [self.contentView addSubview:self.headBgView];
- // nameLabel
- _nameLabel = [[UILabel alloc] init];
- _nameLabel.font = [self fontWithSize:13];
- _nameLabel.textColor = [UIColor d_systemGrayColor];
- [self.contentView addSubview:_nameLabel];
- // container
- _container = [[UIView alloc] init];
- _container.backgroundColor = [UIColor clearColor];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSelectMessage:)];
- tap.cancelsTouchesInView = NO;
- [_container addGestureRecognizer:tap];
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPress:)];
- [_container addGestureRecognizer:longPress];
- [self.contentView addSubview:_container];
- // indicator
- _indicator = [[UIActivityIndicatorView alloc] init];
- _indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
- [_indicator sizeToFit];
- [self.contentView addSubview:_indicator];
- // error
- _retryView = [[UIImageView alloc] init];
- _retryView.userInteractionEnabled = YES;
- UITapGestureRecognizer *resendTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onRetryMessage:)];
- [_retryView addGestureRecognizer:resendTap];
- [self.contentView addSubview:_retryView];
- // messageModifyRepliesLabel
- _messageModifyRepliesButton = [[TUIFitButton alloc] initWithFrame:CGRectMake(0, 0, 12, 12)];
- _messageModifyRepliesButton.imageSize = CGSizeMake(12, 12);
- [_messageModifyRepliesButton addTarget:self action:@selector(onJumpToRepliesDetailPage:) forControlEvents:UIControlEventTouchUpInside];
- [_messageModifyRepliesButton.titleLabel setFont:[self fontWithSize:12]];
- [_messageModifyRepliesButton setTitleColor:TIMCommonDynamicColor(@"chat_message_read_name_date_text_color", @"#999999") forState:UIControlStateNormal];
- [_messageModifyRepliesButton setImage:TIMCommonBundleThemeImage(@"chat_messageReplyIcon_img", @"messageReplyIcon") forState:UIControlStateNormal];
- [self.contentView addSubview:_messageModifyRepliesButton];
- _readReceiptLabel = [[UILabel alloc] init];
- _readReceiptLabel.hidden = YES;
- _readReceiptLabel.font = [self fontWithSize:12];
- _readReceiptLabel.textColor = TIMCommonDynamicColor(@"chat_message_read_status_text_gray_color", @"#BBBBBB");
- _readReceiptLabel.lineBreakMode = NSLineBreakByCharWrapping;
- UITapGestureRecognizer *showReadReceiptTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSelectReadReceipt:)];
- [_readReceiptLabel addGestureRecognizer:showReadReceiptTap];
- _readReceiptLabel.userInteractionEnabled = YES;
- [self.contentView addSubview:_readReceiptLabel];
- // selectedIcon
- _selectedIcon = [[UIImageView alloc] init];
- [self.contentView addSubview:_selectedIcon];
- // selectedView
- _selectedView = [UIButton buttonWithType:UIButtonTypeCustom];
- _selectedView.backgroundColor = [UIColor clearColor];
- [_selectedView addTarget:self action:@selector(onSelectMessage:) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView addSubview:_selectedView];
- // timeLabel
- _timeLabel = [[UILabel alloc] init];
- _timeLabel.textColor = [UIColor darkGrayColor];
- _timeLabel.font = [self fontWithSize:11.0];
- [self.contentView addSubview:_timeLabel];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = UIColor.clearColor;
- self.contentView.backgroundColor = UIColor.clearColor;
-
- [self makeConstraints];
- }
- - (void)makeConstraints {
-
- [self.headBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.avatarView);
- make.centerY.equalTo(self.avatarView);
- make.width.height.equalTo(@40.0);
- }];
- self.headBgView.headImgWidth = 40.0;
-
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.mas_equalTo(_container.mas_leading).mas_offset(7);
- make.top.mas_equalTo(self.avatarView.mas_top);
- make.width.mas_equalTo(1);
- make.height.mas_equalTo(20);
- }];
-
- [self.selectedIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.leading.mas_equalTo(self.contentView.mas_leading).mas_offset(3);
- make.top.mas_equalTo(self.avatarView.mas_centerY).mas_offset(-10);
- make.width.mas_equalTo(20);
- make.height.mas_equalTo(20);
- }];
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.trailing.mas_equalTo(self.contentView.mas_trailing).mas_offset(-10);
- make.top.mas_equalTo(self.avatarView);
- make.width.mas_greaterThanOrEqualTo(10);
- make.height.mas_equalTo(10);
- }];
-
- [self.selectedView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(self.contentView);
- }];
- }
- + (BOOL)requiresConstraintBasedLayout {
- return YES;
- }
- // this is Apple's recommended place for adding/updating constraints
- - (void)updateConstraints {
- TUIMessageCellLayout *cellLayout = self.messageData.cellLayout;
- BOOL isInComing = (self.messageData.direction == MsgDirectionIncoming);
- [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- if (isInComing) {
- make.leading.mas_equalTo(_container.mas_leading).mas_offset(7);
- make.trailing.mas_equalTo(self.contentView).mas_offset(-7);
- } else {
- make.leading.mas_equalTo(self.contentView).mas_offset(7);
- make.trailing.mas_equalTo(self.container.mas_trailing);
- }
- if (self.messageData.showName) {
- make.width.mas_greaterThanOrEqualTo(20);
- make.height.mas_greaterThanOrEqualTo(20);
- } else {
- make.height.mas_equalTo(0);
- }
- make.top.mas_equalTo(self.avatarView.mas_top);
- }];
- [self.selectedIcon mas_updateConstraints:^(MASConstraintMaker *make) {
- if (self.messageData.showCheckBox) {
- make.width.mas_equalTo(20);
- make.height.mas_equalTo(20);
- } else {
- make.size.mas_equalTo(CGSizeZero);
- }
- }];
- [self.timeLabel sizeToFit];
- [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- if (self.messageData.showMessageTime) {
- make.width.mas_equalTo(self.timeLabel.frame.size.width);
- make.height.mas_equalTo(self.timeLabel.frame.size.height);
- } else {
- make.width.mas_equalTo(0);
- make.height.mas_equalTo(0);
- }
- }];
- CGSize csize = [self.class getContentSize:self.messageData];
- CGFloat contentWidth = csize.width;
- CGFloat contentHeight = csize.height;
- if (!CGSizeEqualToSize(self.messageData.messageContainerAppendSize, CGSizeZero)) {
- /**
- * Taking the maximum width between the "emoji reply message" and the text content
- */
- contentWidth = MAX(self.messageData.messageContainerAppendSize.width, csize.width);
- /**
- * Limit the maximum width to Screen_Width *0.25 * 3
- */
- contentWidth = MIN(contentWidth, Screen_Width * 0.25 * 3);
- contentHeight = csize.height + self.messageData.messageContainerAppendSize.height;
- }
- if (self.messageData.direction == MsgDirectionIncoming) {
- self.avatarView.hidden = !self.messageData.showAvatar;
- [self.avatarView mas_remakeConstraints:^(MASConstraintMaker *make) {
- if (self.messageData.showCheckBox) {
- make.leading.mas_equalTo(self.selectedIcon.mas_trailing).mas_offset(cellLayout.avatarInsets.left);
- } else {
- make.leading.mas_equalTo(self.contentView.mas_leading).mas_offset(cellLayout.avatarInsets.left);
- }
- make.top.mas_equalTo(cellLayout.avatarInsets.top);
- make.size.mas_equalTo(cellLayout.avatarSize);
- }];
- [self.container mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.leading.mas_equalTo(self.avatarView.mas_trailing).mas_offset(cellLayout.messageInsets.left);
- make.top.mas_equalTo(self.nameLabel.mas_bottom).mas_offset(cellLayout.messageInsets.top);
- make.width.mas_equalTo(contentWidth);
- make.height.mas_equalTo(contentHeight);
- }];
- CGRect indicatorFrame = self.indicator.frame;
- [self.indicator mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.leading.mas_equalTo(self.container.mas_trailing).mas_offset(8);
- make.centerY.mas_equalTo(self.container.mas_centerY);
- make.size.mas_equalTo(indicatorFrame.size);
- }];
- self.retryView.frame = self.indicator.frame;
- self.readReceiptLabel.hidden = YES;
- } else {
- if (!self.messageData.showAvatar) {
- cellLayout.avatarSize = CGSizeZero;
- }
- [self.avatarView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.trailing.mas_equalTo(self.contentView.mas_trailing).mas_offset(-cellLayout.avatarInsets.right);
- make.top.mas_equalTo(cellLayout.avatarInsets.top);
- make.size.mas_equalTo(cellLayout.avatarSize);
- }];
- [self.container mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.trailing.mas_equalTo(self.avatarView.mas_leading).mas_offset(-cellLayout.messageInsets.right);
- make.top.mas_equalTo(self.nameLabel.mas_bottom).mas_offset(cellLayout.messageInsets.top);
- make.width.mas_equalTo(contentWidth);
- make.height.mas_equalTo(contentHeight);
- }];
- CGRect indicatorFrame = self.indicator.frame;
- [self.indicator mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.trailing.mas_equalTo(self.container.mas_leading).mas_offset(-8);
- make.centerY.mas_equalTo(self.container.mas_centerY);
- make.size.mas_equalTo(indicatorFrame.size);
- }];
- self.retryView.frame = self.indicator.frame;
- [self.readReceiptLabel sizeToFit];
- [self.readReceiptLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.container.mas_bottom);
- make.trailing.mas_equalTo(self.container.mas_leading).mas_offset(-8);
- make.size.mas_equalTo(self.readReceiptLabel.frame.size);
- }];
- }
-
- [self.headBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.avatarView);
- make.centerY.equalTo(self.avatarView);
- make.width.height.equalTo(@40.0);
- }];
- self.headBgView.headImgWidth = 40.0;
- if (!self.messageModifyRepliesButton.isHidden) {
- self.messageModifyRepliesButton.mm_sizeToFit();
- CGFloat repliesBtnTextWidth = self.messageModifyRepliesButton.frame.size.width;
- [self.messageModifyRepliesButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- if (isInComing) {
- make.leading.mas_equalTo(self.container.mas_leading);
- } else {
- make.trailing.mas_equalTo(self.container.mas_trailing);
- }
- make.top.mas_equalTo(self.container.mas_bottom);
- make.size.mas_equalTo(CGSizeMake(repliesBtnTextWidth + 10, 30));
- }];
- }
- // according to apple super should be called at end of method
- [super updateConstraints];
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- }
- - (void)setupRAC {
- @weakify(self);
- [RACObserve(self, readReceiptLabel.text) subscribeNext:^(id _Nullable x) {
- @strongify(self);
- if ([self shouldHighlightReadReceiptLabel]) {
- self.readReceiptLabel.textColor = TIMCommonDynamicColor(@"chat_message_read_status_text_color", @"#147AFF");
- } else {
- self.readReceiptLabel.textColor = TIMCommonDynamicColor(@"chat_message_read_status_text_gray_color", @"#BBBBBB");
- }
- }];
- }
- - (void)prepareForReuse {
- [super prepareForReuse];
- /**
- * In the future, any UI problems caused by reuse can be solved by coding here.
- */
- /**
- * Once the message is reused, it means that a new message is about to appear, and the label content is changed to empty string.
- */
- _readReceiptLabel.text = @"";
- _readReceiptLabel.hidden = YES;
- }
- #pragma mark - Public
- - (void)fillWithData:(TUIMessageCellData *)data {
- [super fillWithData:data];
- self.messageData = data;
- [self loadAvatar:data];
- if (self.messageData.showName) {
- _nameLabel.hidden = NO;
- } else {
- _nameLabel.hidden = YES;
- }
- if (self.messageData.showCheckBox) {
- _selectedIcon.hidden = NO;
- _selectedView.hidden = NO;
- } else {
- _selectedIcon.hidden = YES;
- _selectedView.hidden = YES;
- }
- if ([TUIConfig defaultConfig].avatarType == TAvatarTypeRounded) {
- self.avatarView.layer.masksToBounds = YES;
- self.avatarView.layer.cornerRadius = data.cellLayout.avatarSize.height / 2;
- } else if ([TUIConfig defaultConfig].avatarType == TAvatarTypeRadiusCorner) {
- self.avatarView.layer.masksToBounds = YES;
- self.avatarView.layer.cornerRadius = [TUIConfig defaultConfig].avatarCornerRadius;
- }
- self.nameLabel.text = data.senderName;
-
- if (data.direction == MsgDirectionIncoming) {
- self.nameLabel.textColor = self.class.incommingNameColor;
- self.nameLabel.font = self.class.incommingNameFont;
- } else {
- self.nameLabel.textColor = self.class.outgoingNameColor;
- self.nameLabel.font = self.class.outgoingNameFont;
- }
- self.retryView.image = [UIImage imageNamed:TUIChatImagePath(@"msg_error")];
- if (data.status == Msg_Status_Fail) {
- [_indicator stopAnimating];
- _readReceiptLabel.hidden = YES;
- self.retryView.hidden = NO;
- } else {
- if (data.status == Msg_Status_Sending_2) {
- [_indicator startAnimating];
- _readReceiptLabel.hidden = YES;
- } else if (data.status == Msg_Status_Succ) {
- [_indicator stopAnimating];
- /**
- * The message is sent successfully, indicating that the indicator and error are no longer displayed on the label, and the read receipt label can be
- * displayed.
- */
- if (self.messageData.showReadReceipt && self.messageData.direction == MsgDirectionOutgoing && self.messageData.innerMessage.needReadReceipt &&
- (self.messageData.innerMessage.userID || self.messageData.innerMessage.groupID) &&
- ![self.messageData isKindOfClass:TUISystemMessageCellData.class]) {
- [self updateReadLabelText];
- _readReceiptLabel.hidden = NO;
- }
- } else if (data.status == Msg_Status_Sending) {
- [_indicator startAnimating];
- _readReceiptLabel.hidden = YES;
- }
- self.retryView.hidden = YES;
- }
- self.messageModifyRepliesButton.hidden = !data.showMessageModifyReplies;
- if (data.showMessageModifyReplies) {
- NSString *title = [NSString stringWithFormat:@"%ld%@", data.messageModifyReplies.count, TIMCommonLocalizableString(TUIKitRepliesNum)];
- [self.messageModifyRepliesButton setTitle:title forState:UIControlStateNormal];
- [self.messageModifyRepliesButton sizeToFit];
- [self.messageModifyRepliesButton setNeedsUpdateConstraints];
- [self.messageModifyRepliesButton updateConstraintsIfNeeded];
- [self.messageModifyRepliesButton layoutIfNeeded];
- }
- NSString *imageName = (data.showCheckBox && data.selected) ? TIMCommonImagePath(@"icon_select_selected") : TIMCommonImagePath(@"icon_select_normal");
- self.selectedIcon.image = [UIImage imageNamed:imageName];
- _timeLabel.text = [TUITool convertDateToStr:data.innerMessage.timestamp];
- [_timeLabel sizeToFit];
- _timeLabel.hidden = !data.showMessageTime;
- /**
- * Text highlighting - asynchronous operations are here to keep the order of execution consistent with subclasses
- */
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf highlightWhenMatchKeyword:data.highlightKeyword];
- });
-
- if(![data isKindOfClass:[TUISystemMessageCellData class]]){
- if(data.headdress.length > 0){
- self.headBgView.hidden = NO;
- self.headBgView.isLiving = NO;
- self.headBgView.effectType = data.headgearType;
- self.headBgView.imgUrlStr = data.headdress;
- }
- else{
- self.headBgView.hidden = YES;
- }
- }
- else{
- self.headBgView.hidden = YES;
- }
-
- // tell constraints they need updating
- [self setNeedsUpdateConstraints];
- // update constraints now so we can animate the change
- [self updateConstraintsIfNeeded];
- [self layoutIfNeeded];
- }
- - (void)loadAvatar:(TUIMessageCellData *)data {
- [self.avatarView setImage:DefaultAvatarImage];
- @weakify(self);
- [[[RACObserve(data, avatarUrl) takeUntil:self.rac_prepareForReuseSignal] ignore:nil] subscribeNext:^(NSURL *url) {
- @strongify(self);
- [self.avatarView sd_setImageWithURL:url placeholderImage:DefaultAvatarImage];
- }];
- if (data.isUseMsgReceiverAvatar) {
- NSString *userId = @"";
- if ([data.innerMessage.sender isEqualToString:V2TIMManager.sharedInstance.getLoginUser]) {
- userId = data.innerMessage.userID;
- } else {
- userId = V2TIMManager.sharedInstance.getLoginUser;
- }
- [V2TIMManager.sharedInstance getUsersInfo:@[ userId?:@"" ]
- succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {
- @strongify(self);
- V2TIMUserFullInfo *info = infoList.firstObject;
- if (info && [data isEqual:self.messageData]) {
- data.avatarUrl = [NSURL URLWithString:info.faceURL];
- [self.avatarView sd_setImageWithURL:data.avatarUrl placeholderImage:DefaultAvatarImage];
- }
- }
- fail:^(int code, NSString *desc){
- }];
- }
- }
- - (void)highlightWhenMatchKeyword:(NSString *)keyword {
- static NSString *const key = @"highlightAnimation";
- if (keyword && keyword.length) {
- if (self.highlightAnimating) {
- return;
- }
- self.highlightAnimating = YES;
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"backgroundColor"];
- animation.repeatCount = 3;
- animation.values = @[
- (id)[[UIColor orangeColor] colorWithAlphaComponent:0.2].CGColor,
- (id)[[UIColor orangeColor] colorWithAlphaComponent:0.5].CGColor,
- (id)[[UIColor orangeColor] colorWithAlphaComponent:0.2].CGColor,
- ];
- animation.duration = 0.5;
- animation.removedOnCompletion = YES;
- animation.delegate = self;
- [self.highlightAnimateView.layer addAnimation:animation forKey:key];
- } else {
- [self.highlightAnimateView.layer removeAnimationForKey:key];
- }
- }
- - (void)updateReadLabelText {
- if (self.messageData.innerMessage.groupID.length > 0) {
- // group message
- NSString *text = TIMCommonLocalizableString(Unread);
- if (self.messageData.messageReceipt == nil) {
- // haven't received the message receipt yet
- return;
- }
- NSInteger readCount = self.messageData.messageReceipt.readCount;
- NSInteger unreadCount = self.messageData.messageReceipt.unreadCount;
- if (unreadCount == 0) {
- // show "All read"
- text = TIMCommonLocalizableString(TUIKitMessageReadAllRead);
- } else if (readCount > 0) {
- // show "x read"
- text = [NSString stringWithFormat:@"%ld %@", (long)readCount, TIMCommonLocalizableString(TUIKitMessageReadPartRead)];
- }
- self.readReceiptLabel.text = text;
- } else {
- // c2c message
- BOOL isPeerRead = self.messageData.messageReceipt.isPeerRead;
- NSString *text = isPeerRead ? TIMCommonLocalizableString(TUIKitMessageReadC2CRead) : TIMCommonLocalizableString(TUIKitMessageReadC2CUnRead);
- self.readReceiptLabel.text = text;
- }
-
- [self.readReceiptLabel sizeToFit];
- [self.readReceiptLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.container.mas_bottom);
- make.trailing.mas_equalTo(self.container.mas_leading).mas_offset(-8);
- make.size.mas_equalTo(self.readReceiptLabel.frame.size);
- }];
- self.readReceiptLabel.textColor = [self shouldHighlightReadReceiptLabel] ? TIMCommonDynamicColor(@"chat_message_read_status_text_color", @"#147AFF")
- : TIMCommonDynamicColor(@"chat_message_read_status_text_gray_color", @"#BBBBBB");
- }
- - (UIView *)highlightAnimateView {
- return self.container;
- }
- #pragma mark - TUIMessageCellProtocol
- + (CGFloat)getEstimatedHeight:(TUIMessageCellData *)data {
- return 60.f;
- }
- + (CGFloat)getHeight:(TUIMessageCellData *)data withWidth:(CGFloat)width {
- CGFloat height = 0;
- if (data.showName) height += kScale375(20);
- if (data.showMessageModifyReplies) height += kScale375(22);
-
- if (data.messageContainerAppendSize.height > 0) {
- height += data.messageContainerAppendSize.height;
- }
-
- CGSize containerSize = [self getContentSize:data];
- height += containerSize.height;
- height += data.cellLayout.messageInsets.top;
- height += data.cellLayout.messageInsets.bottom;
-
- if (height < 55) height = 55;
- return height;
- }
- + (CGSize)getContentSize:(TUIMessageCellData *)data {
- return CGSizeZero;
- }
- #pragma mark - Private
- - (void)animationDidStart:(CAAnimation *)anim {
- self.highlightAnimating = YES;
- }
- - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
- self.highlightAnimating = NO;
- }
- #pragma mark-- Event
- - (void)onLongPress:(UIGestureRecognizer *)recognizer {
- if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]] && recognizer.state == UIGestureRecognizerStateBegan) {
- if (_delegate && [_delegate respondsToSelector:@selector(onLongPressMessage:)]) {
- [_delegate onLongPressMessage:self];
- }
- }
- }
- - (void)onRetryMessage:(UIGestureRecognizer *)recognizer {
- if (_messageData.status == Msg_Status_Fail)
- if (_delegate && [_delegate respondsToSelector:@selector(onRetryMessage:)]) {
- [_delegate onRetryMessage:self];
- }
- }
- - (void)onSelectMessage:(UIGestureRecognizer *)recognizer {
- if (_delegate && [_delegate respondsToSelector:@selector(onSelectMessage:)]) {
- [_delegate onSelectMessage:self];
- }
- }
- - (void)onSelectMessageAvatar:(UIGestureRecognizer *)recognizer {
- if (_delegate && [_delegate respondsToSelector:@selector(onSelectMessageAvatar:)]) {
- [_delegate onSelectMessageAvatar:self];
- }
- }
- - (void)onLongSelectMessageAvatar:(UIGestureRecognizer *)recognizer {
- if (_delegate && [_delegate respondsToSelector:@selector(onLongSelectMessageAvatar:)]) {
- [_delegate onLongSelectMessageAvatar:self];
- }
- }
- - (void)onSelectReadReceipt:(UITapGestureRecognizer *)gesture {
- if (![self shouldHighlightReadReceiptLabel]) {
- return;
- }
- if (_delegate && [_delegate respondsToSelector:@selector(onSelectReadReceipt:)]) {
- [_delegate onSelectReadReceipt:self.messageData];
- }
- }
- - (void)onJumpToRepliesDetailPage:(UIButton *)btn {
- NSLog(@"click onJumpToRepliesDetailPage");
- NSLog(@"%@", self.messageData.messageModifyReplies);
- if (_delegate && [_delegate respondsToSelector:@selector(onJumpToRepliesDetailPage:)]) {
- [_delegate onJumpToRepliesDetailPage:self.messageData];
- }
- }
- - (BOOL)shouldHighlightReadReceiptLabel {
- if (self.messageData.innerMessage.groupID.length == 0) {
- return ![self.readReceiptLabel.text isEqualToString:TIMCommonLocalizableString(TUIKitMessageReadC2CRead)];
- } else {
- return ![self.readReceiptLabel.text isEqualToString:TIMCommonLocalizableString(TUIKitMessageReadAllRead)];
- }
- }
- - (UIFont *)fontWithSize:(CGFloat)size {
- static NSCache *fontCache;
- if (fontCache == nil) {
- fontCache = [[NSCache alloc] init];
- }
- UIFont *font = [fontCache objectForKey:@(size)];
- if (font == nil) {
- font = [UIFont systemFontOfSize:size];
- [fontCache setObject:font forKey:@(size)];
- }
- return font;
- }
- - (void)notifyBottomContainerReadyOfData:(TUIMessageCellData *)cellData {
- // Override by subclass.
- }
- @end
- @implementation TUIMessageCell (TUILayoutConfiguration)
- static UIColor *gOutgoingNameColor;
- + (UIColor *)outgoingNameColor {
- if (!gOutgoingNameColor) {
- gOutgoingNameColor = [UIColor d_systemGrayColor];
- }
- return gOutgoingNameColor;
- }
- + (void)setOutgoingNameColor:(UIColor *)outgoingNameColor {
- gOutgoingNameColor = outgoingNameColor;
- }
- static UIFont *gOutgoingNameFont;
- + (UIFont *)outgoingNameFont {
- if (!gOutgoingNameFont) {
- gOutgoingNameFont = [UIFont systemFontOfSize:14];
- }
- return gOutgoingNameFont;
- }
- + (void)setOutgoingNameFont:(UIFont *)outgoingNameFont {
- gOutgoingNameFont = outgoingNameFont;
- }
- static UIColor *gIncommingNameColor;
- + (UIColor *)incommingNameColor {
- if (!gIncommingNameColor) {
- gIncommingNameColor = [UIColor d_systemGrayColor];
- }
- return gIncommingNameColor;
- }
- + (void)setIncommingNameColor:(UIColor *)incommingNameColor {
- gIncommingNameColor = incommingNameColor;
- }
- static UIFont *gIncommingNameFont;
- + (UIFont *)incommingNameFont {
- if (!gIncommingNameFont) {
- gIncommingNameFont = [UIFont systemFontOfSize:14];
- }
- return gIncommingNameFont;
- }
- + (void)setIncommingNameFont:(UIFont *)incommingNameFont {
- gIncommingNameFont = incommingNameFont;
- }
- - (MOHeadNormalView *)headBgView{
- if(!_headBgView){
- _headBgView = [[MOHeadNormalView alloc] init];
- }
- return _headBgView;
- }
- @end
|