SleepStoryCell.m 5.0 KB
//
//  SleepStoryCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/21.
//

#import "SleepStoryCell.h"

@interface SleepStoryCell ()
@property (nonatomic, strong) UIImageView *audioIV;
@property (nonatomic, strong) UILabel *audioLab;
@property (nonatomic, strong) UILabel *audioDescLab;
@property (nonatomic, strong) UIImageView *timeIcon;
@property (nonatomic, strong) UILabel *playTimeLab;
@property (nonatomic, strong) UIButton *playBtn;
@end

@implementation SleepStoryCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.audioIV];
        [self.contentView addSubview:self.audioLab];
        [self.contentView addSubview:self.audioDescLab];
        [self.contentView addSubview:self.timeIcon];
        [self.contentView addSubview:self.playTimeLab];
        [self.contentView addSubview:self.playBtn];
        
        [self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(76, 90));
        }];
        [self.audioLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.audioIV);
            make.left.equalTo(self.audioIV.mas_right).offset(12);
            make.right.equalTo(self.contentView).offset(-15);
        }];
        [self.audioDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(45);
            make.left.equalTo(self.audioLab);
            make.right.equalTo(self.contentView).offset(-62);
        }];
        [self.timeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.audioLab);
            make.size.mas_equalTo(CGSizeMake(14, 14));
            make.bottom.equalTo(self.audioIV).offset(-2);
        }];
        [self.playTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.timeIcon.mas_right).offset(8);
            make.centerY.equalTo(self.timeIcon);
            make.right.equalTo(self.contentView).offset(-84);
        }];
        [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15);
        }];
    }
    return self;
}

- (void)setStoryModel:(SubAudioModel *)storyModel {
    _storyModel = storyModel;
    
    [self.audioIV yy_setImageWithURL:[NSURL URLWithString:storyModel.audio_pic] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(76, 90)]];
    self.audioLab.text = storyModel.audio_name;
    self.audioDescLab.text = storyModel.audio_desc;
    self.playTimeLab.text = storyModel.play_time;
}

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

- (UILabel *)audioLab {
    if (!_audioLab) {
        _audioLab = [UILabel labWithFont:BoldFont(16)];
        _audioLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
    }
    return _audioLab;
}

- (UILabel *)audioDescLab {
    if (!_audioDescLab) {
        _audioDescLab = [UILabel labWithFont:SysFont(14)];
        _audioDescLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
    }
    return _audioDescLab;
}

- (UIImageView *)timeIcon {
    if (!_timeIcon) {
        _timeIcon = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"muse_time_icon", @"dk_muse_time_icon", @"muse_time_icon")];
    }
    return _timeIcon;
}

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

- (UIButton *)playBtn {
    if (!_playBtn) {
        _playBtn = [UIButton btnWithTitle:@"播放" font:BoldFont(16)];
        [_playBtn dk_setTitleColorPicker:DKColorPickerWithKey(Sub_Navi_TITLE) forState:UIControlStateNormal];
        _playBtn.size = (CGSizeMake(64, 34));
        [_playBtn cornerRadius:17];
        CGPoint start = CGPointMake(0, 0.5);
        CGPoint end = CGPointMake(0.5, 0.5);
        UIView *normal_tmp_view = [_playBtn genGradientWithStart:start end:end colors:@[(__bridge id)ColorFromHex(0x9BE3EC).CGColor, (__bridge id)ColorFromHex(0x62C3D5).CGColor] locations:@[@(0), @(1.0f)]];
        UIView *dk_tmp_view = [_playBtn genGradientWithStart:start end:end colors:@[(__bridge id)ColorFromHex(0x77A6AE).CGColor, (__bridge id)ColorFromHex(0x45A4B5).CGColor] locations:@[@(0), @(1.0f)]];
        [_playBtn dk_setBackgroundImage:DKImagePickerWithImages([normal_tmp_view snapshotImage], [dk_tmp_view snapshotImage], [normal_tmp_view snapshotImage]) forState:UIControlStateNormal];
    }
    return _playBtn;
}

@end