123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- //
- // 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
|