DSHomeView.m
4.8 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
//
// DSHomeView.m
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import "DSHomeView.h"
#import "CourseMusicCell.h"
#import "GoodSleepHeadView.h"
#import "NoiseView.h"
@interface DSHomeView () <UITableViewDelegate, UITableViewDataSource>
/// 通用数据
@property (nonatomic, strong) NSArray *courseMusicArr;
/// 舒眠课程数据
@property (nonatomic, strong) NSArray *courseListArr;
/// 助眠音乐数据
@property (nonatomic, strong) NSArray *helpListArr;
@property (nonatomic, strong) GoodSleepHeadView *goodSleepHeadView;
@property (nonatomic, strong) NoiseView *noiseView;
@end
@implementation DSHomeView
- (instancetype)init {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTopHeight(0) - kTabBarHeight) style:UITableViewStyleGrouped]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsVerticalScrollIndicator = NO;
self.delegate = self;
self.dataSource = self;
self.tableHeaderView = self.headerView;
self.tableFooterView = self.noiseView;
}
return self;
}
- (void)refreshBarnner:(NSArray *)bannerListData {
[self.headerView updateBannerWithListData:bannerListData];
}
- (void)updateCourseMusicCell:(CellType)type data:(NSArray *)dataArr {
if (dataArr && dataArr.count > 0) {
if (type == CellTypeCourse) {
self.courseListArr = dataArr;
} else if (type == CellTypeMusic) {
self.helpListArr = dataArr;
}
[self reloadData];
}
}
- (void)updateNoiseAllTypeData:(NSArray *)typeDataArr {
if (typeDataArr && typeDataArr.count > 0) {
[self.noiseView refreshNoiseTypeData:typeDataArr];
}
}
- (void)updateSleepStoryView:(id)model {
[self.headerView updateStory:model];
}
#pragma mark - UITableViewDelegate && UITableViewDataSource
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
NSString *cellID = [NSString stringWithFormat:@"CourseMusicCell_%zd", indexPath.row];
CourseMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[CourseMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
[cell configBasicData:self.courseMusicArr[indexPath.row] cellIndex:indexPath.row];
[cell updateCourseMusicListWithData:(indexPath.row == 0 ? self.courseListArr : self.helpListArr) cellIndex:indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.courseMusicArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 228;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 68;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return self.goodSleepHeadView;
}
#pragma mark - lazy
- (HomeHeaderView *)headerView {
if (!_headerView) {
// banner高度
CGFloat bannerH = 2*(kScreenWidth - 48)/5.0;
// 哄睡按钮宽度
CGFloat width = kScreenWidth - 2*15 - 12;
CGFloat coaxH = 170*.3*width/104.0;
// 睡前故事区域高度
CGFloat sleepStoryH = 185;
CGFloat height = 15 + bannerH + 24 + coaxH + 26 + sleepStoryH;
_headerView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
_headerView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
}
return _headerView;
}
- (GoodSleepHeadView *)goodSleepHeadView {
if (!_goodSleepHeadView) {
_goodSleepHeadView = [[GoodSleepHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 68) headType:GSHeadTypeHome];
}
return _goodSleepHeadView;
}
- (NoiseView *)noiseView {
if (!_noiseView) {
_noiseView = [[NoiseView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40 + 327 + 70) noiseTypeData:@[] headType:GSHeadTypeHome];
}
return _noiseView;
}
- (NSArray *)courseMusicArr {
if (!_courseMusicArr) {
_courseMusicArr = [SafeSleepModel getDatas];
}
return _courseMusicArr;
}
- (NSArray *)courseListArr {
if (!_courseListArr) {
_courseListArr = [NSArray array];
}
return _courseListArr;
}
- (NSArray *)helpListArr {
if (!_helpListArr) {
_helpListArr = [NSArray array];
}
return _helpListArr;
}
@end