CommentCell.m 4.0 KB
//
//  CommentCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/8.
//

#import "CommentCell.h"

@interface CommentCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIView *replyView;
@end

@implementation CommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
                
        [self.contentView addSubview:self.userIcon];
        [self.contentView addSubview:self.userNameLab];
        [self.contentView addSubview:self.timeLab];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.replyView];
        
        [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(30);
            make.top.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.userNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.userIcon.mas_right).offset(14);
            make.top.equalTo(self.userIcon);
            make.right.equalTo(self.contentView).offset(-30);
        }];
        [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.userNameLab);
            make.bottom.equalTo(self.userIcon);
        }];
    }
    return self;
}

- (void)setComReplyModel:(ComReplyModel *)comReplyModel {
    _comReplyModel = comReplyModel;
    
    [self.userIcon yy_setImageWithURL:[NSURL URLWithString:comReplyModel.commentModel.user_profile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
    self.userNameLab.text = comReplyModel.commentModel.nick_name;
    self.timeLab.text = comReplyModel.commentModel.publish_time;
    self.contentLab.text = comReplyModel.commentModel.content;
    
    [self.contentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userIcon.mas_bottom).offset(8);
        make.left.equalTo(self.contentView).offset(84);
        make.right.equalTo(self.contentView).offset(-30);
        make.height.equalTo(@([comReplyModel commentContentHeight]));
    }];
    [self.replyView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLab.mas_bottom).offset(12);
        make.left.right.equalTo(self.contentLab);
        make.height.equalTo(@([comReplyModel replyViewHeight]));
    }];
}

#pragma mark - lazy
- (UIImageView *)userIcon {
    if (!_userIcon) {
        _userIcon = [UIImageView new];
        [_userIcon cornerRadius:20];
        _userIcon.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f);
    }
    return _userIcon;
}

- (UILabel *)userNameLab {
    if (!_userNameLab) {
        _userNameLab = [UILabel labWithFont:BoldFont(15)];
        _userNameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
    }
    return _userNameLab;
}

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

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

- (UIView *)replyView {
    if (!_replyView) {
        _replyView = [UIView new];
        [_replyView cornerRadius:12];
        _replyView.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, CornerViewDarkColor, BGColor);
    }
    return _replyView;
}

@end