// // MOLiveMsgBaseCell.m // MiMoLive // // Created by SuperC on 2023/11/19. // #import "MOLiveMsgBaseCell.h" @implementation MOLiveMsgBaseCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self != nil) { self.contentView.transform = CGAffineTransformMakeScale(1, -1); self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self setupUI]; } return self; } - (void)setupUI{ [self.contentView addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(MOBgViewOffSet); make.width.equalTo(@(MOBgViewMaxWidth)); make.top.equalTo(self.contentView).offset(MOBgViewOffSet); make.bottom.equalTo(self.contentView).offset(-MOBgViewOffSet); }]; self.bgView.layer.cornerRadius = 10.0; [self.bgView addSubview:self.bubbleImgView]; [self.bubbleImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.bgView).offset(-MOBgViewOffSet); make.right.equalTo(self.bgView).offset(MOBgViewOffSet); make.top.equalTo(self.bgView).offset(-MOBgViewOffSet); make.bottom.equalTo(self.bgView).offset(MOBgViewOffSet); }]; [self.bgView addSubview:self.contentTextView]; [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.bgView).offset(MOContentLeftAndRighSpacing); make.right.equalTo(self.bgView).offset(-MOContentLeftAndRighSpacing); make.centerY.equalTo(self.bgView); make.height.equalTo(@16.0); }]; self.bgView.userInteractionEnabled = YES; _bubbleTapGestureRecognizer = [UITapGestureRecognizer new]; [_bubbleTapGestureRecognizer addTarget:self action:@selector(bubbleTapped:)]; _bubbleTapGestureRecognizer.delegate = self; [self.bgView addGestureRecognizer:self.bubbleTapGestureRecognizer]; //去除长按 // _bubbleLongPressGestureRecognizer = [UILongPressGestureRecognizer new]; // [_bubbleLongPressGestureRecognizer addTarget:self action:@selector(bubbleLongPressHandler:)]; // [self.bgView addGestureRecognizer:self.bubbleLongPressGestureRecognizer]; } - (void)bubbleTapped:(UITapGestureRecognizer *)recognizer { MOLogV(@"触发了点击"); self.cellTapBlock ? self.cellTapBlock(self.cellModel) : nil; } - (void)bubbleLongPressHandler:(UILongPressGestureRecognizer *)recognizer{ if (recognizer.state == UIGestureRecognizerStateBegan){ MOLogV(@"触发了长按"); self.cellLongPressBlock ? self.cellLongPressBlock(self.cellModel) : nil; recognizer.enabled = NO; } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) { recognizer.enabled = YES; } } - (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 } - (void)setCellModel:(MORtmEntity *)cellModel{ _cellModel = cellModel; NSMutableAttributedString *attributedString = [MOTextTools creteTextWith:cellModel]; // [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, [attributedString length])]; self.contentTextView.attributedText = attributedString; CGFloat contentHeight = cellModel.cellHeight; if(contentHeight < MORtmContentMixHeight){ contentHeight = MORtmContentMixHeight; } [self.contentTextView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@(contentHeight)); }]; self.bgView.backgroundColor = MONormalBgViewColor; MORtmJosnEntity *jsonEntity = (MORtmJosnEntity *)cellModel.data; MORtmUser *rtmUser = cellModel.user; NSInteger theBubble = rtmUser.bubble; if(theBubble == 0){ theBubble = rtmUser.dressing.bubble; } if(theBubble != 0){ //旧逻辑 - 本地找 UIImage *bubbleImg = [MOTextTools getBubbleImgWithCodeNum:theBubble]; if(bubbleImg){ [self.bubbleImgView setImage:bubbleImg]; self.bubbleImgView.hidden = NO; self.bgView.backgroundColor = [UIColor clearColor]; } else{ //使用新逻辑 - 素材库 MOEffect *bubbleObject = [[MOSvgaSourceManage shareManager] getPropsInfoWithCode:theBubble]; if(bubbleObject){ NSURL *bubbleUrl = [NSURL URLWithString:bubbleObject.effectFile]; WEAKSELF [[MOBubbleImageManager sharedManager] resizableImageWithURL:bubbleUrl completion:^(UIImage *image) { dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.bubbleImgView setImage:image]; }); }]; self.bubbleImgView.hidden = NO; self.bgView.backgroundColor = [UIColor clearColor]; } else{ self.bubbleImgView.hidden = YES; } } //PK 或者 禁言 或点赞提示 不用气泡 if((cellModel.type == MORtmRoomTip && (jsonEntity.type == 2 || jsonEntity.type == 3 || jsonEntity.type == 4)) || cellModel.type == MORoomCleanRtmTip || (cellModel.type == MOLikeComboTip && jsonEntity.type == 1) || cellModel.type == SystemTipGetRed || cellModel.type == MOChangeRoomType || cellModel.type == SystemTipHitDiamond || (cellModel.type == SystemOrder && (jsonEntity.type == 9 || jsonEntity.type == 10 || jsonEntity.type == 11)) || cellModel.type == SystemTipNormalBlue || cellModel.type == SystemTipBlindBox){ self.bgView.backgroundColor = MONormalBgViewColor; self.bubbleImgView.hidden = YES; } } else{ self.bubbleImgView.hidden = YES; } if(cellModel.cellHeight > 26.0){ [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@(MOBgViewMaxWidth)); }]; } else{ //UITextView.textContainer.lineFragmentPadding:文本容器的左右内边距(默认值为 5.0)。 CGFloat width = cellModel.contentWidth + MOContentLeftAndRighSpacing * 2.0 + MOContentOffSet * 2.0 ; if(width > MOBgViewMaxWidth){ width = MOBgViewMaxWidth; } if(width < MOBgViewMinWidth){ width = MOBgViewMinWidth; } [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@(width)); }]; } } #pragma mark - Lazy - (UIView *)bgView { if (_bgView == nil) { _bgView = [UIView new]; _bgView.backgroundColor = MONormalBgViewColor; } return _bgView; } - (UIImageView *)bubbleImgView{ if(!_bubbleImgView){ _bubbleImgView = [[UIImageView alloc] init]; // _bubbleImgView.contentMode = UIViewContentModeScaleToFill; [_bubbleImgView setImage:[UIImage imageNamed:@""]]; } return _bubbleImgView; } - (MOMsgContentTextView *)contentTextView{ if(!_contentTextView){ _contentTextView = [MOMsgContentTextView new]; _contentTextView.backgroundColor = [UIColor clearColor]; _contentTextView.textContainerInset = UIEdgeInsetsMake(MOContentBaseTopSpcing, MOContentBaseLeftSpacing, MOContentBaseBottomSpcing, MOContentBaseRightSpacing);//UITextView原本文字距离左右有间距,设置负数消除边距 _contentTextView.editable = NO; _contentTextView.scrollEnabled = NO;//防止滑出屏幕又滑入时有时单行文字消失 _contentTextView.userInteractionEnabled = NO; _contentTextView.textColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0]; // _contentTextView.backgroundColor = [UIColor redColor]; } return _contentTextView; } @end