Commit 9f14c2c5 cgx

初步完成安睡准备

1 个父辈 e848ee29
正在显示 22 个修改的文件 包含 592 行增加25 行删除
......@@ -254,6 +254,8 @@
D0FAC425281B817D00D4B859 /* GKPhotoBrowser.bundle in Resources */ = {isa = PBXBuildFile; fileRef = D0FAC41B281B817D00D4B859 /* GKPhotoBrowser.bundle */; };
D0FAC429281B865300D4B859 /* GKYYWebImageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FAC427281B865300D4B859 /* GKYYWebImageManager.m */; };
D0FAC662281BAACB00D4B859 /* YYAnimationImageView+Fix.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FAC661281BAACB00D4B859 /* YYAnimationImageView+Fix.m */; };
D0FEE7D128854967006C2B67 /* SleepReadyDoneView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FEE7D028854967006C2B67 /* SleepReadyDoneView.m */; };
D0FEE7D428855483006C2B67 /* SRFinishModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0FEE7D328855483006C2B67 /* SRFinishModel.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -752,6 +754,10 @@
D0FAC660281BAACB00D4B859 /* YYAnimationImageView+Fix.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "YYAnimationImageView+Fix.h"; sourceTree = "<group>"; };
D0FAC661281BAACB00D4B859 /* YYAnimationImageView+Fix.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "YYAnimationImageView+Fix.m"; sourceTree = "<group>"; };
D0FAC663281BB55C00D4B859 /* CGGeometry+RSKImageCropper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CGGeometry+RSKImageCropper.h"; sourceTree = "<group>"; };
D0FEE7CF28854967006C2B67 /* SleepReadyDoneView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SleepReadyDoneView.h; sourceTree = "<group>"; };
D0FEE7D028854967006C2B67 /* SleepReadyDoneView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SleepReadyDoneView.m; sourceTree = "<group>"; };
D0FEE7D228855483006C2B67 /* SRFinishModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SRFinishModel.h; sourceTree = "<group>"; };
D0FEE7D328855483006C2B67 /* SRFinishModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SRFinishModel.m; sourceTree = "<group>"; };
D0FFCD402853421900A01707 /* UnityFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UnityFramework.framework; path = unity_build_framework/UnityFramework.framework; sourceTree = "<group>"; };
F02C34A5649294F60932630C /* Pods-DreamSleep.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DreamSleep.release.xcconfig"; path = "Target Support Files/Pods-DreamSleep/Pods-DreamSleep.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
......@@ -1081,6 +1087,10 @@
D0691DFF287FB330008BFFAB /* XLCircleProgress.m */,
D0691E03287FEA04008BFFAB /* SleepReadyRequestModel.h */,
D0691E04287FEA04008BFFAB /* SleepReadyRequestModel.m */,
D0FEE7CF28854967006C2B67 /* SleepReadyDoneView.h */,
D0FEE7D028854967006C2B67 /* SleepReadyDoneView.m */,
D0FEE7D228855483006C2B67 /* SRFinishModel.h */,
D0FEE7D328855483006C2B67 /* SRFinishModel.m */,
);
path = SleepReady;
sourceTree = "<group>";
......@@ -2183,6 +2193,7 @@
files = (
D037C49D284F5DE8000F3089 /* TaskPointSrollView.m in Sources */,
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D0FEE7D128854967006C2B67 /* SleepReadyDoneView.m in Sources */,
D043DD58285B25EE0043A4CE /* VersionRequestModel.m in Sources */,
D07257F3286BF99F0080F458 /* DailyTaskView.m in Sources */,
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */,
......@@ -2218,6 +2229,7 @@
D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */,
D0D96FE22848493700461839 /* RelaxTrainModel.m in Sources */,
D0B5ECB727F2D9E0003EDFE3 /* main.m in Sources */,
D0FEE7D428855483006C2B67 /* SRFinishModel.m in Sources */,
D0691E1128801D43008BFFAB /* RelaxItemsView.m in Sources */,
D0BE53742845B27E007F15B3 /* DailyTaskModel.m in Sources */,
D07DACA62810557D0067A1BF /* RSKTouchView.m in Sources */,
......
......@@ -9,10 +9,20 @@
NS_ASSUME_NONNULL_BEGIN
@protocol ReadyItemViewDelegate <NSObject>
/// 更新导航栏title
/// @param itemName 当前任务项名称
- (void)curItemName:(NSString *)itemName;
@end
/// 睡前准备任务视图
@interface ReadyItemView : UIView
- (void)start;
@property (nonatomic, weak) id<ReadyItemViewDelegate> delegate;
/// 点击开始仪式进入任务页面
/// @param items 所有任务项
- (void)startWithItems:(NSArray *)items;
@end
......
......@@ -8,11 +8,17 @@
#import "ReadyItemView.h"
#import "XLCircleProgress.h"
#import "RingingTools.h"
#import "ReadyItem.h"
#import "SleepReadyRequestModel.h"
#import "SleepReadyDoneView.h"
@interface ReadyItemView ()
@property (nonatomic, strong) XLCircleProgress *circleProgress;
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UIButton *enterBtn;
@property (nonatomic, strong) NSArray *items;
@property (nonatomic, assign) NSInteger curIndex;
@property (nonatomic, strong) SleepReadyDoneView *srDoneAlertView;
@end
@implementation ReadyItemView
......@@ -21,6 +27,8 @@
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
self.hidden = YES;
self.items = [NSArray array];
[self addSubview:self.bgIV];
[self addSubview:self.circleProgress];
[self addSubview:self.enterBtn];
......@@ -28,6 +36,7 @@
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self).offset(-34);
make.width.height.equalTo(self.mas_width);
}];
[self.enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(155, 40));
......@@ -38,17 +47,84 @@
return self;
}
- (void)start {
#pragma mark - public
- (void)startWithItems:(NSArray *)items {
self.hidden = NO;
self.items = items;
self.curIndex = 0;
[self dealStartNextItem:NO];
}
#pragma mark - Actions
- (void)nextOrEndAction {
if (self.enterBtn.selected) {
// 提前结束
[self updateUserSetupPreparePeaceStatusRequest];
} else {
// 手动点击进入下一项
[self dealStartNextItem:NO];
}
}
#pragma mark - 手动点击提前结束或者任务倒计时结束
- (void)dealStartNextItem:(BOOL)isAuto {
if (isAuto == NO) {
[self displayItemView];
}
// 判断是否是最后一个任务
if (self.curIndex == self.items.count - 1) {
self.enterBtn.selected = YES;
if (isAuto) {
[self updateUserSetupPreparePeaceStatusRequest];
}
} else {
if (isAuto) {
[self displayItemView];
}
self.curIndex++;
}
}
#pragma mark - 展示当前任务
- (void)displayItemView {
ReadyItem *item = self.items[self.curIndex];
[RingingTools playRingingWithName:@"sleep_ready_transit"];
[self.circleProgress fire];
[self.circleProgress fireWithTime:item.time];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *day_img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:item.bg_day]]];
UIImage *night_img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:item.bg_night]]];
dispatch_async(dispatch_get_main_queue(), ^{
[self.bgIV dk_setImagePicker:DKImagePickerWithImages(day_img, night_img, day_img)];
});
});
if (self.delegate && [self.delegate respondsToSelector:@selector(curItemName:)]) {
[self.delegate curItemName:item.item_name];
}
}
#pragma mark - 提前结束或者任务倒计时结束调用做完安睡准备更新状态接口
- (void)updateUserSetupPreparePeaceStatusRequest {
[SleepReadyRequestModel userSetupPreparePeaceStatusWithCompletion:^(SleepReadyRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[self.srDoneAlertView showSleepReadyFinishView:requestModel.finishModel];
}
}];
}
#pragma mark - lazy
- (XLCircleProgress *)circleProgress {
if (!_circleProgress) {
WS(weakSelf);
_circleProgress = [[XLCircleProgress alloc] initWithFrame:CGRectMake(0, 158, 200, 200)];
_circleProgress.centerX = self.centerX;
_circleProgress.progressFinishBlock = ^(BOOL isAuto) {
[weakSelf dealStartNextItem:isAuto];
};
}
return _circleProgress;
}
......@@ -56,7 +132,6 @@
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [UIImageView new];
[_bgIV dk_setImagePicker:DKImagePickerWithNames(@"ai_anshui_xizao", @"dk_ai_anshui_xizao", @"ai_anshui_xizao")];
}
return _bgIV;
}
......@@ -65,14 +140,22 @@
if (!_enterBtn) {
WS(weakSelf);
_enterBtn = [UIButton btnWithTitle:@"进入下一项" font:BoldFont(16.0)];
[_enterBtn setTitle:@"提前结束" forState:UIControlStateSelected];
[_enterBtn cornerRadius:20.0];
[_enterBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
[_enterBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_enterBtn addTouchUpInsideHandler:^(NSInteger tag) {
[weakSelf nextOrEndAction];
}];
}
return _enterBtn;
}
- (SleepReadyDoneView *)srDoneAlertView {
if (!_srDoneAlertView) {
_srDoneAlertView = [[SleepReadyDoneView alloc] init];
}
return _srDoneAlertView;
}
@end
......@@ -9,7 +9,9 @@
NS_ASSUME_NONNULL_BEGIN
@protocol ReadyListControllerDelegate <NSObject>
/// 将调整好的睡前准备项传递到上一个页面
/// @param items items
- (void)passAdjustedReadyItems:(NSArray *)items;
@end
/// 睡前准备设置列表页
......
......@@ -145,6 +145,10 @@
- (void)backAction {
[SleepReadyRequestModel userSetupPrepareItems:self.relaxItemsView.has_relax_items completion:^(SleepReadyRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
if (self.delegate && [self.delegate respondsToSelector:@selector(passAdjustedReadyItems:)]) {
[self.delegate passAdjustedReadyItems:self.relaxItemsView.has_relax_items];
}
[super backAction];
}
}];
......
......@@ -7,9 +7,6 @@
#import "ReadyTimeMarker.h"
@interface ReadyTimeMarker ()
@end
@implementation ReadyTimeMarker
- (instancetype)initWithFrame:(CGRect)frame {
......@@ -45,7 +42,7 @@
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if (self.delegate && [self.delegate respondsToSelector:@selector(touchesBeganWithMarker:)]) {
[self.delegate touchesBeganWithMarker:self];
}
}
}
- (void)panAction:(UIPanGestureRecognizer *)panGR {
......
......@@ -64,10 +64,11 @@
#pragma mark - public
- (void)adjustRelax:(NSArray *)relax_items relaxTime:(int)relax_time {
if (self.relax_items.count || relax_time <= 0) {
_relax_time = relax_time;
if (relax_items.count == 0 || relax_time <= 0) {
return;
}
_relax_time = relax_time;
[self.relax_items addObjectsFromArray:relax_items];
for (int index = 0; index < self.relax_items.count; index++) {
......
//
// SRFinishModel.h
// DreamSleep
//
// Created by peter on 2022/7/18.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 睡前准备完成更新状态数据model
@interface SRFinishModel : NSObject
@property (nonatomic, copy) NSString *word;
@property (nonatomic, copy) NSString *tips;
/// 用于更新放松训练任务参数
@property (nonatomic, strong) NSDictionary *task_relax;
@property (nonatomic, assign) int integral;
/// 是否进入放松训练标记 true 进入 false 返回 AI教练
@property (nonatomic, assign) int flag_relax;
@end
NS_ASSUME_NONNULL_END
//
// SRFinishModel.m
// DreamSleep
//
// Created by peter on 2022/7/18.
//
#import "SRFinishModel.h"
@implementation SRFinishModel
@end
......@@ -14,7 +14,7 @@
#import "StartReadyView.h"
#import "ReadyItemView.h"
@interface SleepReadyController () <ReadyListControllerDelegate, StartReadyViewDelegate>
@interface SleepReadyController () <ReadyListControllerDelegate, StartReadyViewDelegate, ReadyItemViewDelegate>
@property (nonatomic, strong) UIButton *tipsBtn;
@property (nonatomic, strong) UIButton *setBtn;
@property (nonatomic, strong) SRTipsView *sRTipsView;
......@@ -22,6 +22,7 @@
@property (nonatomic, strong) ReadyItemView *readyItemView;
@property (nonatomic, strong) UIButton *musicBtn;
@property (nonatomic, strong) SRMusicView *musicView;
@property (nonatomic, strong) NSArray *adjustedItems;
@end
@implementation SleepReadyController
......@@ -54,14 +55,30 @@
}
#pragma mark - ReadyListControllerDelegate
- (void)passAdjustedReadyItems:(NSArray *)items {
if (items && items.count) {
self.adjustedItems = items;
[self.startReadyView updateAdjustView:self.adjustedItems];
}
}
#pragma mark - StartReadyViewDelegate
- (void)startTask {
if (self.adjustedItems.count == 0) {
// 准备页面点击开始仪式如果没有任务则直接进入列表设置页面
ReadyListController *setListVC = [[ReadyListController alloc] initWithDelegate:self];
[self.navigationController pushViewController:setListVC animated:YES];
return;
}
self.tipsBtn.hidden = YES;
self.setBtn.hidden = YES;
self.startReadyView.hidden = YES;
[self.readyItemView start];
self.naviTitle = @"洗澡";
[self.readyItemView startWithItems:self.adjustedItems];
}
#pragma mark - ReadyItemViewDelegate
- (void)curItemName:(NSString *)itemName {
self.naviTitle = itemName;
}
#pragma mark - UI
......@@ -154,6 +171,7 @@
- (ReadyItemView *)readyItemView {
if (!_readyItemView) {
_readyItemView = [ReadyItemView new];
_readyItemView.delegate = self;
}
return _readyItemView;
}
......@@ -177,4 +195,11 @@
return _musicView;
}
- (NSArray *)adjustedItems {
if (!_adjustedItems) {
_adjustedItems = [NSArray array];
}
return _adjustedItems;
}
@end
//
// SleepReadyDoneView.h
// DreamSleep
//
// Created by peter on 2022/7/18.
//
#import <UIKit/UIKit.h>
#import "SRFinishModel.h"
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, SRFinishAlertType) {
SRFinishAlertTypeNormal, // 普通类型,完成弹框仅显示【返回AI睡眠教练按钮】
SRFinishAlertTypeRelax, // 进入放松训练,完成弹框显示【进入放松训练】和"返回AI睡眠教练"按钮
SRFinishAlertTypeCoax, // 进入哄睡,放松训练完成弹框显示【轻拍哄睡】和"返回AI睡眠教练"按钮
};
/// 睡前准备任务完成后提示框
@interface SleepReadyDoneView : UIView
- (void)showSleepReadyFinishView:(SRFinishModel *)model;
@end
NS_ASSUME_NONNULL_END
//
// SleepReadyDoneView.m
// DreamSleep
//
// Created by peter on 2022/7/18.
//
#import "SleepReadyDoneView.h"
@interface SleepReadyDoneView ()
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) UIImageView *celebrateIV;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UIButton *bgColorBtn;
@property (nonatomic, strong) UIButton *retBtn;
@end
@implementation SleepReadyDoneView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0x6F7587), DSClearColor, DSWhite);
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissSleepReadyFinishView)];
[self addGestureRecognizer:tapGR];
[self debugViewShowBorder];
[self addSubview:self.alertView];
[self.alertView addSubview:self.celebrateIV];
[self.alertView addSubview:self.titleLab];
[self.alertView addSubview:self.detailLab];
[self.alertView addSubview:self.bgColorBtn];
[self.alertView addSubview:self.retBtn];
}
return self;
}
- (void)showSleepReadyFinishView:(SRFinishModel *)model {
[DSKeyWindow addSubview:self];
SRFinishAlertType type = SRFinishAlertTypeNormal;
CGFloat alertH = 252;
if (model) {
if (model.flag_relax == 1) {
type = SRFinishAlertTypeRelax;
alertH = 282;
}
} else {
type = SRFinishAlertTypeCoax;
alertH = 282;
}
if (type == SRFinishAlertTypeNormal) {
self.retBtn.hidden = YES;
[self.bgColorBtn setTitle:@"返回AI睡眠教练" forState:UIControlStateNormal];
} else if (type == SRFinishAlertTypeRelax) {
[self.bgColorBtn setTitle:@"进入放松训练" forState:UIControlStateNormal];
} else if (type == SRFinishAlertTypeCoax) {
[self.bgColorBtn setTitle:@"轻拍哄睡" forState:UIControlStateNormal];
}
self.titleLab.text = model.word;
self.detailLab.text = model.tips;
self.alertView.frame = CGRectMake(0, kScreenHeight - alertH, kScreenWidth, alertH);
[self.celebrateIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.alertView).offset(26);
make.width.height.equalTo(@20);
make.right.equalTo(self.titleLab.mas_left).offset(-9);
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.alertView).offset(24);
make.centerX.equalTo(self.alertView).offset(29);
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLab.mas_bottom).offset(24);
make.centerX.equalTo(self.alertView);
make.left.equalTo(self.alertView).offset(5);
make.right.equalTo(self.alertView).offset(-5);
}];
[self.bgColorBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.detailLab.mas_bottom).offset(48);
make.centerX.equalTo(self.alertView);
make.size.mas_equalTo(CGSizeMake(155, 40));
}];
[self.retBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.alertView).offset(-58);
make.centerX.equalTo(self.alertView);
make.size.mas_equalTo(CGSizeMake(120, 22));
}];
[self layoutIfNeeded];
}
- (void)dismissSleepReadyFinishView {
[self removeFromSuperview];
}
#pragma mark - lazy
- (UIView *)alertView {
if (!_alertView) {
_alertView = [[UIView alloc] initWithFrame:CGRectZero];
_alertView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_alertView setCornerRadiusRect:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:24.0];
}
return _alertView;
}
- (UIImageView *)celebrateIV {
if (!_celebrateIV) {
_celebrateIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"celebrate"]];
}
return _celebrateIV;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel labWithFont:BoldFont(16.0)];
_titleLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
_titleLab.textAlignment = NSTextAlignmentCenter;
}
return _titleLab;
}
- (UILabel *)detailLab {
if (!_detailLab) {
_detailLab = [UILabel labWithFont:SysFont(14.0)];
_detailLab.textAlignment = NSTextAlignmentCenter;
_detailLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
}
return _detailLab;
}
- (UIButton *)bgColorBtn {
if (!_bgColorBtn) {
_bgColorBtn = [UIButton btnWithTitle:@"" font:BoldFont(16.0)];
[_bgColorBtn cornerRadius:20.0];
[_bgColorBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
[_bgColorBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_bgColorBtn addTouchUpInsideHandler:^(NSInteger tag) {
}];
}
return _bgColorBtn;
}
- (UIButton *)retBtn {
if (!_retBtn) {
_retBtn = [UIButton btnWithTitle:@"返回AI睡眠教练" font:SysFont(16.0)];
[_retBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite) forState:UIControlStateNormal];
[_retBtn addTouchUpInsideHandler:^(NSInteger tag) {
}];
}
return _retBtn;
}
@end
......@@ -6,13 +6,19 @@
//
#import "DSNetworkTool.h"
#import "SRFinishModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface SleepReadyRequestModel : DSNetworkTool
/// 任务总时长
@property (nonatomic, assign) int relax_time;
/// 睡前规划任务项数据
@property (nonatomic, strong) NSArray *relax_items;
/// 睡前所有任务列表数据
@property (nonatomic, strong) NSArray *prepare_items;
/// 完成睡前准备后返回的数据
@property (nonatomic, strong) SRFinishModel *finishModel;
/// 安睡准备设置页面列表数据
/// @param completion completion
......
......@@ -50,7 +50,7 @@
[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 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]];
......@@ -72,6 +72,9 @@
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;
NSDictionary *resultDic = apiDic[@"result"];
SRFinishModel *finishModel = [SRFinishModel yy_modelWithDictionary:resultDic];
requestModel.finishModel = finishModel;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
......
......@@ -10,6 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
@protocol StartReadyViewDelegate <NSObject>
/// 点击开始仪式回调
- (void)startTask;
@end
......@@ -20,6 +21,10 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithDelegate:(id<StartReadyViewDelegate>)delegate;
/// 更新调整后的任务视图
/// @param adjustedItems adjustedItems
- (void)updateAdjustView:(NSArray *)adjustedItems;
@end
NS_ASSUME_NONNULL_END
......@@ -6,10 +6,125 @@
//
#import "StartReadyView.h"
#import "ReadyItem.h"
@interface LineView : UIView
@end
@implementation LineView
- (instancetype)initWithFrame:(CGRect)frame {
if (self == [super initWithFrame:frame]) {
UILabel *lineLab = [UILabel labWithText:@"- - - - - - - - - - - - - - - -" font:SysFont(10) fit:YES];
lineLab.lineBreakMode = NSLineBreakByClipping;
lineLab.dk_textColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[self addSubview:lineLab];
UIView *circle = [UIView new];
circle.layer.borderWidth = 1.0;
circle.layer.dk_borderColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[circle cornerRadius:3.0];
[self addSubview:circle];
UIView *center = [UIView new];
[center cornerRadius:1.0];
center.dk_backgroundColorPicker = DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite);
[self addSubview:center];
[lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self);
make.right.equalTo(circle.mas_left);
}];
[circle mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@6.0);
make.top.bottom.right.equalTo(self);
}];
[center mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@2.0);
make.center.equalTo(circle);
}];
}
return self;
}
@end
@interface ItemCell : UIView
@property (nonatomic, strong) ReadyItem *item;
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@end
@implementation ItemCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self addSubview:self.icon];
[self addSubview:self.nameLab];
[self addSubview:self.timeLab];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self);
make.centerX.equalTo(self);
make.width.height.equalTo(@40);
}];
[self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.icon.mas_bottom).offset(16);
make.centerX.equalTo(self);
make.left.equalTo(self).offset(1);
make.right.equalTo(self).offset(-1);
}];
[self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.bottom.equalTo(self);
make.left.equalTo(self).offset(2);
make.right.equalTo(self).offset(-2);
}];
}
return self;
}
- (void)setItem:(ReadyItem *)item {
_item = item;
[self.icon yy_setImageWithURL:[NSURL URLWithString:item.icon] options:YYWebImageOptionShowNetworkActivity];
self.nameLab.text = item.item_name;
self.timeLab.text = [NSString stringWithFormat:@"%dmin", item.time];
}
- (UIImageView *)icon {
if (!_icon) {
_icon = [UIImageView new];
}
return _icon;
}
- (UILabel *)nameLab {
if (!_nameLab) {
_nameLab = [UILabel labWithFont:BoldFont(14.0)];
_nameLab.textAlignment = NSTextAlignmentCenter;
_nameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
}
return _nameLab;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(12.0)];
_timeLab.textAlignment = NSTextAlignmentCenter;
_timeLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .3));
}
return _timeLab;
}
@end
@interface StartReadyView ()
@property (nonatomic, strong) UIImageView *headIV;
@property (nonatomic, strong) UIButton *startBtn;
@property (nonatomic, strong) NSArray *adjustedItems;
@property (nonatomic, strong) NSMutableArray *adjustedCells;
@property (nonatomic, strong) NSMutableArray *sepLines;
@end
@implementation StartReadyView
......@@ -17,10 +132,14 @@
- (instancetype)initWithDelegate:(id<StartReadyViewDelegate>)delegate {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
_delegate = delegate;
self.adjustedItems = [NSArray array];
self.adjustedCells = [NSMutableArray array];
self.sepLines = [NSMutableArray array];
[self addSubview:self.headIV];
[self addSubview:self.startBtn];
[self.headIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self);
}];
......@@ -33,6 +152,51 @@
return self;
}
- (void)updateAdjustView:(NSArray *)adjustedItems {
// 移除所有cell
for (ItemCell *cell in self.adjustedCells) {
[cell removeFromSuperview];
}
[self.adjustedCells removeAllObjects];
// 移除所有分割线
for (LineView *lineV in self.sepLines) {
[lineV removeFromSuperview];
}
[self.sepLines removeAllObjects];
// 新建所有cell和分割线
self.adjustedItems = [adjustedItems copy];
CGFloat itemH = 102;
CGFloat y = 310;
CGFloat left_right_margin = 30;
CGFloat itemW = (self.width - 2*left_right_margin)/adjustedItems.count;
for (int index = 0; index < adjustedItems.count; index++) {
ItemCell *cell = [[ItemCell alloc] initWithFrame:CGRectMake(left_right_margin + index*itemW, y, itemW, itemH)];
cell.item = adjustedItems[index];
[self addSubview:cell];
[self.adjustedCells addObject:cell];
}
if (adjustedItems.count > 1) { // 至少是2个cell
for (int index = 0; index < adjustedItems.count - 1; index++) {
ItemCell *leftCell = self.adjustedCells[index > 0 ? index : 0];
ItemCell *rightCell = self.adjustedCells[index + 1];
LineView *lineView = [LineView new];
[self addSubview:lineView];
[self.sepLines addObject:lineView];
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(leftCell.icon.mas_right).offset(0);
make.right.equalTo(rightCell.icon.mas_left).offset(0);
make.height.equalTo(@6);
make.centerY.equalTo(leftCell.icon);
}];
}
}
}
#pragma mark - lazy
- (UIImageView *)headIV {
if (!_headIV) {
......
......@@ -8,9 +8,12 @@
#import <UIKit/UIKit.h>
typedef void (^ProgressFinishBlock)(BOOL isAuto);
@interface XLCircleProgress : UIView
// 百分比
@property (assign,nonatomic) float progress;
- (void)fire;
/// 任务倒计时结束回调
@property (copy, nonatomic) ProgressFinishBlock progressFinishBlock;
- (void)fireWithTime:(int)time;
@end
......@@ -9,6 +9,10 @@
#import "XLCircleProgress.h"
#import "XLCircle.h"
@interface XLCircleProgress ()
@property (assign, nonatomic) float progress;
@end
@implementation XLCircleProgress {
UIImageView *_dialplateIV;
XLCircle* _circle;
......@@ -25,7 +29,9 @@
return self;
}
- (void)fire {
- (void)fireWithTime:(int)time {
_countTime = time * 60;
_totalTime = _countTime;
[_timer setFireDate:[NSDate date]];
}
......@@ -62,11 +68,13 @@
}
- (void)dealTimerTask {
// 任务完成
// 当前任务完成
if (_countTime == 0) {
[_timer setFireDate:[NSDate distantFuture]];
// 下一任务
// 进入下一任务
if (self.progressFinishBlock) {
self.progressFinishBlock(YES);
}
return;
}
_countTime--;
......
{
"images" : [
{
"filename" : "celebrate.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "celebrate@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "celebrate@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!