XYLiveRoomChatListTextOrGiftCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //
  2. // XYLiveRoomChatListTextOrGiftCell.m
  3. // Timi
  4. //
  5. // Created by gy on 2021/4/20.
  6. //
  7. #import "XYLiveRoomChatListTextOrGiftCell.h"
  8. #import "UIView+border.h"
  9. #import "UIImage+Extension.h"
  10. #import "QQCorner.h"
  11. #import "XYHeadWearView.h"
  12. #import "YQAnmationResourceMag.h"
  13. #import "XYExpressionItemView.h"
  14. @interface XYLiveRoomChatListTextOrGiftCell(){
  15. }
  16. /// 用户头像
  17. @property (nonatomic, strong) UIView *avatarView;
  18. @property (nonatomic, strong) UIImageView *avatarImgView;
  19. @property (nonatomic, strong) XYHeadWearView *headWearView;
  20. /// 用户标签(等级、靓号、官方等)+ 用户名字
  21. @property (nonatomic, weak) AWRichText *markRichText;
  22. /// 用户标签(等级、靓号、官方等)+ 用户名字
  23. @property (nonatomic, weak) AWRichTextLabel *markRichTextLabel;
  24. /// 阴影背景,礼物或者聊天文字消息,两排
  25. @property (nonatomic, strong) UIImageView *textOrGiftShadowView;
  26. /// 文字聊天、礼物A打赏B、通知上下麦活动消息等等
  27. @property (nonatomic, weak) AWRichText *textRichText;
  28. /// 文字聊天、礼物A打赏B、通知上下麦活动消息等等
  29. @property (nonatomic, strong) AWRichTextLabel *textRichTextLabel;
  30. /// 表情view
  31. @property (nonatomic, strong) XYExpressionItemView *expressionItemView;
  32. /// 消息实体
  33. @property (nonatomic, strong) XYLiveRoomMessageInfo *info;
  34. @end
  35. @implementation XYLiveRoomChatListTextOrGiftCell
  36. + (instancetype)cellWithTableView:(UITableView *)tableView{
  37. static NSString *idf = @"XYLiveRoomChatListTextOrGiftCell";
  38. XYLiveRoomChatListTextOrGiftCell *cell = [tableView dequeueReusableCellWithIdentifier:idf];
  39. if (cell == nil) {
  40. cell = [[XYLiveRoomChatListTextOrGiftCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
  41. cell.backgroundColor = [UIColor clearColor];
  42. cell.backgroundView = nil;
  43. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  44. }
  45. return cell;
  46. }
  47. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  48. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  49. [self setup];
  50. }
  51. return self;
  52. }
  53. - (void)setup{
  54. [self avatarView];
  55. [self textOrGiftShadowView];
  56. }
  57. - (void)reload:(XYLiveRoomMessageInfo *)info{
  58. self.info = info;
  59. if(info.isTextOrGift){//礼物或者聊天文字消息,两排
  60. //[self setStyle:info];
  61. [self updateRichText:self.textOrGiftShadowView andMsgInfo:info];
  62. [self.avatarImgView sd_setImageWithURL:UrlForString(info.senderAvatarUrl) placeholderImage:placeholderUserMainBgImage(1)];
  63. if (!StringIsEmpty(info.headWearAnimationId)) {
  64. [self.headWearView setupHeadWearAnimationId:info.headWearAnimationId];
  65. [self.avatarView mas_updateConstraints:^(MASConstraintMaker *make) {;
  66. make.left.equalTo(self.contentView.mas_left).offset(0);
  67. }];
  68. self.headWearView.hidden = NO;
  69. self.markRichTextLabel.rtFrame = CGRectMake(48, KLiveRoomChatListCellBothShadowMargin, KLiveRoomChatListCellWidth-38, 0);
  70. [self.textOrGiftShadowView mas_updateConstraints:^(MASConstraintMaker *make) {
  71. make.left.equalTo(self.contentView.mas_left).offset(48);
  72. make.width.offset(info.cellShadowWidth-5);
  73. make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin+info.cellUserMarkHeight+2);
  74. }];
  75. }else{
  76. [self.avatarView mas_updateConstraints:^(MASConstraintMaker *make) {;
  77. make.left.equalTo(self.contentView.mas_left).offset(-5);
  78. }];
  79. self.headWearView.hidden = YES;
  80. self.markRichTextLabel.rtFrame = CGRectMake(38, KLiveRoomChatListCellBothShadowMargin, KLiveRoomChatListCellWidth-38, 0);
  81. [self.textOrGiftShadowView mas_updateConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(self.contentView.mas_left).offset(38);
  83. make.width.offset(info.cellShadowWidth-5);
  84. make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin+info.cellUserMarkHeight+2);
  85. }];
  86. }
  87. // self.textOrGiftShadowView.image = [UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  88. // graColor.fromColor = [UIColor colorWithHexString:@"#000000" alpha:0.2];
  89. // graColor.toColor = [UIColor colorWithHexString:@"#000000" alpha:0.2];
  90. // graColor.type = QQGradualChangeTypeUpToDown;
  91. // } size:CGSizeMake(info.cellShadowWidth, info.cellHeight-KLiveRoomChatListCellBothShadowMargin-info.cellUserMarkHeight-2) cornerRadius:QQRadiusMake(2, 12, 12, 12)];
  92. UIImage *bubbleImg = [[YQAnmationResourceMag sharedInstance] getBubbleImage:info.bubbleId];
  93. if (bubbleImg) {//有汽泡图片
  94. UIImage *image0 = [bubbleImg resizeToWidth:bubbleImg.size.width/2.0 height:bubbleImg.size.height/2.0];
  95. UIImage *image = [image0 stretchableImageWithLeftCapWidth:image0.size.width*0.5 topCapHeight:image0.size.height*0.5];
  96. self.textOrGiftShadowView.image = image;
  97. }else{
  98. self.textOrGiftShadowView.image = [UIImage resizableImage:@"xy_roomchatlist_normaltextbg"];
  99. }
  100. self.textRichTextLabel.rtFrame = CGRectMake(KLiveRoomChatListCellStringLeftOrRightMargin, KLiveRoomChatListCellStringTopOrBottomMargin, KLiveRoomChatListCellTextGiftRichTextLableWidth, 0);
  101. // //1.刷新表情视图
  102. // AWRTViewComponent *component = (AWRTViewComponent *)[self.textRichTextLabel.richText componentWithTag:@"1000"];
  103. // UIView *view = component.view;
  104. // if ([view isKindOfClass:[XYExpressionItemView class]]) {
  105. // XYExpressionItemView *itemView = (XYExpressionItemView *)view;
  106. // [itemView reload:info];
  107. // }
  108. // //
  109. // [self.expressionItemView reload:info];
  110. // self.expressionItemView.backgroundColor = [UIColor redColor];
  111. }
  112. }
  113. - (void)updateRichText:(UIImageView *)bearView andMsgInfo:(XYLiveRoomMessageInfo *)info{
  114. //---用户标签(等级、靓号、官方等)+ 用户名字
  115. if (![self.markRichText isEqual:info.userMarkRichText]) {
  116. self.markRichText = info.userMarkRichText;
  117. if (self.markRichTextLabel) {
  118. self.markRichTextLabel.richText = info.userMarkRichText;
  119. self.markRichTextLabel.userInteractionEnabled = YES;
  120. }else{
  121. AWRichTextLabel *markRichTextLabel = [[AWRichTextLabel alloc] initWithRichText:info.userMarkRichText rtFrame:CGRectMake(0, 0, 20, 20)];
  122. self.markRichTextLabel = markRichTextLabel;
  123. [self.contentView addSubview:self.markRichTextLabel];
  124. self.markRichTextLabel.userInteractionEnabled = YES;
  125. }
  126. }
  127. // UIView *view = [[XYLiveManger shareInstance] getSvgaView:info];
  128. // AWRTViewComponent *viewComponent = [self getViewComponent:view];
  129. // [textRichText addComponent:viewComponent];
  130. //---文字聊天、礼物A打赏B,通知上下麦活动消息等,活动消息
  131. if (![self.textRichText isEqual:info.textRichText]) {
  132. self.textRichText = info.textRichText;
  133. if (self.textRichTextLabel) {
  134. self.textRichTextLabel.richText = info.textRichText;
  135. self.textRichTextLabel.userInteractionEnabled = YES;
  136. }else{
  137. self.textRichTextLabel = info.textRichText.createRichTextLabel;
  138. [bearView addSubview:self.textRichTextLabel];
  139. self.textRichTextLabel.userInteractionEnabled = YES;
  140. }
  141. }else {
  142. // 防止表情重复播放
  143. AWRTViewComponent *viewComponent = (AWRTViewComponent *)[self.textRichTextLabel.richText componentWithTag:EXPRESSION_AWRTVIEW_TAG];
  144. if (viewComponent.view) {
  145. XYExpressionItemView *expression = (XYExpressionItemView *)viewComponent.view;
  146. [expression stopAnimating];
  147. }
  148. }
  149. }
  150. - (void)setStyle:(XYLiveRoomMessageInfo *)info{
  151. if([info.nobleValue intValue] == 1) {
  152. } else if([info.nobleValue intValue] == 2) {
  153. } else if([info.nobleValue intValue] == 3) {
  154. } else if([info.nobleValue intValue] == 4) {
  155. } else if([info.nobleValue intValue] == 5) {
  156. } else if([info.nobleValue intValue] == 6) {
  157. } else if([info.nobleValue intValue] == 7) {
  158. }
  159. }
  160. - (void)avatarImgViewAction{
  161. NSMutableDictionary *parm = [[NSMutableDictionary alloc] init];
  162. [parm setObject:self.info.senderId forKey:@"identifier"];
  163. [NotificationCenter postNotificationName:LIVEROOM_CHATLIST_CELL_NOTIFICATION object:nil userInfo:parm];
  164. }
  165. #pragma mark - lazy
  166. - (UIView *)avatarView{
  167. if (_avatarView == nil) {
  168. _avatarView = [[UIView alloc] init];
  169. [self.contentView addSubview:_avatarView];
  170. [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {;
  171. make.left.equalTo(self.contentView.mas_left).offset(-5);
  172. make.top.equalTo(self.contentView.mas_top).offset(10);
  173. make.width.offset(40);
  174. make.height.offset(40);
  175. }];
  176. _avatarImgView = [[UIImageView alloc] init];
  177. _avatarImgView.image = placeholderImage();
  178. _avatarImgView.contentMode = UIViewContentModeScaleAspectFill;
  179. [_avatarView addSubview:_avatarImgView];
  180. [_avatarImgView mas_makeConstraints:^(MASConstraintMaker *make) {;
  181. make.center.equalTo(_avatarView);
  182. make.width.offset(28);
  183. make.height.offset(28);
  184. }];
  185. [_avatarImgView layoutIfNeeded];
  186. kViewRadius(_avatarImgView, 14);
  187. _avatarImgView.userInteractionEnabled = YES;
  188. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarImgViewAction)];
  189. [_avatarImgView addGestureRecognizer:tap];
  190. _headWearView = [[XYHeadWearView alloc] init];
  191. _headWearView.backgroundColor = Color_Clear;
  192. [_avatarView addSubview:_headWearView];
  193. [_headWearView mas_makeConstraints:^(MASConstraintMaker *make) {
  194. make.center.equalTo(_avatarImgView);
  195. make.width.height.equalTo(@40.0f);
  196. }];
  197. UITapGestureRecognizer *avatarImgViewTap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(avatarImgViewAction)];
  198. _headWearView.userInteractionEnabled = YES;
  199. [_headWearView addGestureRecognizer:avatarImgViewTap1];
  200. }
  201. return _avatarView;
  202. }
  203. - (UIImageView *)textOrGiftShadowView{
  204. if (_textOrGiftShadowView == nil) {
  205. _textOrGiftShadowView = [[UIImageView alloc] initWithFrame:CGRectZero];
  206. [self.contentView addSubview:_textOrGiftShadowView];
  207. [_textOrGiftShadowView mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.left.equalTo(self.contentView.mas_left).offset(38);
  209. make.top.equalTo(self.contentView.mas_top).offset(KLiveRoomChatListCellBothShadowMargin);
  210. make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
  211. make.width.offset(10);
  212. }];
  213. _textOrGiftShadowView.userInteractionEnabled = YES;
  214. }
  215. return _textOrGiftShadowView;
  216. }
  217. - (XYExpressionItemView *)expressionItemView{
  218. if (_expressionItemView == nil) {
  219. _expressionItemView = [[XYExpressionItemView alloc] initWithFrame:CGRectZero];
  220. [self.contentView addSubview:_expressionItemView];
  221. [_expressionItemView mas_makeConstraints:^(MASConstraintMaker *make) {
  222. make.left.equalTo(self.contentView.mas_left).offset(0);
  223. make.top.equalTo(self.contentView.mas_top).offset(0);
  224. make.width.offset(30);
  225. make.height.offset(30);
  226. }];
  227. }
  228. return _expressionItemView;
  229. }
  230. - (void)awakeFromNib {
  231. [super awakeFromNib];
  232. // Initialization code
  233. }
  234. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  235. [super setSelected:selected animated:animated];
  236. // Configure the view for the selected state
  237. }
  238. @end