Commit 42e0760a cgx

优化登录功能模块,基本完成安睡准备

1 个父辈 9f14c2c5
正在显示 46 个修改的文件 包含 299 行增加81 行删除
......@@ -798,6 +798,66 @@
name = Frameworks;
sourceTree = "<group>";
};
D008476A28865D850085A92B /* Controller */ = {
isa = PBXGroup;
children = (
D02D0825287BBEDE005C3A00 /* SleepReadyController.h */,
D02D0826287BBEDE005C3A00 /* SleepReadyController.m */,
D02D082B287BD05D005C3A00 /* ReadyListController.h */,
D02D082C287BD05D005C3A00 /* ReadyListController.m */,
);
path = Controller;
sourceTree = "<group>";
};
D008476B28865D920085A92B /* View */ = {
isa = PBXGroup;
children = (
D02D0828287BCEF3005C3A00 /* SRTipsView.h */,
D02D0829287BCEF3005C3A00 /* SRTipsView.m */,
D0691E00287FB330008BFFAB /* XLCircle.h */,
D0691DFE287FB330008BFFAB /* XLCircle.m */,
D0691DFD287FB330008BFFAB /* XLCircleProgress.h */,
D0691DFF287FB330008BFFAB /* XLCircleProgress.m */,
D043A8BD287ECB7100226176 /* StartReadyView.h */,
D043A8BE287ECB7100226176 /* StartReadyView.m */,
D024CE87287D59FF00FB4320 /* SRMusicView.h */,
D024CE88287D59FF00FB4320 /* SRMusicView.m */,
D043A8B4287EBA4000226176 /* ReadyItemView.h */,
D043A8B5287EBA4000226176 /* ReadyItemView.m */,
D0691E0C288009D3008BFFAB /* ReadyItemCell.h */,
D0691E0D288009D3008BFFAB /* ReadyItemCell.m */,
D0691E1228801EF3008BFFAB /* ReadyTimeMarker.h */,
D0691E1328801EF3008BFFAB /* ReadyTimeMarker.m */,
D0691E0F28801D43008BFFAB /* RelaxItemsView.h */,
D0691E1028801D43008BFFAB /* RelaxItemsView.m */,
D02E85862882A594002DAD7E /* PrepareItemsCell.h */,
D02E85872882A594002DAD7E /* PrepareItemsCell.m */,
D0FEE7CF28854967006C2B67 /* SleepReadyDoneView.h */,
D0FEE7D028854967006C2B67 /* SleepReadyDoneView.m */,
);
path = View;
sourceTree = "<group>";
};
D008476C28865DAE0085A92B /* RequestModel */ = {
isa = PBXGroup;
children = (
D0691E03287FEA04008BFFAB /* SleepReadyRequestModel.h */,
D0691E04287FEA04008BFFAB /* SleepReadyRequestModel.m */,
);
path = RequestModel;
sourceTree = "<group>";
};
D008476D28865DC60085A92B /* Model */ = {
isa = PBXGroup;
children = (
D0691E09287FFB54008BFFAB /* ReadyItem.h */,
D0691E0A287FFB54008BFFAB /* ReadyItem.m */,
D0FEE7D228855483006C2B67 /* SRFinishModel.h */,
D0FEE7D328855483006C2B67 /* SRFinishModel.m */,
);
path = Model;
sourceTree = "<group>";
};
D013CD1628582C1900F920B4 /* UMSDK */ = {
isa = PBXGroup;
children = (
......@@ -1059,38 +1119,10 @@
D02D0824287BBE9A005C3A00 /* SleepReady */ = {
isa = PBXGroup;
children = (
D02D0825287BBEDE005C3A00 /* SleepReadyController.h */,
D02D0826287BBEDE005C3A00 /* SleepReadyController.m */,
D02D082B287BD05D005C3A00 /* ReadyListController.h */,
D02D082C287BD05D005C3A00 /* ReadyListController.m */,
D0691E09287FFB54008BFFAB /* ReadyItem.h */,
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 */,
D02D0828287BCEF3005C3A00 /* SRTipsView.h */,
D02D0829287BCEF3005C3A00 /* SRTipsView.m */,
D024CE87287D59FF00FB4320 /* SRMusicView.h */,
D024CE88287D59FF00FB4320 /* SRMusicView.m */,
D043A8BD287ECB7100226176 /* StartReadyView.h */,
D043A8BE287ECB7100226176 /* StartReadyView.m */,
D043A8B4287EBA4000226176 /* ReadyItemView.h */,
D043A8B5287EBA4000226176 /* ReadyItemView.m */,
D0691E00287FB330008BFFAB /* XLCircle.h */,
D0691DFE287FB330008BFFAB /* XLCircle.m */,
D0691DFD287FB330008BFFAB /* XLCircleProgress.h */,
D0691DFF287FB330008BFFAB /* XLCircleProgress.m */,
D0691E03287FEA04008BFFAB /* SleepReadyRequestModel.h */,
D0691E04287FEA04008BFFAB /* SleepReadyRequestModel.m */,
D0FEE7CF28854967006C2B67 /* SleepReadyDoneView.h */,
D0FEE7D028854967006C2B67 /* SleepReadyDoneView.m */,
D0FEE7D228855483006C2B67 /* SRFinishModel.h */,
D0FEE7D328855483006C2B67 /* SRFinishModel.m */,
D008476B28865D920085A92B /* View */,
D008476D28865DC60085A92B /* Model */,
D008476A28865D850085A92B /* Controller */,
D008476C28865DAE0085A92B /* RequestModel */,
);
path = SleepReady;
sourceTree = "<group>";
......
......@@ -74,7 +74,7 @@
[self.aiWebView loadRequest:self.request];
}
#pragma mark - DsWebControllerDelegate && RelaxTrainControllerDelegate
#pragma mark - DsWebControllerDelegate && RelaxTrainControllerDelegate && SleepReadyControllerDelegate
- (void)reloadAIPage {
[self.aiWebView reload];
}
......@@ -102,6 +102,11 @@
if ([url isEqualToString:AICoachURL]) {
decisionHandler(WKNavigationActionPolicyAllow);
} else if ([url isEqualToString:[NSString stringWithFormat:@"%@/%@", ServerURL, @"sleep/ssmian/sleep_prepare"]]) {
// 拦截安睡准备
SleepReadyController *srVC = [SleepReadyController new];
[self.navigationController pushViewController:srVC animated:YES];
decisionHandler(WKNavigationActionPolicyCancel);
} else {
// 开启新的webview页面加载
DsWebController *newWebVC = [[DsWebController alloc] initWithLink:url isShowNavi:NO];
......@@ -177,7 +182,7 @@
int type = [bodyDic[@"type"] intValue];
DSLog(@"bodyDic:%@", bodyDic);
switch (type) {
case 1: // 未登录点击开启
case 1: // 跳到登录页面(服务端检查到session过期或用户退出登录后访问需要登录的页面时会触发,不是立即触发)
{
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
......@@ -199,13 +204,9 @@
break;
case 3: // 轻拍哄睡
{
// UnityGameController *gameVC = [UnityGameController new];
// gameVC.gameType = GameTypeCoax;
// [self.navigationController pushViewController:gameVC animated:YES];
#warning - 临时测试
SleepReadyController *srVC = [SleepReadyController new];
[self.navigationController pushViewController:srVC animated:YES];
UnityGameController *gameVC = [UnityGameController new];
gameVC.gameType = GameTypeCoax;
[self.navigationController pushViewController:gameVC animated:YES];
}
break;
case 4: // 安心记事本
......@@ -227,6 +228,13 @@
[self.navigationController pushViewController:srVC animated:YES];
}
break;
case 7: // 跳转到登录页面(未注册或注销后在AI睡眠教练里点击开启跳转到登录页面)
{
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self isAccess:YES];
}
}
break;
default:
break;
}
......
......@@ -6,6 +6,7 @@
//
#import "DSBaseViewController.h"
#import "SRFinishModel.h"
NS_ASSUME_NONNULL_BEGIN
......@@ -19,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id<RelaxTrainControllerDelegate> refreshDelegate;
/// title和step参数
@property (nonatomic, strong) NSDictionary *params;
/// 安睡准备完成后传递过来的数据
@property (nonatomic, strong) SRFinishModel *finishModel;
@end
NS_ASSUME_NONNULL_END
......@@ -8,13 +8,16 @@
#import "RelaxTrainController.h"
#import "RelaxTrainRequestModel.h"
#import "RelaxBodyView.h"
#import "SleepReadyDoneView.h"
#import "UnityGameController.h"
@interface RelaxTrainController () <RelaxBodyViewDelegate, UIScrollViewDelegate>
@interface RelaxTrainController () <RelaxBodyViewDelegate, UIScrollViewDelegate, SleepReadyDoneViewDelegate>
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UILabel *cusTitleLab;
@property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) UIScrollView *lucencyView;
@property (nonatomic, strong) RelaxBodyView *bodyView;
@property (nonatomic, strong) SleepReadyDoneView *srDoneAlertView;
@end
@implementation RelaxTrainController
......@@ -65,6 +68,9 @@
#pragma mark - 根据title匹配下标索引
- (NSInteger)getIndexWithListData:(NSArray *)listData {
__block NSInteger currentIndex = 0;
if (!self.params) {
return currentIndex;
}
NSString *title = self.params[@"title"];
// 放松音频随机选一个
if ([title isEqualToString:@"练习放松训练"]) {
......@@ -97,6 +103,12 @@
self.titleLab.text = trainModel.audio_name;
}
- (void)showScoreAlertView {
SRFinishModel *finishModel = self.finishModel;
finishModel.isCoax = YES;
[self.srDoneAlertView showSleepReadyFinishView:finishModel];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloat offset = scrollView.contentOffset.y;
......@@ -116,6 +128,29 @@
}
}
#pragma mark - SleepReadyDoneViewDelegate
- (void)enterDiffModule:(SRFinishAlertType)type {
if (type == SRFinishAlertTypeNormal) {
// 返回AI睡眠教练
[self.navigationController popToRootViewControllerAnimated:YES];
} else if (type == SRFinishAlertTypeCoax) {
// 进入轻拍哄睡
UnityGameController *gameVC = [UnityGameController new];
gameVC.gameType = GameTypeCoax;
[self.navigationController pushViewController:gameVC animated:YES];
// 移除放松训练页面
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcs enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[RelaxTrainController class]]) {
*stop = YES;
[vcs removeObject:obj];
}
}];
self.navigationController.viewControllers = [vcs copy];
}
}
#pragma mark - lazy
- (UIImageView *)bgIV {
if (!_bgIV) {
......@@ -156,11 +191,20 @@
if (!_bodyView) {
_bodyView = [[RelaxBodyView alloc] initWithFrame:CGRectMake(0, 351, kScreenWidth, 420 + Bottom_SafeArea_Height)];
_bodyView.delegate = self;
_bodyView.isSleepReady = self.finishModel ? YES : NO;
_bodyView.updateParams = self.params;
}
return _bodyView;
}
- (SleepReadyDoneView *)srDoneAlertView {
if (!_srDoneAlertView) {
_srDoneAlertView = [[SleepReadyDoneView alloc] init];
_srDoneAlertView.delegate = self;
}
return _srDoneAlertView;
}
#pragma mark - 设置状态栏文字颜色(重写父类)
- (UIStatusBarStyle)preferredStatusBarStyle {
if (self.isNeedUpdateStatusBarStyle) {
......@@ -169,4 +213,11 @@
return UIStatusBarStyleDefault;
}
#pragma mark - setter
- (void)setFinishModel:(SRFinishModel *)finishModel {
_finishModel = finishModel;
NSDictionary *task_relax = finishModel.task_relax;
self.params = @{@"title":task_relax[@"title"], @"step":task_relax[@"step"]};
}
@end
......@@ -21,8 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 睡眠-AI教练任务更新操作步骤接口
/// @param params @{@"title":xxx, @"step":xxx}
/// @param isReady YES:安睡准备进入的,NO:AI睡眠进入的
/// @param completion completion
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params completion:(void (^)(RelaxTrainRequestModel *requestModel))completion;
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params isReady:(BOOL)isReady completion:(void (^)(RelaxTrainRequestModel *requestModel))completion;
@end
NS_ASSUME_NONNULL_END
......@@ -31,12 +31,15 @@
}];
}
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params completion:(void (^)(RelaxTrainRequestModel *requestModel))completion {
+ (NSURLSessionDataTask *)userCurTaskStateWithParams:(NSDictionary *)params isReady:(BOOL)isReady completion:(void (^)(RelaxTrainRequestModel *requestModel))completion {
RelaxTrainRequestModel * requestModel = [[RelaxTrainRequestModel alloc] init];
NSString *api = @"user_cur_task_state";
NSString *title = params[@"title"];
int step = [params[@"step"] intValue];
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(title:\"%@\",step:%d)}", api, title, step];
if (isReady) {
argStr = [NSString stringWithFormat:@"mutation{%@(title:\"%@\",step:%d,is_receive:true)}", api, title, step];
}
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:YES success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"睡眠-AI教练任务更新操作步骤接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
......
......@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@protocol RelaxBodyViewDelegate <NSObject>
- (void)updateNaviTitleAndBgImg:(RelaxTrainModel *)trainModel;
/// 显示安睡准备进入后播放完成积分弹框
- (void)showScoreAlertView;
@end
/// 放松body主视图
......@@ -24,6 +26,9 @@ NS_ASSUME_NONNULL_BEGIN
/// title和step参数
@property (nonatomic, strong) NSDictionary *updateParams;
/// 是否是安睡准备跳转过来的标识
@property (nonatomic, assign) BOOL isSleepReady;
/// 页面退出时停止音频播放
- (void)stopAudio;
......
......@@ -28,6 +28,7 @@
@property (nonatomic, strong) NSArray *relaxList;
@property (nonatomic, assign) NSInteger curIndex;
@property (nonatomic, assign) BOOL isUpdateTask;
@property (nonatomic, assign) BOOL isShowScoreAlert;
@end
@implementation RelaxBodyView {
......@@ -338,7 +339,7 @@
// 更新腹式呼吸放松法任务状态
@synchronized (weakSelf) {
if (weakSelf.isUpdateTask == NO) {
[RelaxTrainRequestModel userCurTaskStateWithParams:weakSelf.updateParams completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
[RelaxTrainRequestModel userCurTaskStateWithParams:weakSelf.updateParams isReady:weakSelf.isSleepReady completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
weakSelf.isUpdateTask = YES;
}
......@@ -352,6 +353,16 @@
DSLog(@"音频文件加载失败");
break;
case kFsAudioStreamPlaybackCompleted:
DSLog(@"放松音频播放完成");
// 回调只弹1次从安睡准备进来任务完成弹框
if (weakSelf.isSleepReady) {
if (weakSelf.isShowScoreAlert == NO) {
weakSelf.isShowScoreAlert = YES;
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(showScoreAlertView)]) {
[weakSelf.delegate showScoreAlertView];
}
}
}
break;
case kFsAudioStreamRetryingStarted:
DSLog(@"回放失败");
......
......@@ -13,6 +13,7 @@
#import "SRMusicView.h"
#import "StartReadyView.h"
#import "ReadyItemView.h"
#import "RelaxTrainController.h"
@interface SleepReadyController () <ReadyListControllerDelegate, StartReadyViewDelegate, ReadyItemViewDelegate>
@property (nonatomic, strong) UIButton *tipsBtn;
......@@ -81,6 +82,28 @@
self.naviTitle = itemName;
}
- (void)dealFinishAlert:(SRFinishAlertType)type finishModel:(SRFinishModel *)finishModel {
if (type == SRFinishAlertTypeNormal) {
[self.navigationController popToRootViewControllerAnimated:YES];
} else if (type == SRFinishAlertTypeRelax) {
RelaxTrainController *relaxVC = [RelaxTrainController new];
relaxVC.finishModel = finishModel;
[self.navigationController pushViewController:relaxVC animated:YES];
// 移除安睡准备页面
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[vcs enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[SleepReadyController class]]) {
*stop = YES;
[vcs removeObject:obj];
}
}];
self.navigationController.viewControllers = [vcs copy];
}
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
}
#pragma mark - UI
- (void)buildUI {
self.naviTitle = @"睡前准备";
......
......@@ -9,6 +9,12 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, SRFinishAlertType) {
SRFinishAlertTypeNormal, // 普通类型,完成弹框仅显示【返回AI睡眠教练按钮】
SRFinishAlertTypeRelax, // 进入放松训练,完成弹框显示【进入放松训练】和"返回AI睡眠教练"按钮
SRFinishAlertTypeCoax, // 进入哄睡,放松训练完成弹框显示【轻拍哄睡】和"返回AI睡眠教练"按钮
};
/// 睡前准备完成更新状态数据model
@interface SRFinishModel : NSObject
@property (nonatomic, copy) NSString *word;
......@@ -18,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) int integral;
/// 是否进入放松训练标记 true 进入 false 返回 AI教练
@property (nonatomic, assign) int flag_relax;
/// 是否进入哄睡标识
@property (nonatomic, assign) BOOL isCoax;
@end
NS_ASSUME_NONNULL_END
......@@ -6,6 +6,7 @@
//
#import <UIKit/UIKit.h>
#import "SRFinishModel.h"
NS_ASSUME_NONNULL_BEGIN
......@@ -13,6 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
/// 更新导航栏title
/// @param itemName 当前任务项名称
- (void)curItemName:(NSString *)itemName;
/// 安睡准备完成弹框回调
/// @param type 类型
/// @param finishModel 完成数据model
- (void)dealFinishAlert:(SRFinishAlertType)type finishModel:(SRFinishModel *)finishModel;
@end
/// 睡前准备任务视图
......
......@@ -12,7 +12,7 @@
#import "SleepReadyRequestModel.h"
#import "SleepReadyDoneView.h"
@interface ReadyItemView ()
@interface ReadyItemView () <SleepReadyDoneViewDelegate>
@property (nonatomic, strong) XLCircleProgress *circleProgress;
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UIButton *enterBtn;
......@@ -109,13 +109,23 @@
#pragma mark - 提前结束或者任务倒计时结束调用做完安睡准备更新状态接口
- (void)updateUserSetupPreparePeaceStatusRequest {
[DSProgressHUD showProgressHUDWithInfo:@""];
[SleepReadyRequestModel userSetupPreparePeaceStatusWithCompletion:^(SleepReadyRequestModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
[self.circleProgress stopTimer];
[self.srDoneAlertView showSleepReadyFinishView:requestModel.finishModel];
}
}];
}
#pragma mark - SleepReadyDoneViewDelegate
- (void)enterDiffModule:(SRFinishAlertType)type {
if (self.delegate && [self.delegate respondsToSelector:@selector(dealFinishAlert:finishModel:)]) {
[self.delegate dealFinishAlert:type finishModel:self.srDoneAlertView.finishModel];
}
}
#pragma mark - lazy
- (XLCircleProgress *)circleProgress {
if (!_circleProgress) {
......@@ -154,6 +164,7 @@
- (SleepReadyDoneView *)srDoneAlertView {
if (!_srDoneAlertView) {
_srDoneAlertView = [[SleepReadyDoneView alloc] init];
_srDoneAlertView.delegate = self;
}
return _srDoneAlertView;
}
......
......@@ -10,15 +10,19 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, SRFinishAlertType) {
SRFinishAlertTypeNormal, // 普通类型,完成弹框仅显示【返回AI睡眠教练按钮】
SRFinishAlertTypeRelax, // 进入放松训练,完成弹框显示【进入放松训练】和"返回AI睡眠教练"按钮
SRFinishAlertTypeCoax, // 进入哄睡,放松训练完成弹框显示【轻拍哄睡】和"返回AI睡眠教练"按钮
};
@protocol SleepReadyDoneViewDelegate <NSObject>
/// 根据type进入不同的模块
/// @param type type
- (void)enterDiffModule:(SRFinishAlertType)type;
@end
/// 睡前准备任务完成后提示框
@interface SleepReadyDoneView : UIView
@property (nonatomic, weak) id<SleepReadyDoneViewDelegate> delegate;
@property (nonatomic, strong) SRFinishModel *finishModel;
- (void)showSleepReadyFinishView:(SRFinishModel *)model;
@end
......
......@@ -14,6 +14,7 @@
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UIButton *bgColorBtn;
@property (nonatomic, strong) UIButton *retBtn;
@property (nonatomic, assign) SRFinishAlertType alertType;
@end
@implementation SleepReadyDoneView
......@@ -22,11 +23,6 @@
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];
......@@ -41,39 +37,53 @@
- (void)showSleepReadyFinishView:(SRFinishModel *)model {
[DSKeyWindow addSubview:self];
_finishModel = model;
SRFinishAlertType type = SRFinishAlertTypeNormal;
CGFloat alertH = 252;
if (model) {
if (model.flag_relax == 1) {
type = SRFinishAlertTypeRelax;
type = model.isCoax ? SRFinishAlertTypeCoax : 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.alertType = type;
if (type == SRFinishAlertTypeCoax) {
[self.bgColorBtn setTitle:@"轻拍哄睡" forState:UIControlStateNormal];
NSString *leftStr = @"恭喜您已获得今日睡眠计划";
NSString *rightStr = [NSString stringWithFormat:@"%d积分", model.integral];
NSString *titleStr = [NSString stringWithFormat:@"%@%@", leftStr, rightStr];
NSMutableAttributedString *title_attText = [[NSMutableAttributedString alloc] initWithString:titleStr];
UIColor *dkColor1 = [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? MainTextColor : DkTitleColor;
UIColor *dkColor2 = [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? BrandColor : SubNaviDarkColor;
[title_attText addAttribute:NSForegroundColorAttributeName value:dkColor1 range:NSMakeRange(0, leftStr.length)];
[title_attText addAttribute:NSForegroundColorAttributeName value:dkColor2 range:NSMakeRange(leftStr.length, rightStr.length)];
self.titleLab.attributedText = title_attText;
self.detailLab.text = @"接下来,请上床,使用轻拍哄睡帮你快速入";
} else {
if (type == SRFinishAlertTypeNormal) {
self.retBtn.hidden = YES;
[self.bgColorBtn setTitle:@"返回AI睡眠教练" forState:UIControlStateNormal];
} else if (type == SRFinishAlertTypeRelax) {
[self.bgColorBtn setTitle:@"进入放松训练" forState:UIControlStateNormal];
}
self.titleLab.text = model.word;
self.detailLab.text = model.tips;
}
self.titleLab.text = model.word;
self.detailLab.text = model.tips;
self.alertView.frame = CGRectMake(0, kScreenHeight - alertH, kScreenWidth, alertH);
[self.alertView setCornerRadiusRect:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:24.0];
[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);
make.centerY.equalTo(self.celebrateIV);
make.centerX.equalTo(self.alertView).offset(29/2.0);
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.titleLab.mas_bottom).offset(24);
......@@ -91,7 +101,6 @@
make.centerX.equalTo(self.alertView);
make.size.mas_equalTo(CGSizeMake(120, 22));
}];
[self layoutIfNeeded];
}
- (void)dismissSleepReadyFinishView {
......@@ -101,9 +110,8 @@
#pragma mark - lazy
- (UIView *)alertView {
if (!_alertView) {
_alertView = [[UIView alloc] initWithFrame:CGRectZero];
_alertView = [UIView new];
_alertView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_alertView setCornerRadiusRect:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:24.0];
}
return _alertView;
}
......@@ -135,12 +143,16 @@
- (UIButton *)bgColorBtn {
if (!_bgColorBtn) {
WS(weakSelf);
_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) {
[weakSelf dismissSleepReadyFinishView];
if (weakSelf.delegate && [self.delegate respondsToSelector:@selector(enterDiffModule:)]) {
[weakSelf.delegate enterDiffModule:weakSelf.alertType];
}
}];
}
return _bgColorBtn;
......@@ -148,10 +160,14 @@
- (UIButton *)retBtn {
if (!_retBtn) {
WS(weakSelf);
_retBtn = [UIButton btnWithTitle:@"返回AI睡眠教练" font:SysFont(16.0)];
[_retBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite) forState:UIControlStateNormal];
[_retBtn addTouchUpInsideHandler:^(NSInteger tag) {
[weakSelf dismissSleepReadyFinishView];
if (weakSelf.delegate && [self.delegate respondsToSelector:@selector(enterDiffModule:)]) {
[weakSelf.delegate enterDiffModule:SRFinishAlertTypeNormal];
}
}];
}
return _retBtn;
......
......@@ -16,4 +16,6 @@ typedef void (^ProgressFinishBlock)(BOOL isAuto);
@property (copy, nonatomic) ProgressFinishBlock progressFinishBlock;
- (void)fireWithTime:(int)time;
- (void)stopTimer;
@end
......@@ -35,6 +35,10 @@
[_timer setFireDate:[NSDate date]];
}
- (void)stopTimer {
[_timer setFireDate:[NSDate distantFuture]];
}
- (void)dealloc {
[_timer invalidate];
_timer = nil;
......
......@@ -13,6 +13,12 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^LoginSuccessBlock)(void);
@interface LoginController : UIViewController
/*
is_access为YES表示:
未注册或注销后在AI睡眠教练里点击开启跳转到登录页面,
调用微信或者apple登录接口需要传is_access = true参数
*/
@property (nonatomic, assign) BOOL isAccess;
@property (nonatomic, copy) LoginSuccessBlock successBlock;
@end
......
......@@ -42,7 +42,7 @@
- (void)wxLoginAuth:(NSNotification *)noti {
NSString *code = noti.object;
// 发送微信登录请求
[UserRequestModel wxLoginWithCode:code completion:^(UserRequestModel * _Nonnull requestModel) {
[UserRequestModel wxLoginWithCode:code isAccess:self.isAccess completion:^(UserRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"登录成功"];
if (self.successBlock) {self.successBlock(); }
......@@ -94,6 +94,8 @@
[controller performRequests];
[DataStatisticsUtil event:Apple_Login attributes:@{@"name":@"发起苹果登录"}];
} else {
[DSProgressHUD showDetailInfo:@"当前设备系统不支持Apple登录,请升级系统!"];
}
}
break;
......@@ -130,7 +132,7 @@
DSLog(@"ios登陆成功:userID: %@\n,authorizationCode: %@\n,identityToken: %@", userID, authorizationCode, identityToken);
// 发送苹果登录请求
[UserRequestModel appleLoginWithUser:userID identityToken:identityToken authorizationCode:authorizationCode completion:^(UserRequestModel * _Nonnull requestModel) {
[UserRequestModel appleLoginWithUser:userID identityToken:identityToken authorizationCode:authorizationCode isAccess:self.isAccess completion:^(UserRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"登录成功"];
if (self.successBlock) {self.successBlock(); }
......
......@@ -56,6 +56,11 @@ NS_ASSUME_NONNULL_BEGIN
/// @param target 入口控制器
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target;
/// 跳转到登录模块
/// @param target 入口控制器
/// @param isAccess 单独处理参数
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target isAccess:(BOOL)isAccess;
/// 跳转到登录模块,并且登录成功后发送消息给入口控制器
/// @param target 入口控制器
/// @param sel 消息
......
......@@ -99,6 +99,15 @@
}
}
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target isAccess:(BOOL)isAccess {
if (target && [target isKindOfClass:[UIViewController class]]) {
LoginController *loginVC = [[LoginController alloc] init];
loginVC.isAccess = isAccess;
BaseNaviController *navi = [[BaseNaviController alloc] initWithRootViewController:loginVC];
[target presentViewController:navi animated:YES completion:nil];
}
}
+ (void)jumpToLoginControllerWithTarget:(UIViewController *)target selector:(SEL)sel {
if (target && [target isKindOfClass:[UIViewController class]]) {
LoginController *loginVC = [[LoginController alloc] init];
......
......@@ -16,13 +16,15 @@ NS_ASSUME_NONNULL_BEGIN
/// 微信登录请求
/// @param code 客户端微信授权用户code
/// @param isAccess isAccess
/// @param completion completion
+ (NSURLSessionDataTask *)wxLoginWithCode:(NSString *)code completion:(void (^)(UserRequestModel *requestModel))completion;
+ (NSURLSessionDataTask *)wxLoginWithCode:(NSString *)code isAccess:(BOOL)isAccess completion:(void (^)(UserRequestModel *requestModel))completion;
/// 苹果登录请求
+ (NSURLSessionDataTask *)appleLoginWithUser:(NSString *)user
identityToken:(NSString *)identityToken
authorizationCode:(NSString *)authorizationCode
isAccess:(BOOL)isAccess
completion:(void (^)(UserRequestModel *requestModel))completion;
/// 用户退出登录接口
......
......@@ -9,10 +9,13 @@
@implementation UserRequestModel
+ (NSURLSessionDataTask *)wxLoginWithCode:(NSString *)code completion:(void (^)(UserRequestModel *requestModel))completion {
+ (NSURLSessionDataTask *)wxLoginWithCode:(NSString *)code isAccess:(BOOL)isAccess completion:(void (^)(UserRequestModel *requestModel))completion {
UserRequestModel * requestModel = [[UserRequestModel alloc] init];
NSString *api = @"wxLogin";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(code:\"%@\")}", api, code];
if (isAccess) {
argStr = [NSString stringWithFormat:@"mutation{%@(code:\"%@\",is_access:true)}", api, code];
}
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;
......@@ -32,11 +35,15 @@
+ (NSURLSessionDataTask *)appleLoginWithUser:(NSString *)user
identityToken:(NSString *)identityToken
authorizationCode:(NSString *)authorizationCode
isAccess:(BOOL)isAccess
completion:(void (^)(UserRequestModel *requestModel))completion
{
UserRequestModel * requestModel = [[UserRequestModel alloc] init];
NSString *api = @"verify_sign_with_appleid";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(user_id:\"%@\",identity_token:\"%@\",authorization_code:\"%@\")}", api, user, identityToken, authorizationCode];
if (isAccess) {
argStr = [NSString stringWithFormat:@"mutation{%@(user_id:\"%@\",identity_token:\"%@\",authorization_code:\"%@\",is_access:true)}", api, user, identityToken, authorizationCode];
}
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;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!