Commit e848ee29 cgx

基本完成设置睡前安排页面

1 个父辈 dd728923
......@@ -47,6 +47,7 @@
D02D0827287BBEDE005C3A00 /* SleepReadyController.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D0826287BBEDE005C3A00 /* SleepReadyController.m */; };
D02D082A287BCEF3005C3A00 /* SRTipsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D0829287BCEF3005C3A00 /* SRTipsView.m */; };
D02D082D287BD05D005C3A00 /* ReadyListController.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D082C287BD05D005C3A00 /* ReadyListController.m */; };
D02E85882882A594002DAD7E /* PrepareItemsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D02E85872882A594002DAD7E /* PrepareItemsCell.m */; };
D030C1B8284775930014946F /* RelaxTrainController.m in Sources */ = {isa = PBXBuildFile; fileRef = D030C1B7284775930014946F /* RelaxTrainController.m */; };
D0336163285035AB005573CF /* DailyBgView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0336162285035AB005573CF /* DailyBgView.m */; };
D037B11228752A7E00236753 /* IndividualController.m in Sources */ = {isa = PBXBuildFile; fileRef = D037B11128752A7E00236753 /* IndividualController.m */; };
......@@ -97,7 +98,6 @@
D0691E01287FB330008BFFAB /* XLCircle.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691DFE287FB330008BFFAB /* XLCircle.m */; };
D0691E02287FB331008BFFAB /* XLCircleProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691DFF287FB330008BFFAB /* XLCircleProgress.m */; };
D0691E05287FEA04008BFFAB /* SleepReadyRequestModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691E04287FEA04008BFFAB /* SleepReadyRequestModel.m */; };
D0691E08287FF56D008BFFAB /* JXMovableCellTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691E06287FF56D008BFFAB /* JXMovableCellTableView.m */; };
D0691E0B287FFB54008BFFAB /* ReadyItem.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691E0A287FFB54008BFFAB /* ReadyItem.m */; };
D0691E0E288009D3008BFFAB /* ReadyItemCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691E0D288009D3008BFFAB /* ReadyItemCell.m */; };
D0691E1128801D43008BFFAB /* RelaxItemsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0691E1028801D43008BFFAB /* RelaxItemsView.m */; };
......@@ -347,6 +347,8 @@
D02D0829287BCEF3005C3A00 /* SRTipsView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRTipsView.m; sourceTree = "<group>"; };
D02D082B287BD05D005C3A00 /* ReadyListController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReadyListController.h; sourceTree = "<group>"; };
D02D082C287BD05D005C3A00 /* ReadyListController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReadyListController.m; sourceTree = "<group>"; };
D02E85862882A594002DAD7E /* PrepareItemsCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrepareItemsCell.h; sourceTree = "<group>"; };
D02E85872882A594002DAD7E /* PrepareItemsCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrepareItemsCell.m; sourceTree = "<group>"; };
D030C1B6284775930014946F /* RelaxTrainController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainController.h; sourceTree = "<group>"; };
D030C1B7284775930014946F /* RelaxTrainController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainController.m; sourceTree = "<group>"; };
D0336161285035AB005573CF /* DailyBgView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DailyBgView.h; sourceTree = "<group>"; };
......@@ -442,8 +444,6 @@
D0691E00287FB330008BFFAB /* XLCircle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XLCircle.h; sourceTree = "<group>"; };
D0691E03287FEA04008BFFAB /* SleepReadyRequestModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SleepReadyRequestModel.h; sourceTree = "<group>"; };
D0691E04287FEA04008BFFAB /* SleepReadyRequestModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SleepReadyRequestModel.m; sourceTree = "<group>"; };
D0691E06287FF56D008BFFAB /* JXMovableCellTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXMovableCellTableView.m; sourceTree = "<group>"; };
D0691E07287FF56D008BFFAB /* JXMovableCellTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXMovableCellTableView.h; sourceTree = "<group>"; };
D0691E09287FFB54008BFFAB /* ReadyItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReadyItem.h; sourceTree = "<group>"; };
D0691E0A287FFB54008BFFAB /* ReadyItem.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReadyItem.m; sourceTree = "<group>"; };
D0691E0C288009D3008BFFAB /* ReadyItemCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ReadyItemCell.h; sourceTree = "<group>"; };
......@@ -1061,12 +1061,12 @@
D0691E0A287FFB54008BFFAB /* ReadyItem.m */,
D0691E0C288009D3008BFFAB /* ReadyItemCell.h */,
D0691E0D288009D3008BFFAB /* ReadyItemCell.m */,
D02E85862882A594002DAD7E /* PrepareItemsCell.h */,
D02E85872882A594002DAD7E /* PrepareItemsCell.m */,
D0691E1228801EF3008BFFAB /* ReadyTimeMarker.h */,
D0691E1328801EF3008BFFAB /* ReadyTimeMarker.m */,
D0691E0F28801D43008BFFAB /* RelaxItemsView.h */,
D0691E1028801D43008BFFAB /* RelaxItemsView.m */,
D0691E07287FF56D008BFFAB /* JXMovableCellTableView.h */,
D0691E06287FF56D008BFFAB /* JXMovableCellTableView.m */,
D02D0828287BCEF3005C3A00 /* SRTipsView.h */,
D02D0829287BCEF3005C3A00 /* SRTipsView.m */,
D024CE87287D59FF00FB4320 /* SRMusicView.h */,
......@@ -2267,6 +2267,7 @@
D091E66B283F120100D3279E /* MyScoreModel.m in Sources */,
D01BD428282C003900BA86B3 /* NoiseTypeModel.m in Sources */,
D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */,
D02E85882882A594002DAD7E /* PrepareItemsCell.m in Sources */,
D0D69ED3282360F100A0D5EB /* LookAllController.m in Sources */,
D07A4B2D280EA73B00BA0EC0 /* UserInfoView.m in Sources */,
D0878F48280BD18F005F1B7F /* LoginView.m in Sources */,
......@@ -2285,7 +2286,6 @@
D037B1172875635F00236753 /* DarwArcView.swift in Sources */,
D08F79E0281A1838000D99DD /* TZImagePickerController.m in Sources */,
D091E671283F2E6F00D3279E /* ScoreDetailListController.m in Sources */,
D0691E08287FF56D008BFFAB /* JXMovableCellTableView.m in Sources */,
D07DACAB2810557D0067A1BF /* RSKImageScrollView.m in Sources */,
D0AEFE812817DD1500230DC6 /* MyFeedCell.m in Sources */,
D02D082D287BD05D005C3A00 /* ReadyListController.m in Sources */,
......
//
// JXMovableCellTableView.h
// JXMovableCellTableView
//
// Created by jiaxin on 16/2/15.
// Copyright © 2016年 jiaxin. All rights reserved.
//
#import <UIKit/UIKit.h>
@class JXMovableCellTableView;
@protocol JXMovableCellTableViewDataSource <UITableViewDataSource>
@required
/**
* 获取tableView的数据源数组
*/
- (NSArray *)dataSourceArrayInTableView:(JXMovableCellTableView *)tableView;
/**
* 返回移动之后调换后的数据源
*/
- (void)tableView:(JXMovableCellTableView *)tableView newDataSourceArrayAfterMove:(NSArray *)newDataSourceArray;
@end
@protocol JXMovableCellTableViewDelegate <UITableViewDelegate>
@optional
/**
* 将要开始移动indexPath位置的cell
*/
- (void)tableView:(JXMovableCellTableView *)tableView willMoveCellAtIndexPath:(NSIndexPath *)indexPath;
/**
* 完成一次从fromIndexPath cell到toIndexPath cell的移动
*/
- (void)tableView:(JXMovableCellTableView *)tableView didMoveCellFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath;
/**
* 结束移动cell在indexPath
*/
- (void)tableView:(JXMovableCellTableView *)tableView endMoveCellAtIndexPath:(NSIndexPath *)indexPath;
@end
@interface JXMovableCellTableView : UITableView
@property (nonatomic, weak) id<JXMovableCellTableViewDataSource> dataSource;
@property (nonatomic, weak) id<JXMovableCellTableViewDelegate> delegate;
/**
* 长按手势最小触发时间,默认1.0,最小0.2
*/
@property (nonatomic, assign) CGFloat gestureMinimumPressDuration;
/**
* 自定义可移动cell的截图样式
*/
@property (nonatomic, copy) void(^drawMovalbeCellBlock)(UIView *movableCell);
/**
* 是否允许拖动到屏幕边缘后,开启边缘滚动,默认YES
*/
@property (nonatomic, assign) BOOL canEdgeScroll;
/**
* 边缘滚动触发范围,默认150,越靠近边缘速度越快
*/
@property (nonatomic, assign) CGFloat edgeScrollRange;
@end
//
// PrepareItemsCell.h
// DreamSleep
//
// Created by peter on 2022/7/16.
//
#import <UIKit/UIKit.h>
#import "ReadyItem.h"
NS_ASSUME_NONNULL_BEGIN
/// 安睡准备选项Cell
@interface PrepareItemsCell : UITableViewCell
@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) ReadyItem *item;
- (void)adjustSelectBtnState;
- (void)adjustSelectBtnOrder:(NSUInteger)order;
@end
NS_ASSUME_NONNULL_END
//
// PrepareItemsCell.m
// DreamSleep
//
// Created by peter on 2022/7/16.
//
#import "PrepareItemsCell.h"
@interface PrepareItemsCell ()
@property (nonatomic, strong) UIImageView *iconIV;
@property (nonatomic, strong) UILabel *itemNameLab;
@property (nonatomic, strong) UILabel *descLab;
@property (nonatomic, strong) UILabel *goodLab;
@end
@implementation PrepareItemsCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = DSClearColor;
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.iconIV];
[self.contentView addSubview:self.itemNameLab];
[self.contentView addSubview:self.descLab];
[self.contentView addSubview:self.goodLab];
[self.contentView addSubview:self.selectBtn];
[self.iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(15);
make.size.mas_equalTo(CGSizeMake(40, 40));
make.centerY.equalTo(self.contentView);
}];
[self.descLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.iconIV.mas_right).offset(12);
make.bottom.equalTo(self.contentView).offset(-15);
}];
[self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView).offset(-20);
make.size.mas_equalTo(CGSizeMake(20, 20));
make.centerY.equalTo(self.contentView);
}];
}
return self;
}
- (void)setItem:(ReadyItem *)item {
_item = item;
[self.iconIV yy_setImageWithURL:[NSURL URLWithString:item.icon] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.itemNameLab.text = item.item_name;
self.descLab.text = item.desc;
self.goodLab.hidden = item.flag_tips ? NO : YES;
self.selectBtn.selected = item.status == 1;
[self adjustSelectBtnState];
[self.itemNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.iconIV.mas_right).offset(12);
make.top.equalTo(self.contentView).offset(15);
}];
[self.goodLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.itemNameLab.mas_right).offset(12);
make.size.mas_equalTo(CGSizeMake(35, 17));
make.centerY.equalTo(self.itemNameLab);
}];
}
- (void)adjustSelectBtnState {
if (self.selectBtn.selected) {
self.selectBtn.dk_backgroundColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
self.selectBtn.layer.borderWidth = 1.0;
self.selectBtn.layer.borderColor = DSClearColor.CGColor;
} else {
[self.selectBtn setTitle:@"" forState:UIControlStateNormal];
self.selectBtn.backgroundColor = DSClearColor;
self.selectBtn.layer.borderWidth = 1.0;
self.selectBtn.layer.dk_borderColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
}
}
- (void)adjustSelectBtnOrder:(NSUInteger)order {
if (order == -1) {
return;
}
[self.selectBtn setTitle:[NSString stringWithFormat:@"%lu", order + 1] forState:UIControlStateNormal];
}
#pragma mark - lazy
- (UIImageView *)iconIV {
if (!_iconIV) {
_iconIV = [UIImageView new];
}
return _iconIV;
}
- (UILabel *)itemNameLab {
if (!_itemNameLab) {
_itemNameLab = [UILabel labWithFont:SysFont(15.0)];
_itemNameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
}
return _itemNameLab;
}
- (UILabel *)descLab {
if (!_descLab) {
_descLab = [UILabel labWithFont:SysFont(12.0)];
_descLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3));
}
return _descLab;
}
- (UILabel *)goodLab {
if (!_goodLab) {
_goodLab = [UILabel labWithText:@"优选" textColor:ColorFromHex(0xFCC21E) font:SysFont(12.0)];
_goodLab.textAlignment = NSTextAlignmentCenter;
[_goodLab cornerRadius:2.0];
_goodLab.backgroundColor = ColorFromHexA(0xFCC21E, .2);;
}
return _goodLab;
}
- (UIButton *)selectBtn {
if (!_selectBtn) {
_selectBtn = [UIButton btnWithTitle:@"" font:SysFont(12.0)];
[_selectBtn cornerRadius:10.0];
[_selectBtn dk_setTitleColorPicker:DKColorPickerWithKey(TabBarBG) forState:UIControlStateSelected];
_selectBtn.userInteractionEnabled = NO;
}
return _selectBtn;
}
@end
......@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *desc;
/// 选项图标
@property (nonatomic, copy) NSString *icon;
/// 状态 1 选择 0 未选中
@property (nonatomic, assign) int status;
@end
NS_ASSUME_NONNULL_END
......@@ -6,15 +6,14 @@
//
#import "ReadyListController.h"
#import "JXMovableCellTableView.h"
#import "SleepReadyRequestModel.h"
#import "RelaxItemsView.h"
#import "ReadyItem.h"
#import "PrepareItemsCell.h"
@interface ReadyListController () <JXMovableCellTableViewDataSource, JXMovableCellTableViewDelegate>
@interface ReadyListController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) RelaxItemsView *relaxItemsView;
@property (nonatomic, strong) JXMovableCellTableView *prepareItemsView;
@property (nonatomic, strong) NSArray *relax_items;
@property (nonatomic, strong) UITableView *prepareItemsView;
@property (nonatomic, strong) NSArray *prepare_items;
@end
......@@ -41,6 +40,7 @@
[self.view addSubview:self.relaxItemsView];
[self.view addSubview:self.prepareItemsView];
[self queryPreparePeaceListRequest];
}
- (void)queryPreparePeaceListRequest {
......@@ -48,10 +48,9 @@
if (requestModel.resCode == DSResCodeSuccess) {
[self.prepareItemsView.mj_header endRefreshing];
self.relax_items = requestModel.relax_items;
self.prepare_items = requestModel.prepare_items;
[self.relaxItemsView adjustRelax:self.relax_items relaxTime:requestModel.relax_time];
[self.relaxItemsView adjustRelax:requestModel.relax_items relaxTime:requestModel.relax_time];
[self.prepareItemsView reloadData];
}
}];
......@@ -68,14 +67,11 @@
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"MoveCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.backgroundColor = DSClearColor;
cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
PrepareItemsCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([PrepareItemsCell class]) forIndexPath:indexPath];
ReadyItem *item = self.prepare_items[indexPath.row];
cell.item = item;
// 根据item_id在已安排好列表中匹配获取下标
[cell adjustSelectBtnOrder:[self getIndex:item.item_id]];
return cell;
}
......@@ -83,32 +79,25 @@
return 70.0;
}
#pragma mark - JXMovableCellTableViewDataSource && JXMovableCellTableViewDelegate
- (NSArray *)dataSourceArrayInTableView:(JXMovableCellTableView *)tableView {
return self.prepare_items.copy;
}
- (void)tableView:(JXMovableCellTableView *)tableView newDataSourceArrayAfterMove:(NSArray *)newDataSourceArray {
self.prepare_items = newDataSourceArray.copy;
}
- (void)tableView:(JXMovableCellTableView *)tableView endMoveCellAtIndexPath:(NSIndexPath *)indexPath {
[self.prepareItemsView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PrepareItemsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
ReadyItem *item = self.prepare_items[indexPath.row];
#warning 模拟业务逻辑
if (indexPath.row == 0) {
// 移除
[self.relaxItemsView removeItem:1];
} else if (indexPath.row == 1) {
// 添加
[self.relaxItemsView addItem:item];
} else if (indexPath.row == 2) {
// 添加
if (cell.selectBtn.selected == NO) {
if (self.relaxItemsView.itemCount >= 3) {
[DSProgressHUD showDetailInfo:@"最多选择3个,请先取消1个"];
return;
}
[self.relaxItemsView addItem:item];
cell.selectBtn.selected = YES;
item.status = 1;
} else {
[self.relaxItemsView removeItem:item.item_id];
cell.selectBtn.selected = NO;
item.status = 0;
}
[cell adjustSelectBtnState];
[self.prepareItemsView reloadData];
}
#pragma mark - lazy
......@@ -119,40 +108,20 @@
return _relaxItemsView;
}
- (JXMovableCellTableView *)prepareItemsView {
- (UITableView *)prepareItemsView {
if (!_prepareItemsView) {
_prepareItemsView = [[JXMovableCellTableView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.relaxItemsView.frame) + 15, kScreenWidth - 30, kScreenHeight - self.dsNaviBar.height - self.relaxItemsView.height - 30 - 24 - Bottom_SafeArea_Height) style:UITableViewStylePlain];
_prepareItemsView = [[UITableView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(self.relaxItemsView.frame) + 15, kScreenWidth - 30, kScreenHeight - self.dsNaviBar.height - self.relaxItemsView.height - 30 - 24 - Bottom_SafeArea_Height) style:UITableViewStylePlain];
_prepareItemsView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_prepareItemsView cornerRadius:24.0];
_prepareItemsView.showsVerticalScrollIndicator = NO;
_prepareItemsView.separatorStyle = UITableViewCellSeparatorStyleNone;
_prepareItemsView.dataSource = self;
_prepareItemsView.delegate = self;
_prepareItemsView.gestureMinimumPressDuration = 1.0;
_prepareItemsView.drawMovalbeCellBlock = ^(UIView *movableCell) {
movableCell.layer.shadowColor = [UIColor grayColor].CGColor;
movableCell.layer.masksToBounds = NO;
movableCell.layer.cornerRadius = 0;
movableCell.layer.shadowOffset = CGSizeMake(-5, 0);
movableCell.layer.shadowOpacity = 0.4;
movableCell.layer.shadowRadius = 5;
};
WS(weakSelf);
_prepareItemsView.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
[weakSelf queryPreparePeaceListRequest];
}];
[_prepareItemsView.mj_header beginRefreshing];
[_prepareItemsView registerClass:[PrepareItemsCell class] forCellReuseIdentifier:NSStringFromClass([PrepareItemsCell class])];
}
return _prepareItemsView;
}
- (NSArray *)relax_items {
if (!_relax_items) {
_relax_items = [NSArray array];
}
return _relax_items;
}
- (NSArray *)prepare_items {
if (!_prepare_items) {
_prepare_items = [NSArray array];
......@@ -160,4 +129,25 @@
return _prepare_items;
}
#pragma mark - others
- (NSUInteger)getIndex:(int)itemID {
NSArray *relax_items = self.relaxItemsView.has_relax_items;
__block NSUInteger index = -1;
[relax_items enumerateObjectsUsingBlock:^(ReadyItem * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (itemID == obj.item_id) {
*stop = YES;
index = idx;
}
}];
return index;
}
- (void)backAction {
[SleepReadyRequestModel userSetupPrepareItems:self.relaxItemsView.has_relax_items completion:^(SleepReadyRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[super backAction];
}
}];
}
@end
......@@ -12,6 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
@interface RelaxItemsView : UIView
@property (nonatomic, assign) NSUInteger itemCount;
@property (nonatomic, strong, readonly) NSArray *has_relax_items;
/// 重置任务
/// @param relax_items relax_items
/// @param relax_time 放松总时长
......
......@@ -171,15 +171,18 @@
[self.timeWidths addObject:@(0)];
[self.itemCells addObject:itemCell];
ReadyTimeMarker *marker = [[ReadyTimeMarker alloc] initWithFrame:CGRectMake(0, _topMargin, _markerW, self.height - _topMargin - _markerBottomMargin)];
marker.delegate = self;
[self addSubview:marker];
[self.markers addObject:marker];
// 重新计算timeWidth,取平均值
NSUInteger itemsCount = self.relax_items.count;
CGFloat divideTimeW = _lineW / itemsCount;
CGFloat divideTime = _relax_time / itemsCount;
CGFloat divideTimeW = _lineW / itemsCount;
if (itemsCount > 1) {
ReadyTimeMarker *marker = [[ReadyTimeMarker alloc] initWithFrame:CGRectMake(0, _topMargin, _markerW, self.height - _topMargin - _markerBottomMargin)];
marker.delegate = self;
[self addSubview:marker];
[self.markers addObject:marker];
}
// 重新计算timeWidth,取平均值
for (int index = 0; index < itemsCount; index++) {
self.timeWidths[index] = @(divideTimeW);
ReadyItem *item = self.relax_items[index];
......@@ -198,6 +201,8 @@
}];
}
ReadyItemCell *itemCell = self.itemCells[index];
itemCell.item.time = divideTime;
[itemCell adjustTime];
[UIView animateWithDuration:.3 animations:^{
itemCell.centerX = self->_lineMargin + timeW/2.0 + leftAllTimeW2;
}];
......@@ -321,4 +326,12 @@
return _lineMargin + self.divideW - _markerW/2.0;
}
- (NSUInteger)itemCount {
return self.relax_items.count;
}
- (NSArray *)has_relax_items {
return [self.relax_items copy];
}
@end
......@@ -18,6 +18,18 @@ NS_ASSUME_NONNULL_BEGIN
/// @param completion completion
+ (NSURLSessionDataTask *)queryPreparePeaceListWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion;
/// 用户设置睡前选项接口
/// @param relaxItems 调整后的睡前准备列表
/// @param completion completion
+ (NSURLSessionDataTask *)userSetupPrepareItems:(NSArray *)relaxItems completion:(void (^)(SleepReadyRequestModel *requestModel))completion;
/// 做完安睡准备更新状态接口
/// @param completion completion
+ (NSURLSessionDataTask *)userSetupPreparePeaceStatusWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion;
/// 获取开始睡前准备数据的接口
/// @param completion completion
+ (NSURLSessionDataTask *)userPrepareSleepItemsWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -9,7 +9,7 @@
#import "ReadyItem.h"
@implementation SleepReadyRequestModel
// user_setup_prepare_items、user_setup_prepare_peace_status
+ (NSURLSessionDataTask *)queryPreparePeaceListWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion {
SleepReadyRequestModel * requestModel = [[SleepReadyRequestModel alloc] init];
NSString *api = @"query_prepare_peace_list";
......@@ -21,7 +21,7 @@
requestModel.relax_time = [resultDic[@"relax_time"] intValue];
NSArray *relax_items = resultDic[@"relax_items"];
NSArray *prepare_items = resultDic[@"prepare_items"];
NSMutableArray *tmp_relax_items = [NSMutableArray array];
for (int i = 0; i < relax_items.count; i++) {
ReadyItem *readyItem = [ReadyItem yy_modelWithJSON:relax_items[i]];
......@@ -43,4 +43,56 @@
}];
}
+ (NSURLSessionDataTask *)userSetupPrepareItems:(NSArray *)relaxItems completion:(void (^)(SleepReadyRequestModel *requestModel))completion {
SleepReadyRequestModel * requestModel = [[SleepReadyRequestModel alloc] init];
NSString *api = @"user_setup_prepare_items";
NSMutableString *mStr = [NSMutableString string];
[mStr appendString:@"\"["];
for (int index = 0; index < relaxItems.count; index++) {
ReadyItem *item = relaxItems[index];
[mStr appendFormat:@"{item_id:%d,time:%d}%@", item.item_id, item.time, (index == relaxItems.count - 1) ? @"" : @","];
}
[mStr appendString:@"]\""];
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(relax_items:%@)}", api, [mStr copy]];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"用户设置睡前选项接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
+ (NSURLSessionDataTask *)userSetupPreparePeaceStatusWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion {
SleepReadyRequestModel * requestModel = [[SleepReadyRequestModel alloc] init];
NSString *api = @"user_setup_prepare_peace_status";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@}", api];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"做完安睡准备更新状态接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
+ (NSURLSessionDataTask *)userPrepareSleepItemsWithCompletion:(void (^)(SleepReadyRequestModel *requestModel))completion {
SleepReadyRequestModel * requestModel = [[SleepReadyRequestModel alloc] init];
NSString *api = @"user_prepare_sleep_items";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@}", api];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"获取开始睡前准备数据的接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
@end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!