AudioCourseCell.m 7.2 KB
//
//  AudioCourseCell.m
//  DreamSleep
//
//  Created by peter on 2022/5/6.
//

#import "AudioCourseCell.h"

@interface AudioCourseCell ()
@property (nonatomic,strong) UILabel *numberLb;
@property (nonatomic,strong) UIImageView *playVedioImgV;
@property (nonatomic,strong) UILabel *titleLb;
@property (nonatomic,strong) UIImageView *timeimgV;
@property (nonatomic,strong) UILabel *timeLb;
@property (nonatomic,strong) UIButton *pleyerBtn;
@property (nonatomic,strong) UIView *bigView;
@property (nonatomic,strong) UILabel *tryLab;
@end

@implementation AudioCourseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.numberLb = [UILabel new];
        [self.contentView addSubview:self.numberLb];
        self.numberLb.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        self.numberLb.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xDFEFF4), ColorFromHex(0x21364F), DSWhite);
        self.numberLb.textAlignment = NSTextAlignmentCenter;
        self.numberLb.textColor = BrandColor;
        self.numberLb.layer.cornerRadius = 6;
        self.numberLb.layer.masksToBounds = YES;
        [self.numberLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.top.equalTo(self.contentView.mas_top).offset(20);
            make.width.equalTo(@30);
            make.height.equalTo(@30);
        }];
        
        self.playVedioImgV = [UIImageView new];
        [self.contentView addSubview:self.playVedioImgV];
        
        [self.playVedioImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.top.equalTo(self.contentView.mas_top).offset(20);
            make.width.equalTo(@30);
            make.height.equalTo(@30);
        }];
        
        self.bigView = [UIView new];
        [self.contentView addSubview:self.bigView];
        self.bigView.dk_backgroundColorPicker = DKColorPickerWithKey(CornerViewBG);
        self.bigView.layer.cornerRadius = 12;
        self.bigView.layer.masksToBounds = YES;
        [self.bigView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.numberLb.mas_right).offset(12);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        }];
        
        self.titleLb = [UILabel new];
        [self.bigView addSubview:self.titleLb];
        self.titleLb.textAlignment = NSTextAlignmentLeft;
        self.titleLb.text = @"第一天-睡前准备";
        self.titleLb.font = [UIFont systemFontOfSize:15];
        self.titleLb.layer.masksToBounds = YES;
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bigView.mas_left).offset(15);
            make.top.equalTo(self.bigView.mas_top).offset(15);
            make.height.equalTo(@21);
            make.width.equalTo(@190);
        }];
        
        self.timeimgV = [UIImageView new];
        [self.bigView addSubview:self.timeimgV];
        [self.timeimgV dk_setImagePicker:DKImagePickerWithNames(@"muse_time_icon", @"dk_muse_time_icon", @"muse_time_icon")];
        [self.timeimgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bigView.mas_left).offset(15);
            make.bottom.equalTo(self.bigView.mas_bottom).offset(-17);
            make.width.equalTo(@14);
            make.height.equalTo(@14);
        }];
        
        self.timeLb = [UILabel new];
        [self.bigView addSubview:self.timeLb];
        self.timeLb.textAlignment = NSTextAlignmentLeft;
        self.timeLb.text = @"00:01/25:00";
        self.timeLb.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHex(0x626778), DSWhite);
        self.timeLb.font = [UIFont systemFontOfSize:15];
        self.timeLb.layer.masksToBounds = YES;
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.timeimgV.mas_right).offset(8);
            make.centerY.equalTo(self.timeimgV.mas_centerY);
            make.height.equalTo(@17);
            make.width.equalTo(@100);
        }];
        
        self.pleyerBtn = [UIButton new];
        self.pleyerBtn.userInteractionEnabled = NO;
        [self.bigView addSubview:self.pleyerBtn];
        [self.pleyerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bigView.mas_right).offset(-15);
            make.width.equalTo(@40);
            make.height.equalTo(@40);
            make.centerY.equalTo(self.bigView.mas_centerY);
        }];
        
        self.tryLab = [UILabel labWithText:@"试听" font:SysFont(12) fit:NO];
        self.tryLab.dk_textColorPicker = DKColorPickerWithKey(TabBarBG);
        self.tryLab.backgroundColor = BrandColor;
        self.tryLab.hidden = YES;
        [self.tryLab cornerRadius:9];
        self.tryLab.textAlignment = NSTextAlignmentCenter;
        [self.bigView addSubview:self.tryLab];
        [self.tryLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.bigView);
            make.right.equalTo(self.bigView).offset(-15);
            make.size.mas_equalTo(CGSizeMake(40, 18));
        }];
    }
    return self;
}

- (void)updateUI:(SubAudioModel *)model indexPath:(NSIndexPath *)indexPath {
    self.numberLb.hidden = NO;
    self.playVedioImgV.hidden = !self.numberLb.hidden;
    
    self.numberLb.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
    self.timeLb.text = model.play_time;
    self.titleLb.text = model.audio_name;
    
    UIColor *normalTitleColor = model.is_lock == 1 ? ColorFromHex(0x848484) : MainTextColor;
    UIColor *darkTitleColor = model.is_lock == 1 ? ColorFromHex(0xBBBBBB) : ColorFromHex(0xE8E9E9);
    NSString *normalImgName = model.is_lock == 1 ? @"dk_ic_list_play_normal" : @"ic_list_play_normal";
    NSString *darkImgName = model.is_lock == 1 ? @"dk_ic_list_play_normal" : @"dk_ic_list_play_normal_unlock";
    self.titleLb.dk_textColorPicker = DKColorPickerWithColors(normalTitleColor, darkTitleColor, DSWhite);
    [self.pleyerBtn dk_setImage:DKImagePickerWithNames(normalImgName, darkImgName, @"dk_ic_list_play_normal") forState:UIControlStateNormal];
    
    // 音频未🔒
    if (model.is_lock == 0) {
        self.tryLab.hidden = [LoginUtils getUserLoginData];
    } else {
        self.tryLab.hidden = YES;
    }
    self.pleyerBtn.hidden = !self.tryLab.hidden;
}

- (void)updatePlayingAudio {
    self.numberLb.hidden = YES;
    self.playVedioImgV.hidden = !self.numberLb.hidden;
    self.tryLab.hidden = YES;
    self.pleyerBtn.hidden = !self.tryLab.hidden;
    
    [self.playVedioImgV dk_setImagePicker:DKImagePickerWithNames(@"ic_list_playing_normal", @"dk_ic_list_playing_normal", @"ic_list_playing_normal")];
    [self.pleyerBtn setImage:[UIImage imageNamed:@"ic_list_suspend_normal"] forState:UIControlStateNormal];
}

@end