MessageComReplyCell.m 6.7 KB
//
//  MessageComReplyCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/10.
//

#import "MessageComReplyCell.h"

@interface MessageComReplyCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UILabel *preContentLab;
@property (nonatomic, strong) UIButton *replyBtn;
@end

@implementation MessageComReplyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = DSClearColor;
        
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.nameLab];
        [self.contentView addSubview:self.timeLab];
        [self.contentView addSubview:self.detailLab];
        [self.contentView addSubview:self.mesCountLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.lineView];
        [self.contentView addSubview:self.preContentLab];
        [self.contentView addSubview:self.replyBtn];
        
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.icon.mas_right).offset(12);
            make.bottom.equalTo(self.icon);
            make.right.equalTo(self.contentView).offset(-12);
        }];
    }
    return self;
}

- (void)setComReplyModel:(MessageComReplyModel *)comReplyModel {
    _comReplyModel = comReplyModel;
    
    [self.icon yy_setImageWithURL:[NSURL URLWithString:comReplyModel.userProfile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
    self.nameLab.text = comReplyModel.nickName;
    self.timeLab.text = comReplyModel.publishTime;
    self.detailLab.text = comReplyModel.type == 0 ? @"评论了你的动态" : @"回复你的评论";
    self.contentLab.text = comReplyModel.content;
    self.preContentLab.text = comReplyModel.preContent;
    [self.timeLab sizeToFit];
    
    [self.timeLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-15);
        make.top.equalTo(self.contentView).offset(3);
    }];
    [self.nameLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.detailLab);
        make.top.equalTo(self.icon);
        make.right.equalTo(self.timeLab.mas_left).offset(-12);
    }];
    [self.contentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon.mas_bottom).offset(3);
        make.left.equalTo(self.contentView).offset([MessageComReplyModel contentLeftMargin]);
        make.right.equalTo(self.contentView).offset(-[MessageComReplyModel contentRightMargin]);
        make.height.equalTo(@([comReplyModel contentHeight]));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLab);
        make.top.equalTo(self.contentLab.mas_bottom).offset(9);
        make.size.mas_equalTo(CGSizeMake(2, 14));
    }];
    [self.preContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLab.mas_bottom).offset(6);
        make.left.equalTo(self.lineView.mas_right).offset(4);
        make.right.equalTo(self.contentLab);
        make.height.equalTo(@([comReplyModel preContentHeight]));
    }];
    [self.replyBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLab);
        make.size.mas_equalTo(CGSizeMake(116, 30));
        make.bottom.equalTo(self.contentView).offset(-30);
    }];
}

#pragma mark - private
- (void)replyAction {
    if (self.tapReplyBtnBlock) { self.tapReplyBtnBlock(); }
}

#pragma mark - lazy
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [UIImageView new];
        _icon.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
        [_icon cornerRadius:20];
    }
    return _icon;
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [UILabel labWithFont:BoldFont(15)];
        _nameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
    }
    return _nameLab;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [UILabel labWithFont:SysFont(12)];
        _timeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
        _timeLab.textAlignment = NSTextAlignmentRight;
    }
    return _timeLab;
}

- (UILabel *)detailLab {
    if (!_detailLab) {
        _detailLab = [UILabel labWithFont:SysFont(12)];
        _detailLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
    }
    return _detailLab;
}

- (UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [UILabel labWithFont:[MessageComReplyModel contentFont]];
        _contentLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
        _contentLab.numberOfLines = 0;
    }
    return _contentLab;
}

- (UILabel *)preContentLab {
    if (!_preContentLab) {
        _preContentLab = [UILabel labWithFont:[MessageComReplyModel preContentFont]];
        _preContentLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .4), DSWhite);
    }
    return _preContentLab;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xF0F0F0), ColorFromHex(0x1F263F), DSWhite);
        [_lineView cornerRadius:3];
    }
    return _lineView;
}

- (UIButton *)replyBtn {
    if (!_replyBtn) {
        _replyBtn = [UIButton btnWithTitle:@"回复评论" font:SysFont(12)];
        [_replyBtn cornerRadius:15];
        [_replyBtn dk_setImage:DKImagePickerWithNames(@"ic_shequ_pinlun", @"dk_ic_shequ_pinlun", @"ic_shequ_pinlun") forState:UIControlStateNormal];
        [_replyBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite) forState:UIControlStateNormal];
        _replyBtn.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
        [_replyBtn addTarget:self action:@selector(replyAction) forControlEvents:UIControlEventTouchUpInside];
        _replyBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 8);
    }
    return _replyBtn;
}

@end