SafeSleepListController.m
4.0 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
//
// SafeSleepListController.m
// DreamSleep
//
// Created by peter on 2022/5/5.
//
#import "SafeSleepListController.h"
#import "SafeSleepRequestModel.h"
#import "CourseCollectionCell.h"
#import "CourseDetailController.h"
@interface SafeSleepListController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *courseListView;
@property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView;
@end
@implementation SafeSleepListController {
CourseType _type;
}
- (instancetype)initWithCourseType:(CourseType)type {
if (self = [super init]) {
_type = type;
_listArr = @[];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.courseListView];
[self getCourseDataRequest];
}
- (void)getCourseDataRequest {
[SafeSleepRequestModel getCourseListDataWithSubID:(_type == CourseTypeSafe ? 6 : 18) isHome:NO completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
self.exceptionView.hidden = YES;
self.listArr = requestModel.courseListData;
[self.courseListView reloadData];
} else {
self.exceptionView.hidden = NO;
[self.exceptionView showServerErrInfo:requestModel.errMessage];
}
}];
}
#pragma mark - UICollectionViewDataSource && UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.listArr.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CourseCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CourseCollectionCellID" forIndexPath:indexPath];
CourseModel *model = [self.listArr objectAtIndex:indexPath.row];
if (indexPath.row < self.listArr.count) {
cell.model = model;
}
cell.courseType = _type;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.listArr.count > indexPath.row) {
CourseModel *model = [self.listArr objectAtIndex:indexPath.row];
CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init];
coureDetailVC.courseModel = model;
coureDetailVC.courseType = _type;
coureDetailVC.entrance = EntranceCourseList;
[self.navigationController pushViewController:coureDetailVC animated:YES];
}
}
#pragma mark - lazy
- (UICollectionView *)courseListView {
if (!_courseListView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionFootersPinToVisibleBounds = YES;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.itemSize = [CourseModel itemSize];
layout.sectionInset = [CourseModel sectionEdgeInset];
layout.minimumLineSpacing = [CourseModel minimumLineSpacing];
_courseListView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, self.view.height - Bottom_SafeArea_Height - kTopHeight(0) - 40) collectionViewLayout:layout];
_courseListView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_courseListView.showsVerticalScrollIndicator = NO;
_courseListView.delegate = self;
_courseListView.dataSource = self;
[_courseListView registerClass:[CourseCollectionCell class] forCellWithReuseIdentifier:@"CourseCollectionCellID"];
}
return _courseListView;
}
- (ExceptionDefaultView *)exceptionView {
if (!_exceptionView) {
WS(weakSelf);
_exceptionView = [[ExceptionDefaultView alloc] initWithType:ExceptionTypeNet block:^{
weakSelf.exceptionView.hidden = YES;
[weakSelf getCourseDataRequest];
} superView:self.view];
}
return _exceptionView;
}
@end