SleepReadyController.m 5.4 KB
//
//  SleepReadyController.m
//  DreamSleep
//
//  Created by peter on 2022/7/11.
//

#import "SleepReadyController.h"
#import "ReadyListController.h"
#import "SRTipsView.h"
#import "SRMusicView.h"
#import "NoisePlayerManager.h"
#import "WhiteNoiseRequestModel.h"

@interface SleepReadyController () <ReadyListControllerDelegate>
@property (nonatomic, strong) UIImageView *headIV;
@property (nonatomic, strong) UIButton *tipsBtn;
@property (nonatomic, strong) UIButton *setBtn;
@property (nonatomic, strong) SRTipsView *sRTipsView;
@property (nonatomic, strong) UIButton *startBtn;
@property (nonatomic, strong) UIButton *musicBtn;
@property (nonatomic, strong) SRMusicView *musicView;
@end

@implementation SleepReadyController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.naviTitle = @"睡前准备";
    self.naviBarAlpha = 1.0;
    self.dsNaviBar.dk_backgroundColorPicker = DKColorPickerWithColors(DSClearColor, DSClearColor, DSWhite);
    [self.dsNaviBar addSubview:self.backBtn];
    self.titleLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
    [self.backBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"sys_back_icon", @"sys_back_icon") forState:UIControlStateNormal];
    
    [self.dsNaviBar addSubview:self.tipsBtn];
    [self.dsNaviBar addSubview:self.setBtn];
    
    self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
    
    [self.view insertSubview:self.headIV atIndex:0];
    [self.view addSubview:self.startBtn];
    [self.view addSubview:self.musicBtn];
    
    [self.tipsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLab);
    }];
    [self.setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tipsBtn);
        make.left.equalTo(self.tipsBtn.mas_right).offset(24);
        make.right.equalTo(self.view).offset(-15);
    }];
    [self.headIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
    }];
    [self.startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(155, 40));
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-94-Bottom_SafeArea_Height);
    }];
    [self.musicBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.startBtn);
        make.right.equalTo(self.view).offset(-15);
    }];
    
    // 暂停白噪音
    [[NSNotificationCenter defaultCenter] postNotificationName:NeedPauseAllNoise object:nil];
    
    [self queryRelaxWhiteNoiseType];
}

- (void)queryRelaxWhiteNoiseType {
    // 获取白噪音类型请求
    [WhiteNoiseRequestModel queryRelaxWhiteNoiseTypeWithCompletion:^(WhiteNoiseRequestModel * _Nonnull requestModel) {
        if (requestModel.resCode == DSResCodeSuccess) {
            DSLog(@"获取白噪音类型请求成功...");
            [self.musicView refreshNoiseTypeData:requestModel.noiseTypeArr];
        }
    }];
}

- (void)backAction {
    // 暂停白噪音
    [[NSNotificationCenter defaultCenter] postNotificationName:NeedPauseAllNoise object:nil];
    
    [super backAction];
}

#pragma mark - ReadyListControllerDelegate

#pragma mark - lazy
- (UIImageView *)headIV {
    if (!_headIV) {
        _headIV = [UIImageView new];
        _headIV.dk_imagePicker = DKImagePickerWithNames(@"bg_anshui_start", @"dk_bg_anshui_start", @"bg_anshui_start");
    }
    return _headIV;
}

- (UIButton *)tipsBtn {
    if (!_tipsBtn) {
        WS(weakSelf);
        _tipsBtn = [UIButton new];
        [_tipsBtn dk_setImage:DKImagePickerWithNames(@"ic_zhunbei_zhushi", @"dk_ic_zhunbei_zhushi", @"ic_zhunbei_zhushi") forState:UIControlStateNormal];
        [_tipsBtn addTouchUpInsideHandler:^(NSInteger tag) {
            [weakSelf.sRTipsView showTipsAlertView];
        }];
    }
    return _tipsBtn;
}

- (UIButton *)setBtn {
    if (!_setBtn) {
        WS(weakSelf);
        _setBtn = [UIButton new];
        [_setBtn dk_setImage:DKImagePickerWithNames(@"ic_zhunbei_set", @"dk_ic_zhunbei_set", @"ic_zhunbei_set") forState:UIControlStateNormal];
        [_setBtn addTouchUpInsideHandler:^(NSInteger tag) {
            ReadyListController *setListVC = [[ReadyListController alloc] initWithDelegate:weakSelf];
            [weakSelf.navigationController pushViewController:setListVC animated:YES];
        }];
    }
    return _setBtn;
}

- (SRTipsView *)sRTipsView {
    if (!_sRTipsView) {
        _sRTipsView = [SRTipsView new];
    }
    return _sRTipsView;
}

- (UIButton *)startBtn {
    if (!_startBtn) {
        _startBtn = [UIButton btnWithTitle:@"开始仪式" font:BoldFont(16.0)];
        [_startBtn cornerRadius:20.0];
        [_startBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
        [_startBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
        [_startBtn addTouchUpInsideHandler:^(NSInteger tag) {
        }];
    }
    return _startBtn;
}

- (UIButton *)musicBtn {
    if (!_musicBtn) {
        WS(weakSelf);
        _musicBtn = [UIButton new];
        [_musicBtn setImage:[UIImage imageNamed:@"ic_zhunbei_baizaoyin"] forState:UIControlStateNormal];
        [_musicBtn addTouchUpInsideHandler:^(NSInteger tag) {
            [weakSelf.musicView showMusicView];
        }];
    }
    return _musicBtn;
}

- (SRMusicView *)musicView {
    if (!_musicView) {
        _musicView = [[SRMusicView alloc] initWithFrame:CGRectZero];
    }
    return _musicView;
}

@end