Commit d9fb03a7 cgx

完成舒眠课程、助眠音乐模块

1 个父辈 ee637f38
...@@ -53,10 +53,6 @@ ...@@ -53,10 +53,6 @@
return self; return self;
} }
- (void)dealloc {
DSLog(@"deallocdeallocdealloc");
}
#pragma mark - Actions #pragma mark - Actions
- (void)dealAction { - (void)dealAction {
if (self.dealBlock) { self.dealBlock(); } if (self.dealBlock) { self.dealBlock(); }
......
...@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
/// 音频详情播放列表页头部视图 /// 音频详情播放列表页头部视图
@interface AudioDetailHeaderView : UIView @interface AudioDetailHeaderView : UIView
- (instancetype)initWithModel:(CourseModel *)model; - (instancetype)initWithModel:(CourseModel *)model courseType:(CourseType)courseType;
@end @end
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
@interface AudioDetailHeaderView () @interface AudioDetailHeaderView ()
@property (nonatomic, strong) UIImageView *bgIV; @property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, strong) UIImageView *audioIV; @property (nonatomic, strong) UIImageView *audioIV;
@property (nonatomic, strong) UILabel *audioNameLab; @property (nonatomic, strong) UILabel *audioNameLab;
@property (nonatomic, strong) UILabel *audioDescLab; @property (nonatomic, strong) UILabel *audioDescLab;
...@@ -17,43 +18,78 @@ ...@@ -17,43 +18,78 @@
@implementation AudioDetailHeaderView @implementation AudioDetailHeaderView
- (instancetype)initWithModel:(CourseModel *)model { - (instancetype)initWithModel:(CourseModel *)model courseType:(CourseType)courseType {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, 250)]) { if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, courseType == CourseTypeSafe ? 250 : 300)]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.clipsToBounds = YES; self.clipsToBounds = YES;
[self addSubview:self.bgIV]; [self addSubview:self.bgIV];
[self addSubview:self.audioIV];
[self addSubview:self.audioNameLab]; [self addSubview:self.audioNameLab];
[self addSubview:self.audioDescLab];
[self addSubview:self.cornerView]; if (courseType == CourseTypeSafe) {
[self addSubview:self.audioIV];
[self addSubview:self.audioDescLab];
[self addSubview:self.cornerView];
self.audioDescLab.text = model.audio_desc;
// self.bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
// self.audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
} else {
[self addSubview:self.maskView];
[self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.width.height.equalTo(@118);
make.top.equalTo(self).offset(118);
}];
}
[self.bgIV yy_setImageWithURL:[NSURL URLWithString:model.bg_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]]; [self.bgIV yy_setImageWithURL:[NSURL URLWithString:model.bg_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]];
[self.audioIV yy_setImageWithURL:[NSURL URLWithString:model.audio_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]]; [self.audioIV yy_setImageWithURL:[NSURL URLWithString:model.audio_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.audioNameLab.text = model.audio_name; self.audioNameLab.text = model.audio_name;
self.audioDescLab.text = model.audio_desc; self.audioNameLab.font = courseType == CourseTypeSafe ? BoldFont(16.0) : BoldFont(18.0);
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) { [self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self); if (courseType == CourseTypeSafe) {
make.edges.equalTo(self);
} else {
make.top.left.right.equalTo(self);
make.height.equalTo(@210);
}
}]; }];
[self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) { [self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(17); if (courseType == CourseTypeSafe) {
make.top.equalTo(self).offset(105); make.left.equalTo(self).offset(17);
make.width.height.equalTo(@100); make.top.equalTo(self).offset(105);
make.width.height.equalTo(@100);
} else {
[self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.maskView);
}];
}
}]; }];
[self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) { [self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.audioIV.mas_right).offset(30); if (courseType == CourseTypeSafe) {
make.top.equalTo(self.audioIV); make.left.equalTo(self.audioIV.mas_right).offset(30);
}]; make.top.equalTo(self.audioIV);
[self.audioDescLab mas_makeConstraints:^(MASConstraintMaker *make) { } else {
make.left.equalTo(self.audioNameLab); make.centerX.equalTo(self);
make.top.equalTo(self.audioNameLab.mas_bottom).offset(10); make.top.equalTo(self.audioIV.mas_bottom).offset(15);
}]; }
[self.cornerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self).offset(20);
make.height.equalTo(@40);
}]; }];
if (courseType == CourseTypeSafe) {
[self.audioDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.audioNameLab);
make.top.equalTo(self.audioNameLab.mas_bottom).offset(10);
}];
[self.cornerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self).offset(20);
make.height.equalTo(@40);
}];
}
} }
return self; return self;
} }
...@@ -62,15 +98,25 @@ ...@@ -62,15 +98,25 @@
- (UIImageView *)bgIV { - (UIImageView *)bgIV {
if (!_bgIV) { if (!_bgIV) {
_bgIV = [UIImageView new]; _bgIV = [UIImageView new];
_bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5); _bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
} }
return _bgIV; return _bgIV;
} }
- (UIView *)maskView {
if (!_maskView) {
_maskView = [UIView new];
_maskView.backgroundColor = DSWhite;
[_maskView cornerRadius:15.0];
[_maskView addSubview:self.audioIV];
}
return _maskView;
}
- (UIImageView *)audioIV { - (UIImageView *)audioIV {
if (!_audioIV) { if (!_audioIV) {
_audioIV = [UIImageView new]; _audioIV = [UIImageView new];
_audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5); _audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .8, .5);
} }
return _audioIV; return _audioIV;
} }
......
...@@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
/// 课程详情页(音频列表) /// 课程详情页(音频列表)
@interface CourseDetailController : DSBaseViewController @interface CourseDetailController : DSBaseViewController
@property (nonatomic, strong) CourseModel *courseModel; @property (nonatomic, strong) CourseModel *courseModel;
@property (nonatomic, assign) CourseType courseType;
@property (nonatomic, weak) id<CourseDetailControllerDelegate> delegate; @property (nonatomic, weak) id<CourseDetailControllerDelegate> delegate;
......
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
[self getAudiosData]; [self getAudiosData];
} }
#pragma mark - UITableViewDelegate, UITableViewDataSource #pragma mark - UITableViewDelegate && UITableViewDataSource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.subAudioArr.count; return self.subAudioArr.count;
} }
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
_audioListView.showsVerticalScrollIndicator = NO; _audioListView.showsVerticalScrollIndicator = NO;
_audioListView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); _audioListView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_audioListView.separatorStyle = UITableViewCellSeparatorStyleNone; _audioListView.separatorStyle = UITableViewCellSeparatorStyleNone;
_audioListView.tableHeaderView = [[AudioDetailHeaderView alloc] initWithModel:self.courseModel]; _audioListView.tableHeaderView = [[AudioDetailHeaderView alloc] initWithModel:self.courseModel courseType:self.courseType];
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)]; UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
_audioListView.tableFooterView = footView; _audioListView.tableFooterView = footView;
_audioListView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _audioListView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
......
...@@ -7,6 +7,14 @@ ...@@ -7,6 +7,14 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
/*
课程类型
*/
typedef enum {
CourseTypeSafe, // 舒眠课程
CourseTypeRelax // 发送音乐
} CourseType;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程和助眠音乐课程数据model /// 舒眠课程和助眠音乐课程数据model
...@@ -23,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -23,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *audio_pic; @property (nonatomic, copy) NSString *audio_pic;
// 背景图 // 背景图
@property (nonatomic, copy) NSString *bg_url; @property (nonatomic, copy) NSString *bg_url;
// 主页显示图标
@property (nonatomic, copy) NSString *home_img;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
} }
} }
- (void)switchViewcontrollerAction:(UIButton *)sender { - (void)switchViewControllerAction:(UIButton *)sender {
_selectedIndex = sender.tag; _selectedIndex = sender.tag;
[UIView animateWithDuration:.3 animations:^{ [UIView animateWithDuration:.3 animations:^{
self->_indicatorView.x = sender.x; self->_indicatorView.x = sender.x;
...@@ -68,18 +68,18 @@ ...@@ -68,18 +68,18 @@
- (UIButton *)btnWithTitle:(NSString *)title font:(UIFont *)font tag:(NSInteger)tag sView:(UIView *)sView { - (UIButton *)btnWithTitle:(NSString *)title font:(UIFont *)font tag:(NSInteger)tag sView:(UIView *)sView {
UIButton *btn = [UIButton btnWithTitle:title font:font]; UIButton *btn = [UIButton btnWithTitle:title font:font];
btn.tag = tag; btn.tag = tag;
[btn addTarget:self action:@selector(switchViewcontrollerAction:) forControlEvents:UIControlEventTouchUpInside]; [btn addTarget:self action:@selector(switchViewControllerAction:) forControlEvents:UIControlEventTouchUpInside];
[sView addSubview:btn]; [sView addSubview:btn];
return btn; return btn;
} }
- (void)addSubControllerView { - (void)addSubControllerView {
SafeSleepListController *safeVC = [[SafeSleepListController alloc] initWithSubID:6]; SafeSleepListController *safeVC = [[SafeSleepListController alloc] initWithCourseType:CourseTypeSafe];
safeVC.view.frame = CGRectMake(0, 0, kScreenWidth, self.bodyView.height); safeVC.view.frame = CGRectMake(0, 0, kScreenWidth, self.bodyView.height);
[self.bodyView addSubview:safeVC.view]; [self.bodyView addSubview:safeVC.view];
[self addChildViewController:safeVC]; [self addChildViewController:safeVC];
SafeSleepListController *relaxVC = [[SafeSleepListController alloc] initWithSubID:18]; SafeSleepListController *relaxVC = [[SafeSleepListController alloc] initWithCourseType:CourseTypeRelax];
relaxVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, self.bodyView.height); relaxVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, self.bodyView.height);
[self.bodyView addSubview:relaxVC.view]; [self.bodyView addSubview:relaxVC.view];
[self addChildViewController:relaxVC]; [self addChildViewController:relaxVC];
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
- (UIView *)headView { - (UIView *)headView {
if (!_headView) { if (!_headView) {
_headView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 30, 40)]; _headView = [[UIView alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 30, 40)];
UIButton *btn1 = [self btnWithTitle:@"舒眠课程" font:BoldFont(16) tag:0 sView:_headView]; UIButton *btn1 = [self btnWithTitle:@"舒眠课程" font:BoldFont(16) tag:0 sView:_headView];
UIButton *btn2 = [self btnWithTitle:@"放松音乐" font:SysFont(15) tag:1 sView:_headView]; UIButton *btn2 = [self btnWithTitle:@"放松音乐" font:SysFont(15) tag:1 sView:_headView];
_indicatorView = [UIView new]; _indicatorView = [UIView new];
...@@ -140,6 +140,7 @@ ...@@ -140,6 +140,7 @@
_bodyView.pagingEnabled = YES; _bodyView.pagingEnabled = YES;
_bodyView.showsHorizontalScrollIndicator = NO; _bodyView.showsHorizontalScrollIndicator = NO;
_bodyView.delegate = self; _bodyView.delegate = self;
[_bodyView setContentOffset:CGPointMake(_selectedIndex * _bodyView.width, 0)];
[self addSubControllerView]; [self addSubControllerView];
} }
......
...@@ -11,7 +11,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,7 +11,11 @@ NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程、助眠音乐、好眠声音数据 model /// 舒眠课程、助眠音乐、好眠声音数据 model
@interface SafeSleepModel : NSObject @interface SafeSleepModel : NSObject
/// cell标题
@property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *title;
/// 课程列表数据
@property (nonatomic, copy) NSArray *courseListDatas;
+ (NSArray *)getDatas; + (NSArray *)getDatas;
@end @end
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
SafeSleepModel *m = [SafeSleepModel new]; SafeSleepModel *m = [SafeSleepModel new];
m.title = titles[i]; m.title = titles[i];
m.courseListDatas = @[];
[tmpDatas addObject:m]; [tmpDatas addObject:m];
} }
return [tmpDatas copy]; return [tmpDatas copy];
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
NSString *api = @"query_relax_meditation_type"; NSString *api = @"query_relax_meditation_type";
NSString *argStr = [NSString stringWithFormat:@"query{%@(sub_id:%d,is_home:%@)}", api, subID, isHome ? @"true" : @"false"]; NSString *argStr = [NSString stringWithFormat:@"query{%@(sub_id:%d,is_home:%@)}", api, subID, isHome ? @"true" : @"false"];
SafeSleepRequestModel * requestModel = [[SafeSleepRequestModel alloc] init]; SafeSleepRequestModel * requestModel = [[SafeSleepRequestModel alloc] init];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary *apiDic) { return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary *apiDic) {
requestModel.resCode = DSResCodeSuccess; requestModel.resCode = DSResCodeSuccess;
DSLog(@"获取舒眠课程、助眠音乐列表数据接口dataDic:%@", apiDic); DSLog(@"获取舒眠课程、助眠音乐列表数据接口dataDic:%@", apiDic);
NSArray *resultArr = apiDic[@"result"]; NSArray *resultArr = apiDic[@"result"];
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "CourseModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程和助眠音乐列表控制器 /// 舒眠课程和助眠音乐列表控制器
@interface SafeSleepListController : UIViewController @interface SafeSleepListController : UIViewController
- (instancetype)initWithSubID:(int)subID; - (instancetype)initWithCourseType:(CourseType)type;
@end @end
......
...@@ -8,21 +8,21 @@ ...@@ -8,21 +8,21 @@
#import "SafeSleepListController.h" #import "SafeSleepListController.h"
#import "SafeSleepRequestModel.h" #import "SafeSleepRequestModel.h"
#import "CourseCollectionCell.h" #import "CourseCollectionCell.h"
#import "CourseModel.h"
#import "CourseDetailController.h" #import "CourseDetailController.h"
@interface SafeSleepListController () <UICollectionViewDataSource, UICollectionViewDelegate> @interface SafeSleepListController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *courseListView; @property (nonatomic, strong) UICollectionView *courseListView;
@property (nonatomic, strong) NSArray *listArr; @property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView;
@end @end
@implementation SafeSleepListController { @implementation SafeSleepListController {
int _sub_id; CourseType _type;
} }
- (instancetype)initWithSubID:(int)subID { - (instancetype)initWithCourseType:(CourseType)type {
if (self = [super init]) { if (self = [super init]) {
_sub_id = subID; _type = type;
_listArr = @[]; _listArr = @[];
} }
return self; return self;
...@@ -34,41 +34,22 @@ ...@@ -34,41 +34,22 @@
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.courseListView]; [self.view addSubview:self.courseListView];
self.courseListView.mj_header = [DSGifHeader headerWithRefreshingBlock:^{ [self getCourseDataRequest];
[self getCourseDataRequest];
}];
[self.courseListView.mj_header beginRefreshing];
} }
- (void)getCourseDataRequest { - (void)getCourseDataRequest {
[SafeSleepRequestModel getCourseListDataWithSubID:self->_sub_id isHome:NO completion:^(SafeSleepRequestModel * _Nonnull requestModel) { [SafeSleepRequestModel getCourseListDataWithSubID:(_type == CourseTypeSafe ? 6 : 18) isHome:NO completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
[self.courseListView.mj_header endRefreshing]; [self.courseListView.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
self.exceptionView.hidden = YES;
self.listArr = requestModel.courseListData; self.listArr = requestModel.courseListData;
[self.courseListView reloadData]; [self.courseListView reloadData];
} else {
self.exceptionView.hidden = NO;
} }
}]; }];
} }
#pragma mark - lazy
- (UICollectionView *)courseListView {
if (!_courseListView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionFootersPinToVisibleBounds = YES;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
CGFloat width = (kScreenWidth - 60)/3;
layout.itemSize = CGSizeMake(width, 130);
layout.minimumInteritemSpacing = 15;
_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;
}
#pragma mark - UICollectionViewDataSource && UICollectionViewDelegate #pragma mark - UICollectionViewDataSource && UICollectionViewDelegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.listArr.count; return self.listArr.count;
...@@ -92,8 +73,39 @@ ...@@ -92,8 +73,39 @@
CourseModel *model = [self.listArr objectAtIndex:indexPath.row]; CourseModel *model = [self.listArr objectAtIndex:indexPath.row];
CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init]; CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init];
coureDetailVC.courseModel = model; coureDetailVC.courseModel = model;
coureDetailVC.courseType = _type;
[self.navigationController pushViewController:coureDetailVC animated:YES]; [self.navigationController pushViewController:coureDetailVC animated:YES];
} }
} }
#pragma mark - lazy
- (UICollectionView *)courseListView {
if (!_courseListView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionFootersPinToVisibleBounds = YES;
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
CGFloat width = (kScreenWidth - 60)/3;
layout.itemSize = CGSizeMake(width, 130);
layout.minimumInteritemSpacing = 15;
_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 @end
...@@ -14,37 +14,56 @@ ...@@ -14,37 +14,56 @@
@interface HomeTableView () <UITableViewDelegate> @interface HomeTableView () <UITableViewDelegate>
@property (nonatomic, strong) HomeHeaderView *headerView; @property (nonatomic, strong) HomeHeaderView *headerView;
@property (nonatomic, strong) DSDataSource *homeDataSource; @property (nonatomic, strong) DSDataSource *homeDataSource;
@property (nonatomic, strong) NSArray *dataArr;
@end @end
@implementation HomeTableView @implementation HomeTableView {
// 舒眠课程数据
NSArray *_courseSafeArr;
// 助眠音乐数据
NSArray *_courseHelpArr;
}
- (instancetype)init { - (instancetype)init {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain]) { if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain]) {
_courseSafeArr = @[];
_courseHelpArr = @[];
self.dataArr = [SafeSleepModel getDatas];
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.separatorStyle = UITableViewCellSeparatorStyleNone; self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsVerticalScrollIndicator = NO; self.showsVerticalScrollIndicator = NO;
[self.homeDataSource addDataArray:[SafeSleepModel getDatas]]; [self.homeDataSource addDataArray:self.dataArr];
self.mj_header = [DSGifHeader headerWithRefreshingBlock:^{ self.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
// 获取首页banner数据
[HomeRequestModel queryBannerListWithCompletion:^(HomeRequestModel * _Nonnull requestModel) { [HomeRequestModel queryBannerListWithCompletion:^(HomeRequestModel * _Nonnull requestModel) {
[self.mj_header endRefreshing]; [self.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
[self.headerView updateBannerWithListData:requestModel.bannerListData]; [self.headerView updateBannerWithListData:requestModel.bannerListData];
} }
}]; }];
// [SafeSleepRequestModel getCourseListDataWithSubID:6 isHome:YES completion:^(SafeSleepRequestModel * _Nonnull requestModel) { // 获取首页舒眠课程数据
// [self.mj_header endRefreshing]; [SafeSleepRequestModel getCourseListDataWithSubID:6 isHome:YES completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
// }]; [self.mj_header endRefreshing];
// [SafeSleepRequestModel getCourseListDataWithSubID:18 isHome:Yes completion:^(SafeSleepRequestModel * _Nonnull requestModel) { if (requestModel.resCode == DSResCodeSuccess) {
// [self.mj_header endRefreshing]; self->_courseSafeArr = requestModel.courseListData;
// }]; }
}];
// 获取首页助眠音乐数据
[SafeSleepRequestModel getCourseListDataWithSubID:18 isHome:YES completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
[self.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
self->_courseHelpArr = requestModel.courseListData;
}
}];
}]; }];
[self.mj_header beginRefreshing]; [self.mj_header beginRefreshing];
} }
return self; return self;
} }
#pragma mark - lazy
- (DSDataSource *)homeDataSource { - (DSDataSource *)homeDataSource {
if (!_homeDataSource) { if (!_homeDataSource) {
CellConfigureBlock cellBlock = ^(SafeSleepCell * cell, SafeSleepModel * model, NSIndexPath * indexPath) { CellConfigureBlock cellBlock = ^(SafeSleepCell * cell, SafeSleepModel * model, NSIndexPath * indexPath) {
......
...@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initCollectionViewWithIndexPath:(NSIndexPath *)indexPath; - (instancetype)initCollectionViewWithIndexPath:(NSIndexPath *)indexPath;
- (instancetype)initWithIndexPath:(NSIndexPath *)indexPath courseListDatas:(NSArray *)courseListDatas;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -10,11 +10,14 @@ ...@@ -10,11 +10,14 @@
@interface SafeHelperCollectionView () <UICollectionViewDelegate, UICollectionViewDataSource> @interface SafeHelperCollectionView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) NSIndexPath *cellIndexPath; @property (nonatomic, strong) NSIndexPath *cellIndexPath;
/// 首页舒眠课程和助眠音乐课程列表数据
@property (nonatomic, strong) NSArray *courseListData;
@end @end
@implementation SafeHelperCollectionView @implementation SafeHelperCollectionView
- (instancetype)initCollectionViewWithIndexPath:(NSIndexPath *)indexPath { - (instancetype)initWithIndexPath:(NSIndexPath *)indexPath courseListDatas:(NSArray *)courseListDatas {
self.courseListData = courseListDatas;
self.cellIndexPath = indexPath; self.cellIndexPath = indexPath;
CGFloat width = indexPath.row == 0 ? 100 : 90; CGFloat width = indexPath.row == 0 ? 100 : 90;
CGFloat height = indexPath.row == 0 ? 130 : 120; CGFloat height = indexPath.row == 0 ? 130 : 120;
...@@ -36,18 +39,17 @@ ...@@ -36,18 +39,17 @@
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource #pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 8; return self.courseListData.count;
} }
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SafeHelperCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shCollectionViewCell" forIndexPath:indexPath]; SafeHelperCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shCollectionViewCell" forIndexPath:indexPath];
cell.courseModel = self.courseListData[indexPath.row];
[cell mockDatas:self.cellIndexPath];
return cell; return cell;
} }
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"row:%ld", indexPath.row); DSLog(@"row:%ld", indexPath.row);
} }
@end @end
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "CourseModel.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface SafeHelperCollectionViewCell : UICollectionViewCell @interface SafeHelperCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) CourseModel *courseModel;
- (void)mockDatas:(NSIndexPath *)cellIndexPath; - (void)mockDatas:(NSIndexPath *)cellIndexPath;
@end @end
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
return self; return self;
} }
- (void)setCourseModel:(CourseModel *)courseModel {
_courseModel = courseModel;
[self.homeIV yy_setImageWithURL:[NSURL URLWithString:courseModel.home_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
}
- (void)mockDatas:(NSIndexPath *)cellIndexPath { - (void)mockDatas:(NSIndexPath *)cellIndexPath {
self.homeIV.image = [UIImage imageNamed:cellIndexPath.row == 0 ? @"test0" : @"test1"]; self.homeIV.image = [UIImage imageNamed:cellIndexPath.row == 0 ? @"test0" : @"test1"];
self.audioTypeLab.text = @"都会浪漫"; self.audioTypeLab.text = @"都会浪漫";
...@@ -72,6 +78,7 @@ ...@@ -72,6 +78,7 @@
}]; }];
} }
#pragma mark - lazy
- (UIView *)roundedView { - (UIView *)roundedView {
if (!_roundedView) { if (!_roundedView) {
_roundedView = [UIView new]; _roundedView = [UIView new];
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.contentView addSubview:self.leftIV]; [self.contentView addSubview:self.leftIV];
[self.contentView addSubview:self.recommandLb]; [self.contentView addSubview:self.recommandLb];
} }
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
} }
} }
#pragma mark - lazy
- (UIView *)leftIV { - (UIView *)leftIV {
if (!_leftIV) { if (!_leftIV) {
_leftIV = [UIView new]; _leftIV = [UIView new];
...@@ -119,7 +120,7 @@ ...@@ -119,7 +120,7 @@
- (SafeHelperCollectionView *)shCollectionView { - (SafeHelperCollectionView *)shCollectionView {
if (!_shCollectionView) { if (!_shCollectionView) {
_shCollectionView = [[SafeHelperCollectionView alloc] initCollectionViewWithIndexPath:self.indexPath]; _shCollectionView = [[SafeHelperCollectionView alloc] initWithIndexPath:self.indexPath courseListDatas:@[]];
} }
return _shCollectionView; return _shCollectionView;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!