Commit 1bed1b3e cgx

完成首页舒眠课程和助眠音乐(到时候需要调整)

1 个父辈 1765b8bf
正在显示 24 个修改的文件 包含 392 行增加308 行删除
......@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
/// 查看全部控制器
@interface LookAllController : UIViewController
- (instancetype)initWithIndexPath:(NSIndexPath *)indexPath;
- (instancetype)initWithDefaultIndex:(NSInteger)defaultIndex;
@end
......
......@@ -14,17 +14,17 @@
@end
@implementation LookAllController {
NSIndexPath *_indexPath;
NSInteger _defaultIndex;
UIView *_indicatorView;
NSArray *_btns;
NSInteger _selectedIndex;
}
- (instancetype)initWithIndexPath:(NSIndexPath *)indexPath {
- (instancetype)initWithDefaultIndex:(NSInteger)defaultIndex {
if (self = [super init]) {
_indexPath = indexPath;
_selectedIndex = _indexPath.row;
self.navigationItem.title = indexPath.row == 0 ? @"舒眠课程" : @"助眠音乐";
_defaultIndex = defaultIndex;
_selectedIndex = defaultIndex;
self.navigationItem.title = _defaultIndex == 0 ? @"舒眠课程" : @"助眠音乐";
}
return self;
}
......@@ -121,7 +121,7 @@
}];
[_indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(btn1);
make.centerX.equalTo(_indexPath.row == 0 ? btn1 : btn2);
make.centerX.equalTo(_defaultIndex == 0 ? btn1 : btn2);
make.height.equalTo(@4);
make.bottom.equalTo(_headView);
}];
......
......@@ -12,7 +12,7 @@
*/
typedef enum {
CourseTypeSafe, // 舒眠课程
CourseTypeRelax // 发送音乐
CourseTypeRelax // 放松音乐
} CourseType;
NS_ASSUME_NONNULL_BEGIN
......@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *bg_url;
// 主页显示图标
@property (nonatomic, copy) NSString *home_img;
// 课程数量
@property (nonatomic, assign) int count;
@end
NS_ASSUME_NONNULL_END
......@@ -7,16 +7,23 @@
#import <Foundation/Foundation.h>
// Cell类型
typedef NS_ENUM(NSInteger, CellType) {
CellTypeCourse, // 舒眠课程
CellTypeMusic, // 助眠音乐
CellTypeGood // 好眠声音
};
NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程、助眠音乐、好眠声音数据 model
/// 舒眠课程、助眠音乐、好眠声音数据通用数据 model
@interface SafeSleepModel : NSObject
/// cell标题
@property (nonatomic, copy) NSString *title;
/// 课程列表数据
@property (nonatomic, copy) NSArray *courseListDatas;
/// cell类型
@property (nonatomic, assign) CellType type;
/// 获取所有cell数据
+ (NSArray *)getDatas;
@end
......
......@@ -11,11 +11,12 @@
+ (NSArray *)getDatas {
NSArray *titles = @[@"舒眠课程", @"助眠音乐", @"好眠声音"];
NSArray *types = @[@(CellTypeCourse), @(CellTypeMusic), @(CellTypeGood)];
NSMutableArray *tmpDatas = [NSMutableArray array];
for (int i = 0; i < 3; i++) {
SafeSleepModel *m = [SafeSleepModel new];
m.type = [types[i] integerValue];
m.title = titles[i];
m.courseListDatas = @[];
[tmpDatas addObject:m];
}
return [tmpDatas copy];
......
......@@ -6,15 +6,16 @@
//
#import "HomeViewController.h"
#import "HomeTableView.h"
#import "DSHomeView.h"
#import "RescuePlanView.h"
#import "FirstLeadAlertView.h"
#import "UserRequestModel.h"
#import "HomeRequestModel.h"
#import "ThreeMinuteController.h"
#import "SafeSleepRequestModel.h"
@interface HomeViewController ()
@property (nonatomic, strong) HomeTableView *homeTV;
@property (nonatomic, strong) DSHomeView *homeTV;
@property (nonatomic, strong) RescuePlanView *rescuePlanView;
@end
......@@ -34,14 +35,43 @@
if ([LoginUtils getUserLoginData]) {
// 自动登录请求(调用时机)
[UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {
}];
[UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {}];
}
// 活动运营弹框(首次启动不弹框,后面每隔24个小时请求后台接口)
[self promotionAlert];
// APP首次启动弹框(只出现一次)
[self showFirstLeadAlertView];
[self requestHomeData];
}
#pragma mark - banner、舒眠课程、助眠音乐数据获取
- (void)requestHomeData {
self.homeTV.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
// 获取首页banner数据
[HomeRequestModel queryBannerListWithCompletion:^(HomeRequestModel * _Nonnull requestModel) {
[self.homeTV.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
[self.homeTV refreshBarnner:requestModel.bannerListData];
}
}];
// 获取首页舒眠课程数据
[SafeSleepRequestModel getCourseListDataWithSubID:6 isHome:YES completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
[self.homeTV.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
[self.homeTV updateCourseMusicCell:CellTypeCourse data:requestModel.courseListData];
}
}];
// 获取首页助眠音乐数据
[SafeSleepRequestModel getCourseListDataWithSubID:18 isHome:YES completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
[self.homeTV.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
[self.homeTV updateCourseMusicCell:CellTypeMusic data:requestModel.courseListData];
}
}];
}];
[self.homeTV.mj_header beginRefreshing];
}
#pragma mark - APP首次启动弹框
......@@ -137,9 +167,9 @@
}
#pragma mark - lazy
- (HomeTableView *)homeTV {
- (DSHomeView *)homeTV {
if (!_homeTV) {
_homeTV = [[HomeTableView alloc] init];
_homeTV = [[DSHomeView alloc] init];
}
return _homeTV;
}
......
//
// CourseMusicCell.h
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import "HomeBasicCell.h"
NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程、助眠音乐Cell
@interface CourseMusicCell : HomeBasicCell
/// 刷新首页舒眠课程、助眠音乐列表数据
/// @param dataArr dataArr
/// @param cellIndex cellIndex
- (void)updateCourseMusicListWithData:(NSArray *)dataArr cellIndex:(NSInteger)cellIndex;
@end
NS_ASSUME_NONNULL_END
//
// CourseMusicCell.m
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import "CourseMusicCell.h"
#import "LookAllController.h"
#import "SafeHelperCollectionView.h"
@interface CourseMusicCell ()
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) SafeHelperCollectionView *shCollectionView;
@end
@implementation CourseMusicCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self.contentView addSubview:self.moreBtn];
[self.contentView addSubview:self.shCollectionView];
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.verticalView.mas_centerY);
}];
[self.shCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLab.mas_bottom).offset(17);
make.left.equalTo(self.verticalView);
make.right.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).offset(0);
}];
}
return self;
}
- (void)updateCourseMusicListWithData:(NSArray *)dataArr cellIndex:(NSInteger)cellIndex {
[self.shCollectionView reloadWithData:dataArr cellIndex:cellIndex];
}
- (void)lookAllAction {
NSInteger defaultIndex = self.model.type == CellTypeCourse ? 0 : 1;
LookAllController *lookAllVC = [[LookAllController alloc] initWithDefaultIndex:defaultIndex];
[self.ds_viewController.navigationController pushViewController:lookAllVC animated:YES];
}
#pragma mark - lazy
- (UIButton *)moreBtn {
if (!_moreBtn) {
_moreBtn = [UIButton dkBtnWithSubTitle:@"查看全部" imgName:@"rightRow" font:SysFont(12)];
_moreBtn.frame = CGRectMake(0, 0, 100, 40);
[_moreBtn adjustLayoutWithType:UIButtonLayoutTypeLeftTitleRightImage midSpace:4 sizeToFit:NO];
[_moreBtn addTarget:self action:@selector(lookAllAction) forControlEvents:UIControlEventTouchUpInside];
}
return _moreBtn;
}
- (SafeHelperCollectionView *)shCollectionView {
if (!_shCollectionView) {
_shCollectionView = [[SafeHelperCollectionView alloc] initWithCellIndex:self.cellIndex];
}
return _shCollectionView;
}
@end
//
// DSHomeView.h
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import <UIKit/UIKit.h>
#import "SafeSleepModel.h"
NS_ASSUME_NONNULL_BEGIN
/// APP首页自定义视图
@interface DSHomeView : UITableView
/// 刷新banner
/// @param bannerListData bannerListData
- (void)refreshBarnner:(NSArray *)bannerListData;
/// 刷新舒眠课程或者助眠音乐cell
/// @param type type
/// @param dataArr dataArr
- (void)updateCourseMusicCell:(CellType)type data:(NSArray *)dataArr;
@end
NS_ASSUME_NONNULL_END
//
// HomeTableView.m
// DSHomeView.m
// DreamSleep
//
// Created by peter on 2022/4/8.
// Created by peter on 2022/5/11.
//
#import "HomeTableView.h"
#import "DSHomeView.h"
#import "HomeHeaderView.h"
#import "SafeSleepCell.h"
#import "HomeRequestModel.h"
#import "SafeSleepRequestModel.h"
#import "CourseMusicCell.h"
#import "GoodSleepSoundCell.h"
@interface HomeTableView () <UITableViewDelegate>
@interface DSHomeView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) HomeHeaderView *headerView;
@property (nonatomic, strong) DSDataSource *homeDataSource;
@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, strong) NSArray *courseMusicArr;
@end
@implementation HomeTableView {
// 舒眠课程数据
NSArray *_courseSafeArr;
// 助眠音乐数据
NSArray *_courseHelpArr;
}
@implementation DSHomeView
- (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: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];
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];
self.delegate = self;
self.dataSource = self;
[self registerClass:[CourseMusicCell class] forCellReuseIdentifier:NSStringFromClass([CourseMusicCell class])];
[self registerClass:[GoodSleepSoundCell class] forCellReuseIdentifier:NSStringFromClass([GoodSleepSoundCell class])];
self.tableHeaderView = self.headerView;
}
return self;
}
#pragma mark - lazy
- (DSDataSource *)homeDataSource {
if (!_homeDataSource) {
CellConfigureBlock cellBlock = ^(SafeSleepCell * cell, SafeSleepModel * model, NSIndexPath * indexPath) {
[cell configureCellWithModel:model indexPath:indexPath];
};
NSString * const safeSleepCellID = @"safeSleepCellID";
_homeDataSource = [[DSDataSource alloc] initWithIdentifier:safeSleepCellID datas:@[] isSection:NO configureBlock:cellBlock];
self.dataSource = _homeDataSource;
self.delegate = self;
[self registerClass:[SafeSleepCell class] forCellReuseIdentifier:safeSleepCellID];
self.tableHeaderView = self.headerView;
}
return _homeDataSource;
- (void)refreshBarnner:(NSArray *)bannerListData {
[self.headerView updateBannerWithListData:bannerListData];
}
- (HomeHeaderView *)headerView {
if (!_headerView) {
// banner高度
CGFloat bannerH = 2*(kScreenWidth - 48)/5.0;
// 三分钟即刻入睡按钮宽度
CGFloat width = (kScreenWidth - 2*15 - 14)/2;
CGFloat height = 15 + bannerH + 24 + 133*width/165.0;
_headerView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
_headerView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
- (void)updateCourseMusicCell:(CellType)type data:(NSArray *)dataArr {
NSInteger index = type == CellTypeCourse ? 0 : 1;
CourseMusicCell *cell = (CourseMusicCell *)[self cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];
[cell updateCourseMusicListWithData:dataArr cellIndex:index];
}
- (NSString *)cellIdentiferAtIndexPath:(NSIndexPath *)indexPath {
SafeSleepModel *item = self.courseMusicArr[indexPath.row];
if (item.type == CellTypeGood) {
return NSStringFromClass([GoodSleepSoundCell class]);
} else {
return NSStringFromClass([CourseMusicCell class]);
}
return _headerView;
}
#pragma mark - UITableViewDelegate
#pragma mark - UITableViewDelegate && UITableViewDataSource
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
HomeBasicCell *cell = [tableView dequeueReusableCellWithIdentifier:[self cellIdentiferAtIndexPath:indexPath] forIndexPath:indexPath];
[cell configBasicData:self.courseMusicArr[indexPath.row] cellIndex:indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.courseMusicArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 300;
if (indexPath.row == 0) {
......@@ -119,4 +87,25 @@
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
#pragma mark - lazy
- (HomeHeaderView *)headerView {
if (!_headerView) {
// banner高度
CGFloat bannerH = 2*(kScreenWidth - 48)/5.0;
// 三分钟即刻入睡按钮宽度
CGFloat width = (kScreenWidth - 2*15 - 14)/2;
CGFloat height = 15 + bannerH + 24 + 133*width/165.0;
_headerView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
_headerView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
}
return _headerView;
}
- (NSArray *)courseMusicArr {
if (!_courseMusicArr) {
_courseMusicArr = [SafeSleepModel getDatas];
}
return _courseMusicArr;
}
@end
//
// HomeTableView.h
// GoodSleepSoundCell.h
// DreamSleep
//
// Created by peter on 2022/4/8.
// Created by peter on 2022/5/11.
//
#import <UIKit/UIKit.h>
#import "HomeBasicCell.h"
NS_ASSUME_NONNULL_BEGIN
/// 自定义首页tableView
@interface HomeTableView : UITableView
/// 好眠声音cell
@interface GoodSleepSoundCell : HomeBasicCell
@end
NS_ASSUME_NONNULL_END
//
// GoodSleepSoundCell.m
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import "GoodSleepSoundCell.h"
@interface GoodSleepSoundCell ()
@property (nonatomic, strong) UIButton *timerBtn;
@end
@implementation GoodSleepSoundCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self.contentView addSubview:self.timerBtn];
[self.timerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.verticalView.mas_centerY);
}];
}
return self;
}
#pragma mark - Actions
- (void)timerSetting:(UIButton *)sender {
DSLog(@"66666:%ld", self.model.type);
DSLog(@"timerSetting");
}
#pragma mark - lazy
- (UIButton *)timerBtn {
if (!_timerBtn) {
_timerBtn = [UIButton new];
[_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk", @"timerIcon_dk") forState:UIControlStateNormal];
[_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside];
}
return _timerBtn;
}
@end
//
// SafeSleepCell.h
// HomeBasicCell.h
// DreamSleep
//
// Created by peter on 2022/4/11.
// Created by peter on 2022/5/11.
//
#import <UIKit/UIKit.h>
......@@ -10,14 +10,19 @@
NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程、助眠音乐、好眠声音静态Cell
@interface SafeSleepCell : UITableViewCell
/// 首页基础Cell
@interface HomeBasicCell : UITableViewCell
/// 左边竖条视图
@property (nonatomic, strong) UIView *verticalView;
/// 标题标签
@property (nonatomic, strong) UILabel *titleLab;
/// 通用数据项
@property (nonatomic, strong) SafeSleepModel *model;
@property (nonatomic, strong) NSIndexPath *indexPath;
- (void)configureCellWithModel:(SafeSleepModel *)model indexPath:(NSIndexPath *)indexPath;
/// cellIndex
@property (nonatomic, assign) NSInteger cellIndex;
- (void)configBasicData:(SafeSleepModel *)model cellIndex:(NSInteger)cellIndex;
@end
NS_ASSUME_NONNULL_END
//
// HomeBasicCell.m
// DreamSleep
//
// Created by peter on 2022/5/11.
//
#import "HomeBasicCell.h"
@interface HomeBasicCell ()
@end
@implementation HomeBasicCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.contentView addSubview:self.verticalView];
[self.contentView addSubview:self.titleLab];
[self.verticalView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).offset(10);
make.top.equalTo(self.contentView.mas_top).offset(33);
make.width.equalTo(@4);
make.height.equalTo(@16);
}];
}
return self;
}
- (void)configBasicData:(SafeSleepModel *)model cellIndex:(NSInteger)cellIndex {
_model = model;
_cellIndex = cellIndex;
self.titleLab.text = model.title;
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.verticalView.mas_right).offset(10);
make.centerY.equalTo(self.verticalView.mas_centerY);
}];
}
#pragma mark - lazy
- (UIView *)verticalView {
if (!_verticalView) {
_verticalView = [UIView new];
_verticalView.backgroundColor = BrandColor;
[_verticalView cornerRadius:3];
}
return _verticalView;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel dkLabWithFont:BoldFont(16.0)];
}
return _titleLab;
}
@end
......@@ -12,9 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 舒眠课程、助眠音乐集合视图
@interface SafeHelperCollectionView : UICollectionView
- (instancetype)initCollectionViewWithIndexPath:(NSIndexPath *)indexPath;
- (instancetype)initWithCellIndex:(NSInteger)cellIndex;
- (instancetype)initWithIndexPath:(NSIndexPath *)indexPath courseListDatas:(NSArray *)courseListDatas;
- (void)reloadWithData:(NSArray *)dataArr cellIndex:(NSInteger)cellIndex;
@end
......
......@@ -7,20 +7,22 @@
#import "SafeHelperCollectionView.h"
#import "SafeHelperCollectionViewCell.h"
#import "CourseDetailController.h"
@interface SafeHelperCollectionView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) NSIndexPath *cellIndexPath;
/// 首页传递过来的cell下标
@property (nonatomic, assign) NSInteger cellIndex;
/// 首页舒眠课程和助眠音乐课程列表数据
@property (nonatomic, strong) NSArray *courseListData;
@end
@implementation SafeHelperCollectionView
- (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;
- (instancetype)initWithCellIndex:(NSInteger)cellIndex {
self.cellIndex = cellIndex;
self.courseListData = @[];
CGFloat width = cellIndex == 0 ? 100 : 90;
CGFloat height = cellIndex == 0 ? 130 : 120;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 10);
layout.itemSize = CGSizeMake(width, height);
......@@ -37,6 +39,12 @@
return self;
}
- (void)reloadWithData:(NSArray *)dataArr cellIndex:(NSInteger)cellIndex {
self.cellIndex = cellIndex;
self.courseListData = dataArr;
[self reloadData];
}
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.courseListData.count;
......@@ -44,12 +52,16 @@
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SafeHelperCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shCollectionViewCell" forIndexPath:indexPath];
cell.courseModel = self.courseListData[indexPath.row];
[cell updateCellWithCellIndex:self.cellIndex model:self.courseListData[indexPath.row]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DSLog(@"row:%ld", indexPath.row);
CourseModel *model = [self.courseListData objectAtIndex:indexPath.row];
CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init];
coureDetailVC.courseModel = model;
coureDetailVC.courseType = self.cellIndex == 0 ? CourseTypeSafe : CourseTypeRelax;
[self.ds_viewController.navigationController pushViewController:coureDetailVC animated:YES];
}
@end
......@@ -12,9 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SafeHelperCollectionViewCell : UICollectionViewCell
@property (nonatomic, strong) CourseModel *courseModel;
- (void)mockDatas:(NSIndexPath *)cellIndexPath;
- (void)updateCellWithCellIndex:(NSInteger)cellIndex model:(CourseModel *)model;
@end
......
......@@ -30,23 +30,17 @@
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 = @"都会浪漫";
- (void)updateCellWithCellIndex:(NSInteger)cellIndex model:(CourseModel *)model {
[self.homeIV yy_setImageWithURL:[NSURL URLWithString:model.home_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.audioTypeLab.text = model.audio_name;
[self.audioTypeLab sizeToFit];
if (cellIndexPath.row == 0) { // 舒眠课程
if (cellIndex == 0) { // 舒眠课程
[self insertSubview:self.roundedView belowSubview:self.homeIV];
[self addSubview:self.courseIcon];
[self addSubview:self.courseLab];
self.courseLab.text = @"10课时";
self.courseLab.text = [NSString stringWithFormat:@"%d", model.count];
[self.courseLab sizeToFit];
[self.roundedView mas_makeConstraints:^(MASConstraintMaker *make) {
......@@ -64,9 +58,10 @@
make.centerY.equalTo(self.courseIcon);
}];
}
CGFloat width = cellIndexPath.row == 0 ? 100 : 90;
CGFloat bottomSpace = cellIndexPath.row == 0 ? 0 : -3;
CGFloat topSpacing = cellIndexPath.row == 0 ? 4 : 0;
CGFloat width = cellIndex == 0 ? 100 : 90;
CGFloat bottomSpace = cellIndex == 0 ? 0 : -3;
CGFloat topSpacing = cellIndex == 0 ? 4 : 0;
[self.homeIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(topSpacing);
make.left.equalTo(self);
......
//
// SafeSleepCell.m
// DreamSleep
//
// Created by peter on 2022/4/11.
//
#import "SafeSleepCell.h"
#import "SafeHelperCollectionView.h"
#import "SafeHelperCollectionViewCell.h"
#import "LookAllController.h"
@interface SafeSleepCell ()
@property (nonatomic, strong) UIView *leftIV;
@property (nonatomic, strong) UILabel *recommandLb;
@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) UIButton *timerBtn;
@property (nonatomic, strong) SafeHelperCollectionView *shCollectionView;
@end
@implementation SafeSleepCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.contentView addSubview:self.leftIV];
[self.contentView addSubview:self.recommandLb];
}
return self;
}
// 隐藏选中Cell时的分割线
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
self.selectedBackgroundView.backgroundColor = DSClearColor;
[super setSelected:selected animated:animated];
}
- (void)configureCellWithModel:(SafeSleepModel *)model indexPath:(NSIndexPath *)indexPath {
_model = model;
_indexPath = indexPath;
self.recommandLb.text = model.title;
[self.leftIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).offset(10);
make.top.equalTo(self.contentView.mas_top).offset(33);
make.width.equalTo(@4);
make.height.equalTo(@16);
}];
[self.recommandLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftIV.mas_right).offset(10);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
if (indexPath.row == 2) { // 好眠声音区域
[self.contentView addSubview:self.timerBtn];
[self.timerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
} else { // 舒眠课程和助眠音乐
[self.contentView addSubview:self.moreBtn];
[self.contentView addSubview:self.shCollectionView];
[self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).offset(-5);
make.width.equalTo(@100);
make.height.equalTo(@30);
make.centerY.equalTo(self.leftIV.mas_centerY);
}];
[self.shCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.recommandLb.mas_bottom).offset(17);
make.left.equalTo(self.leftIV);
make.right.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).offset(0);
}];
}
}
#pragma mark - lazy
- (UIView *)leftIV {
if (!_leftIV) {
_leftIV = [UIView new];
_leftIV.backgroundColor = BrandColor;
_leftIV.layer.cornerRadius = 3;
_leftIV.layer.masksToBounds = YES;
}
return _leftIV;
}
- (UILabel *)recommandLb {
if (!_recommandLb) {
_recommandLb = [UILabel dkLabWithText:@"助眠音乐" font:BoldFont(16.0)];
}
return _recommandLb;
}
- (UIButton *)moreBtn {
if (!_moreBtn) {
_moreBtn = [UIButton dkBtnWithSubTitle:@"查看全部" imgName:@"rightRow" font:SysFont(12)];
_moreBtn.frame = CGRectMake(0, 0, 100, 40);
[_moreBtn adjustLayoutWithType:UIButtonLayoutTypeLeftTitleRightImage midSpace:4 sizeToFit:NO];
[_moreBtn addTarget:self action:@selector(lookMore:) forControlEvents:UIControlEventTouchUpInside];
}
return _moreBtn;
}
- (UIButton *)timerBtn {
if (!_timerBtn) {
_timerBtn = [UIButton new];
[_timerBtn dk_setImage:DKImagePickerWithNames(@"timerIcon", @"timerIcon_dk", @"timerIcon_dk") forState:UIControlStateNormal];
[_timerBtn addTarget:self action:@selector(timerSetting:) forControlEvents:UIControlEventTouchUpInside];
}
return _timerBtn;
}
- (SafeHelperCollectionView *)shCollectionView {
if (!_shCollectionView) {
_shCollectionView = [[SafeHelperCollectionView alloc] initWithIndexPath:self.indexPath courseListDatas:@[]];
}
return _shCollectionView;
}
#pragma mark - Actions
- (void)timerSetting:(UIButton *)sender {
DSLog(@"timerSetting");
}
- (void)lookMore:(UIButton *)sender {
LookAllController *lookAllVC = [[LookAllController alloc] initWithIndexPath:self.indexPath];
[self.ds_viewController.navigationController pushViewController:lookAllVC animated:YES];
}
@end
{
"images" : [
{
"filename" : "test0.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "test1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!