RelaxTrainController.m 4.2 KB
//
//  RelaxTrainController.m
//  DreamSleep
//
//  Created by peter on 2022/6/1.
//

#import "RelaxTrainController.h"
#import "RelaxTrainRequestModel.h"
#import "RelaxBodyView.h"

@interface RelaxTrainController () <RelaxBodyViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UILabel *cusTitleLab;
@property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) UIScrollView *lucencyView;
@property (nonatomic, strong) RelaxBodyView *bodyView;
@end

@implementation RelaxTrainController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    
    [self.view addSubview:self.bgIV];
    [self.view addSubview:self.lucencyView];
    [self.lucencyView addSubview:self.bodyView];
    [self.view addSubview:self.dsNaviBar];
    [self.view addSubview:self.dkBackBtn];
    [self.dkBackBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"cus_back_icon", @"dk_cus_back_icon") forState:UIControlStateNormal];
    [self.view addSubview:self.cusTitleLab];
    
    CGFloat iv_h = kScreenWidth*1233/1125.0;
    [self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@(iv_h));
    }];
    [self.cusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.dsNaviBar);
        make.bottom.equalTo(self.dsNaviBar).offset(-9);
    }];
    [self.lucencyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    
    [RelaxTrainRequestModel queryRelaxAudioListWithCompletion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
        if (requestModel.resCode == DSResCodeSuccess) {
            if (requestModel.trainAudioList.count) {
                self.listArr = requestModel.trainAudioList;
                [self.bodyView refreshData:self.listArr currentIndex:0];
            }
        }
    }];
    
#warning - 需要梳理业务逻辑
    [RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
        
    }];
}

#pragma mark - Actions
- (void)backAction {
    [super backAction];
    [self.bodyView stopAudio];
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - RelaxBodyViewDelegate
- (void)updateNaviTitleAndBgImg:(RelaxTrainModel *)trainModel {
    [self.bgIV setImageWithURL:[NSURL URLWithString:trainModel.bg_url] placeholderImage:[UIImage imageNamed:@"basicPlaceholder"]];
    self.cusTitleLab.text = trainModel.audio_name;
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
    CGFloat offset = scrollView.contentOffset.y;
    NSLog(@"offset:%f", offset);
    
    if (offset >= 35) {
        self.dkBackBtn.hidden = YES;
    }
    if (offset <= -20) {
        self.dkBackBtn.hidden = NO;
    }
}

#pragma mark - lazy
- (UIImageView *)bgIV {
    if (!_bgIV) {
        _bgIV = [UIImageView new];
    }
    return _bgIV;
}

- (UILabel *)cusTitleLab {
    if (!_cusTitleLab) {
        _cusTitleLab = [UILabel labWithTextColor:MainTextColor font:BoldFont(18)];
        _cusTitleLab.textAlignment = NSTextAlignmentCenter;
    }
    return _cusTitleLab;
}

- (NSArray *)listArr {
    if (!_listArr) {
        _listArr = [NSArray array];
    }
    return _listArr;
}

- (UIScrollView *)lucencyView {
    if (!_lucencyView) {
        _lucencyView = [UIScrollView new];
        _lucencyView.showsVerticalScrollIndicator = NO;
        _lucencyView.delegate = self;
        CGFloat bodyTopMargin = 351;
        CGFloat bodyH = 420 + Bottom_SafeArea_Height;
        _lucencyView.contentSize = CGSizeMake(kScreenWidth, bodyH + bodyTopMargin);
    }
    return _lucencyView;
}

- (RelaxBodyView *)bodyView {
    if (!_bodyView) {
        _bodyView = [[RelaxBodyView alloc] initWithFrame:CGRectMake(0, 351, kScreenWidth, 420 + Bottom_SafeArea_Height)];
        _bodyView.delegate = self;
    }
    return _bodyView;
}

#pragma mark - 设置状态栏文字颜色(重写父类)
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

@end