Commit d9fb03a7 cgx

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

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