SleepStoryView.m
3.1 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
//
// SleepStoryView.m
// DreamSleep
//
// Created by peter on 2022/10/21.
//
#import "SleepStoryView.h"
@interface SleepStoryView () <UITableViewDelegate>
@property (nonatomic, strong) UITableView *storyListView;
@end
@implementation SleepStoryView
- (instancetype)initWithDelegate:(id<SleepStoryViewDelegate>)delegate {
if (self = [super init]) {
self.delegate = delegate;
[self.dataSource addDataArray:@[]];
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
}
return self;
}
#pragma mark - public
- (void)updateList:(NSArray *)dataList {
if (dataList && dataList.count) {
[self.dataSource addDataArray:dataList];
[self.storyListView reloadData];
}
[self.storyListView.mj_header endRefreshing];
}
- (void)endRefresh {
[self.storyListView.mj_header endRefreshing];
}
- (void)reRefresh {
[self.storyListView.mj_header beginRefreshing];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 105;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SubAudioModel *model = self.dataSource.dataArray[indexPath.row];
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectStoryItem:)]) {
[self.delegate didSelectStoryItem:model];
}
}
#pragma mark - lazy
- (DSDataSource *)dataSource {
if (!_dataSource) {
CellConfigureBlock cellBlock = ^(SleepStoryCell * cell, SubAudioModel * model, NSIndexPath * indexPath) {
cell.storyModel = model;
};
_dataSource = [[DSDataSource alloc] initWithIdentifier:NSStringFromClass([SleepStoryCell class]) datas:@[] isSection:NO configureBlock:cellBlock];
UITableView *storyListView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
storyListView.separatorStyle = UITableViewCellSeparatorStyleNone;
storyListView.delegate = self;
storyListView.dataSource = _dataSource;
storyListView.showsVerticalScrollIndicator = NO;
storyListView.backgroundColor = DSClearColor;
storyListView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[storyListView registerClass:[SleepStoryCell class] forCellReuseIdentifier:NSStringFromClass([SleepStoryCell class])];
storyListView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 24 + Bottom_SafeArea_Height)];
[self addSubview:storyListView];
self.storyListView = storyListView;
[self.storyListView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
WS(weakSelf);
storyListView.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(getSleepStoryListData)]) {
[weakSelf.delegate getSleepStoryListData];
}
}];
[storyListView.mj_header beginRefreshing];
}
return _dataSource;
}
@end