SafeSleepCell.m 4.6 KB
//
//  SafeSleepCell.m
//  DreamSleep
//
//  Created by peter on 2022/4/11.
//

#import "SafeSleepCell.h"
#import "SafeHelperCollectionView.h"
#import "SafeHelperCollectionViewCell.h"

@interface SafeSleepCell ()
@property (nonatomic, strong) UIView *leftIV;
@property (nonatomic, strong) UILabel *recommandLb;
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) UIButton *timerBtn;
@property (nonatomic, strong) SafeHelperCollectionView *shCollectionView;
@end

@implementation SafeSleepCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
        
        [self.contentView addSubview:self.leftIV];
        [self.contentView addSubview:self.recommandLb];
    }
    return self;
}

// 隐藏选中Cell时的分割线
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
    self.selectedBackgroundView.backgroundColor = DSClearColor;
    
    [super setSelected:selected animated:animated];
}

- (void)configureCellWithModel:(SafeSleepModel *)model indexPath:(NSIndexPath *)indexPath {
    _model = model;
    _indexPath = indexPath;
    self.recommandLb.text = model.title;
    
    [self.leftIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.top.equalTo(self.contentView.mas_top).offset(33);
        make.width.equalTo(@4);
        make.height.equalTo(@16);
    }];
    [self.recommandLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftIV.mas_right).offset(10);
        make.centerY.equalTo(self.leftIV.mas_centerY);
    }];
    
    if (indexPath.row == 2) { // 好眠声音区域
        [self.contentView addSubview:self.timerBtn];
        [self.timerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-5);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            make.centerY.equalTo(self.leftIV.mas_centerY);
        }];
    } else { // 舒眠课程和助眠音乐
        [self.contentView addSubview:self.moreBtn];
        [self.contentView addSubview:self.shCollectionView];
        
        [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-5);
            make.width.equalTo(@100);
            make.height.equalTo(@30);
            make.centerY.equalTo(self.leftIV.mas_centerY);
        }];
        [self.shCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.recommandLb.mas_bottom).offset(17);
            make.left.equalTo(self.leftIV);
            make.right.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView).offset(0);
        }];
    }
}

- (UIView *)leftIV {
    if (!_leftIV) {
        _leftIV = [UIView new];
        _leftIV.backgroundColor = BrandColor;
        _leftIV.layer.cornerRadius = 3;
        _leftIV.layer.masksToBounds = YES;
    }
    return _leftIV;
}

- (UILabel *)recommandLb {
    if (!_recommandLb) {
        _recommandLb = [UILabel dkLabWithText:@"助眠音乐" font:BoldFont(16.0)];
    }
    return _recommandLb;
}

- (UIButton *)moreBtn {
    if (!_moreBtn) {
        _moreBtn = [UIButton dkBtnWithSubTitle:@"查看全部" imgName:@"rightRow" font:SysFont(12)];
        _moreBtn.frame = CGRectMake(0, 0, 100, 40);
        [_moreBtn adjustLayoutWithType:UIButtonLayoutTypeLeftTitleRightImage midSpace:4 sizeToFit:NO];
        [_moreBtn addTarget:self action:@selector(lookMore:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _moreBtn;
}

- (UIButton *)timerBtn {
    if (!_timerBtn) {
        _timerBtn = [UIButton new];
        [_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk", @"timerIcon_dk") forState:UIControlStateNormal];
        [_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _timerBtn;
}

- (SafeHelperCollectionView *)shCollectionView {
    if (!_shCollectionView) {
        _shCollectionView = [[SafeHelperCollectionView alloc] initCollectionViewWithIndexPath:self.indexPath];
    }
    return _shCollectionView;
}

#pragma mark - Actions
- (void)timerSetting:(UIButton *)sender {
    DSLog(@"timerSetting");
}

- (void)lookMore:(UIButton *)sender {
    DSLog(@"cellIndexPath:%ld", self.indexPath.row);
}

@end