SleepReadyController.m
5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// SleepReadyController.m
// DreamSleep
//
// Created by peter on 2022/7/11.
//
#import "SleepReadyController.h"
#import "ReadyListController.h"
#import "NoisePlayerManager.h"
#import "WhiteNoiseRequestModel.h"
#import "SRTipsView.h"
#import "SRMusicView.h"
#import "StartReadyView.h"
#import "ReadyItemView.h"
@interface SleepReadyController () <ReadyListControllerDelegate, StartReadyViewDelegate>
@property (nonatomic, strong) UIButton *tipsBtn;
@property (nonatomic, strong) UIButton *setBtn;
@property (nonatomic, strong) SRTipsView *sRTipsView;
@property (nonatomic, strong) StartReadyView *startReadyView;
@property (nonatomic, strong) ReadyItemView *readyItemView;
@property (nonatomic, strong) UIButton *musicBtn;
@property (nonatomic, strong) SRMusicView *musicView;
@end
@implementation SleepReadyController
- (void)viewDidLoad {
[super viewDidLoad];
[self buildUI];
// 暂停白噪音
[[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 - StartReadyViewDelegate
- (void)startTask {
self.tipsBtn.hidden = YES;
self.setBtn.hidden = YES;
self.startReadyView.hidden = YES;
[self.readyItemView start];
self.naviTitle = @"洗澡";
}
#pragma mark - UI
- (void)buildUI {
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.startReadyView atIndex:0];
[self.view insertSubview:self.readyItemView atIndex:1];
[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.musicBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-15);
make.bottom.equalTo(self.view).offset(-94-Bottom_SafeArea_Height);
}];
[self.startReadyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
[self.readyItemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// 首次弹提示框
if (!kGetUserDefaultsBOOL(IsFirstSRTipsAlert)) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.sRTipsView showTipsAlertView];
kSetUserDefaultsBOOL(YES, IsFirstSRTipsAlert);
kUserDefaultsSynchronize;
});
}
}
#pragma mark - lazy
- (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;
}
- (StartReadyView *)startReadyView {
if (!_startReadyView) {
_startReadyView = [[StartReadyView alloc] initWithDelegate:self];
}
return _startReadyView;
}
- (ReadyItemView *)readyItemView {
if (!_readyItemView) {
_readyItemView = [ReadyItemView new];
}
return _readyItemView;
}
- (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