// // HomeMsgTableViewCell.m // tongxin // // Created by ecell on 2023/4/24. // Copyright © 2023 xTT. All rights reserved. // #import "HomeMsgTableViewCell.h" #import "UIImageView+MultiAvatar.h" #import @interface HomeMsgTableViewCell () @property (nonatomic ,weak) UILabel *msgLabel; @property (nonatomic ,weak) UILabel *timeLabel; @property (nonatomic ,weak) UILabel *titleLabel; @property (nonatomic ,weak) UIImageView *iconImg; @property (nonatomic ,weak) UILabel *msgNumLabel; @end @implementation HomeMsgTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = KKWhiteColorColor; [self subCellView]; } return self; } - (void)setListModel:(HomeChatListModel *)listModel { _listModel = listModel; NSString *nameStr = @""; if (listModel.groupid) { [DCAvatarManager sharedAvatar].distanceBetweenAvatar = 1; [DCAvatarManager sharedAvatar].groupAvatarType = DCGroupAvatarQQType; NSMutableArray *avatorArr = [NSMutableArray new]; for (NSDictionary *dic in listModel.members) { NSString *avator = dic[@"avator"]; [avatorArr addObject:avator]; if([dic[@"openid"] isEqualToString:listModel.message[@"senderID"]]) nameStr = [NSString stringWithFormat:@"%@:",dic[@"name"]]; } [self.iconImg dc_setImageAvatarWithGroupId:listModel.groupid Source:avatorArr]; } else [self.iconImg sd_setImageWithURL:[NSURL URLWithString:listModel.avator] placeholderImage:ImageName_(@"设备默认头像")]; self.titleLabel.text = listModel.groupid ? @"家庭群聊" : listModel.name; NSString *message = @"--"; if (listModel.message) { /// 类型 1 文字 3 语音 4表情 if ([listModel.message[@"type"] integerValue] == 1) message = listModel.message[@"content"]; else if ([listModel.message[@"type"] integerValue] == 3) message = @"[语音]"; else if ([listModel.message[@"type"] integerValue] == 4) message = @"[表情]"; NSTimeInterval timestamp = [listModel.message[@"timestamp"] doubleValue]; self.timeLabel.text = [UICommon updateTimeForRow:[NSString stringWithFormat:@"%.0f",timestamp]]; } self.msgLabel.text = [NSString stringWithFormat:@"%@%@",nameStr,message]; self.msgNumLabel.hidden = listModel.msgNum > 0 ? NO : YES; self.msgNumLabel.text = [NSString stringWithFormat:@"%ld",listModel.msgNum]; if (listModel.msgNum > 0) { CGFloat ww = listModel.msgNum > 9 && listModel.msgNum < 100 ? 25 : listModel.msgNum > 99 ? 32 : 20; [self.msgNumLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.iconImg.mas_right); make.top.equalTo(self.iconImg).offset(3); make.size.mas_equalTo(CGSizeMake(ww, 20)); }]; } } - (void)subCellView { UIImageView *iconImg = [UICommon ui_imageView:CGRectZero fileName:@""]; iconImg.layer.cornerRadius = 28; iconImg.layer.masksToBounds = YES; self.iconImg = iconImg; [self.contentView addSubview:iconImg]; [iconImg mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(self.contentView); make.left.equalTo(self.contentView).offset(15); make.size.mas_equalTo(CGSizeMake(56, 56)); }]; UILabel *msgNumLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(13) textColor:KKWhiteColorColor text:@"" Radius:10]; msgNumLabel.layer.borderWidth = 1.5; msgNumLabel.layer.borderColor = KKWhiteColorColor.CGColor; msgNumLabel.backgroundColor = RGB(254, 83, 71); msgNumLabel.hidden = YES; self.msgNumLabel = msgNumLabel; [self.contentView addSubview:msgNumLabel]; [msgNumLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(iconImg.mas_right).offset(3); make.top.equalTo(iconImg).offset(-3); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(16) textColor:KKTextBlackColor text:@"系统消息" Radius:0]; self.titleLabel = titleLabel; [self.contentView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(iconImg.mas_right).offset(10); make.bottom.equalTo(iconImg.mas_centerY).inset(3); }]; UILabel *msgLabel = [UICommon ui_label:CGRectZero lines:2 align:NSTextAlignmentLeft font:Font_(13) textColor:KKGrey163 text:@"" Radius:0]; self.msgLabel = msgLabel; [self.contentView addSubview:msgLabel]; [msgLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(titleLabel); make.right.equalTo(self.contentView.mas_right).inset(15); make.top.equalTo(iconImg.mas_centerY).offset(3); }]; UILabel *timeLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(11) textColor:KKGrey163 text:@"" Radius:0]; self.timeLabel = timeLabel; [self.contentView addSubview:timeLabel]; [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.contentView.mas_right).inset(15); make.centerY.equalTo(titleLabel); }]; } - (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