// // XYLiveRoomChatListTextOrGiftCell.m // Timi // // Created by gy on 2021/4/20. // #import "XYLiveRoomChatListTextOrGiftCell.h" #import "UIView+border.h" #import "UIImage+Extension.h" #import "QQCorner.h" #import "XYHeadWearView.h" #import "YQAnmationResourceMag.h" #import "XYExpressionItemView.h" @interface XYLiveRoomChatListTextOrGiftCell(){ } /// 用户头像 @property (nonatomic, strong) UIView *avatarView; @property (nonatomic, strong) UIImageView *avatarImgView; @property (nonatomic, strong) XYHeadWearView *headWearView; /// 用户标签(等级、靓号、官方等)+ 用户名字 @property (nonatomic, weak) AWRichText *markRichText; /// 用户标签(等级、靓号、官方等)+ 用户名字 @property (nonatomic, weak) AWRichTextLabel *markRichTextLabel; /// 阴影背景,礼物或者聊天文字消息,两排 @property (nonatomic, strong) UIImageView *textOrGiftShadowView; /// 文字聊天、礼物A打赏B、通知上下麦活动消息等等 @property (nonatomic, weak) AWRichText *textRichText; /// 文字聊天、礼物A打赏B、通知上下麦活动消息等等 @property (nonatomic, strong) AWRichTextLabel *textRichTextLabel; /// 表情view @property (nonatomic, strong) XYExpressionItemView *expressionItemView; /// 消息实体 @property (nonatomic, strong) XYLiveRoomMessageInfo *info; @end @implementation XYLiveRoomChatListTextOrGiftCell + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *idf = @"XYLiveRoomChatListTextOrGiftCell"; XYLiveRoomChatListTextOrGiftCell *cell = [tableView dequeueReusableCellWithIdentifier:idf]; if (cell == nil) { cell = [[XYLiveRoomChatListTextOrGiftCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf]; cell.backgroundColor = [UIColor clearColor]; cell.backgroundView = nil; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self setup]; } return self; } - (void)setup{ [self avatarView]; [self textOrGiftShadowView]; } - (void)reload:(XYLiveRoomMessageInfo *)info{ self.info = info; if(info.isTextOrGift){//礼物或者聊天文字消息,两排 //[self setStyle:info]; [self updateRichText:self.textOrGiftShadowView andMsgInfo:info]; [self.avatarImgView sd_setImageWithURL:UrlForString(info.senderAvatarUrl) placeholderImage:placeholderUserMainBgImage(1)]; if (!StringIsEmpty(info.headWearAnimationId)) { [self.headWearView setupHeadWearAnimationId:info.headWearAnimationId]; [self.avatarView mas_updateConstraints:^(MASConstraintMaker *make) {; make.left.equalTo(self.contentView.mas_left).offset(0); }]; self.headWearView.hidden = NO; self.markRichTextLabel.rtFrame = CGRectMake(48, KLiveRoomChatListCellBothShadowMargin, KLiveRoomChatListCellWidth-38, 0); [self.textOrGiftShadowView mas_updateConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(48); make.width.offset(info.cellShadowWidth-5); make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin+info.cellUserMarkHeight+2); }]; }else{ [self.avatarView mas_updateConstraints:^(MASConstraintMaker *make) {; make.left.equalTo(self.contentView.mas_left).offset(-5); }]; self.headWearView.hidden = YES; self.markRichTextLabel.rtFrame = CGRectMake(38, KLiveRoomChatListCellBothShadowMargin, KLiveRoomChatListCellWidth-38, 0); [self.textOrGiftShadowView mas_updateConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(38); make.width.offset(info.cellShadowWidth-5); make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin+info.cellUserMarkHeight+2); }]; } // self.textOrGiftShadowView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { // graColor.fromColor = [UIColor colorWithHexString:@"#000000" alpha:0.2]; // graColor.toColor = [UIColor colorWithHexString:@"#000000" alpha:0.2]; // graColor.type = QQGradualChangeTypeUpToDown; // } size:CGSizeMake(info.cellShadowWidth, info.cellHeight-KLiveRoomChatListCellBothShadowMargin-info.cellUserMarkHeight-2) cornerRadius:QQRadiusMake(2, 12, 12, 12)]; UIImage *bubbleImg = [[YQAnmationResourceMag sharedInstance] getBubbleImage:info.bubbleId]; if (bubbleImg) {//有汽泡图片 UIImage *image0 = [bubbleImg resizeToWidth:bubbleImg.size.width/2.0 height:bubbleImg.size.height/2.0]; UIImage *image = [image0 stretchableImageWithLeftCapWidth:image0.size.width*0.5 topCapHeight:image0.size.height*0.5]; self.textOrGiftShadowView.image = image; }else{ self.textOrGiftShadowView.image = [UIImage resizableImage:@"xy_roomchatlist_normaltextbg"]; } self.textRichTextLabel.rtFrame = CGRectMake(KLiveRoomChatListCellStringLeftOrRightMargin, KLiveRoomChatListCellStringTopOrBottomMargin, KLiveRoomChatListCellTextGiftRichTextLableWidth, 0); // //1.刷新表情视图 // AWRTViewComponent *component = (AWRTViewComponent *)[self.textRichTextLabel.richText componentWithTag:@"1000"]; // UIView *view = component.view; // if ([view isKindOfClass:[XYExpressionItemView class]]) { // XYExpressionItemView *itemView = (XYExpressionItemView *)view; // [itemView reload:info]; // } // // // [self.expressionItemView reload:info]; // self.expressionItemView.backgroundColor = [UIColor redColor]; } } - (void)updateRichText:(UIImageView *)bearView andMsgInfo:(XYLiveRoomMessageInfo *)info{ //---用户标签(等级、靓号、官方等)+ 用户名字 if (![self.markRichText isEqual:info.userMarkRichText]) { self.markRichText = info.userMarkRichText; if (self.markRichTextLabel) { self.markRichTextLabel.richText = info.userMarkRichText; self.markRichTextLabel.userInteractionEnabled = YES; }else{ AWRichTextLabel *markRichTextLabel = [[AWRichTextLabel alloc] initWithRichText:info.userMarkRichText rtFrame:CGRectMake(0, 0, 20, 20)]; self.markRichTextLabel = markRichTextLabel; [self.contentView addSubview:self.markRichTextLabel]; self.markRichTextLabel.userInteractionEnabled = YES; } } // UIView *view = [[XYLiveManger shareInstance] getSvgaView:info]; // AWRTViewComponent *viewComponent = [self getViewComponent:view]; // [textRichText addComponent:viewComponent]; //---文字聊天、礼物A打赏B,通知上下麦活动消息等,活动消息 if (![self.textRichText isEqual:info.textRichText]) { self.textRichText = info.textRichText; if (self.textRichTextLabel) { self.textRichTextLabel.richText = info.textRichText; self.textRichTextLabel.userInteractionEnabled = YES; }else{ self.textRichTextLabel = info.textRichText.createRichTextLabel; [bearView addSubview:self.textRichTextLabel]; self.textRichTextLabel.userInteractionEnabled = YES; } }else { // 防止表情重复播放 AWRTViewComponent *viewComponent = (AWRTViewComponent *)[self.textRichTextLabel.richText componentWithTag:EXPRESSION_AWRTVIEW_TAG]; if (viewComponent.view) { XYExpressionItemView *expression = (XYExpressionItemView *)viewComponent.view; [expression stopAnimating]; } } } - (void)setStyle:(XYLiveRoomMessageInfo *)info{ if([info.nobleValue intValue] == 1) { } else if([info.nobleValue intValue] == 2) { } else if([info.nobleValue intValue] == 3) { } else if([info.nobleValue intValue] == 4) { } else if([info.nobleValue intValue] == 5) { } else if([info.nobleValue intValue] == 6) { } else if([info.nobleValue intValue] == 7) { } } - (void)avatarImgViewAction{ NSMutableDictionary *parm = [[NSMutableDictionary alloc] init]; [parm setObject:self.info.senderId forKey:@"identifier"]; [NotificationCenter postNotificationName:LIVEROOM_CHATLIST_CELL_NOTIFICATION object:nil userInfo:parm]; } #pragma mark - lazy - (UIView *)avatarView{ if (_avatarView == nil) { _avatarView = [[UIView alloc] init]; [self.contentView addSubview:_avatarView]; [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {; make.left.equalTo(self.contentView.mas_left).offset(-5); make.top.equalTo(self.contentView.mas_top).offset(10); make.width.offset(40); make.height.offset(40); }]; _avatarImgView = [[UIImageView alloc] init]; _avatarImgView.image = placeholderImage(); _avatarImgView.contentMode = UIViewContentModeScaleAspectFill; [_avatarView addSubview:_avatarImgView]; [_avatarImgView mas_makeConstraints:^(MASConstraintMaker *make) {; make.center.equalTo(_avatarView); make.width.offset(28); make.height.offset(28); }]; [_avatarImgView layoutIfNeeded]; kViewRadius(_avatarImgView, 14); _avatarImgView.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarImgViewAction)]; [_avatarImgView addGestureRecognizer:tap]; _headWearView = [[XYHeadWearView alloc] init]; _headWearView.backgroundColor = Color_Clear; [_avatarView addSubview:_headWearView]; [_headWearView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(_avatarImgView); make.width.height.equalTo(@40.0f); }]; UITapGestureRecognizer *avatarImgViewTap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(avatarImgViewAction)]; _headWearView.userInteractionEnabled = YES; [_headWearView addGestureRecognizer:avatarImgViewTap1]; } return _avatarView; } - (UIImageView *)textOrGiftShadowView{ if (_textOrGiftShadowView == nil) { _textOrGiftShadowView = [[UIImageView alloc] initWithFrame:CGRectZero]; [self.contentView addSubview:_textOrGiftShadowView]; [_textOrGiftShadowView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(38); make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin); make.bottom.equalTo(self.contentView.mas_bottom).offset(0); make.width.offset(10); }]; _textOrGiftShadowView.userInteractionEnabled = YES; } return _textOrGiftShadowView; } - (XYExpressionItemView *)expressionItemView{ if (_expressionItemView == nil) { _expressionItemView = [[XYExpressionItemView alloc] initWithFrame:CGRectZero]; [self.contentView addSubview:_expressionItemView]; [_expressionItemView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.mas_left).offset(0); make.top.equalTo(self.contentView.mas_top).offset(0); make.width.offset(30); make.height.offset(30); }]; } return _expressionItemView; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end