Commit 03525e60 cgx

梳理业务逻辑

1 个父辈 4ff6808d
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#import "ThreeMinuteController.h" #import "ThreeMinuteController.h"
#import "UserRequestModel.h" #import "UserRequestModel.h"
@interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, DsWebControllerDelegate> @interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, DsWebControllerDelegate, RelaxTrainControllerDelegate>
@property (strong, nonatomic) WKWebView *aiWebView; @property (strong, nonatomic) WKWebView *aiWebView;
@property (strong, nonatomic) NSMutableURLRequest *request; @property (strong, nonatomic) NSMutableURLRequest *request;
@property (strong, nonatomic) UIProgressView *progressView; @property (strong, nonatomic) UIProgressView *progressView;
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
} }
} }
#pragma mark - DsWebControllerDelegate #pragma mark - DsWebControllerDelegate && RelaxTrainControllerDelegate
- (void)reloadAIPage { - (void)reloadAIPage {
[self.aiWebView reload]; [self.aiWebView reload];
} }
...@@ -171,6 +171,7 @@ ...@@ -171,6 +171,7 @@
case 5: // 练习腹式呼吸法 case 5: // 练习腹式呼吸法
{ {
RelaxTrainController *relaxVC = [RelaxTrainController new]; RelaxTrainController *relaxVC = [RelaxTrainController new];
relaxVC.refreshDelegate = self;
[self.navigationController pushViewController:relaxVC animated:YES]; [self.navigationController pushViewController:relaxVC animated:YES];
} }
break; break;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "RelaxTrainModel.h" #import "RelaxTrainModel.h"
#import <FSAudioController.h> #import <FSAudioController.h>
#import "RelaxTrainCell.h" #import "RelaxTrainCell.h"
#import "RelaxTrainRequestModel.h"
@interface RelaxBodyView () <UIGestureRecognizerDelegate, UICollectionViewDelegate, UICollectionViewDataSource> @interface RelaxBodyView () <UIGestureRecognizerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UIButton *playerBtn; @property (nonatomic, strong) UIButton *playerBtn;
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
@property (nonatomic, strong) UICollectionView *relaxCollectionView; @property (nonatomic, strong) UICollectionView *relaxCollectionView;
@property (nonatomic, strong) NSArray *relaxList; @property (nonatomic, strong) NSArray *relaxList;
@property (nonatomic, assign) NSInteger curIndex; @property (nonatomic, assign) NSInteger curIndex;
@property (nonatomic, assign) BOOL isUpdateTask;
@end @end
@implementation RelaxBodyView { @implementation RelaxBodyView {
...@@ -103,7 +105,7 @@ ...@@ -103,7 +105,7 @@
} }
- (void)playControlAction:(UIButton *)sender { - (void)playControlAction:(UIButton *)sender {
if (self.streamState == kFsAudioStreamStopped) { if (self.streamState == kFsAudioStreamStopped || self.streamState == kFsAudioStreamRetrievingURL) {
[self.audioStream play]; [self.audioStream play];
} else if (self.streamState == kFsAudioStreamPlaying) { } else if (self.streamState == kFsAudioStreamPlaying) {
// 暂停播放 // 暂停播放
...@@ -144,15 +146,7 @@ ...@@ -144,15 +146,7 @@
if (listArr.count && index < listArr.count) { if (listArr.count && index < listArr.count) {
self.curIndex = index; self.curIndex = index;
RelaxTrainModel *relaxModel = listArr[index]; RelaxTrainModel *relaxModel = listArr[index];
[self refreshTopData:relaxModel]; [self refreshTopData:relaxModel isStartPlay:NO];
// self.titleLab.text = relaxModel.audio_name;
// NSString *audio_desc = [[NSString stringWithFormat:@"%@", relaxModel.audio_desc] stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
// self.tipsLab.height = [NSString getHeightWithText:audio_desc withFont:SysFont(14.0) withMaxWidth:kScreenWidth - 30];
// self.tipsLab.text = audio_desc;
//
// // 不是正在播放的状态需要先停止
// if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; }
// [self.audioStream playFromURL:[NSURL URLWithString:relaxModel.audio_url]];
self.relaxList = listArr; self.relaxList = listArr;
[self.relaxCollectionView reloadData]; [self.relaxCollectionView reloadData];
...@@ -166,7 +160,7 @@ ...@@ -166,7 +160,7 @@
[self.audioStream stop]; [self.audioStream stop];
} }
- (void)refreshTopData:(RelaxTrainModel *)relaxModel { - (void)refreshTopData:(RelaxTrainModel *)relaxModel isStartPlay:(BOOL)isStartPlay {
if (self.delegate && [self.delegate respondsToSelector:@selector(updateNaviTitleAndBgImg:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(updateNaviTitleAndBgImg:)]) {
[self.delegate updateNaviTitleAndBgImg:relaxModel]; [self.delegate updateNaviTitleAndBgImg:relaxModel];
} }
...@@ -178,7 +172,8 @@ ...@@ -178,7 +172,8 @@
// 不是正在播放的状态需要先停止 // 不是正在播放的状态需要先停止
if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; } if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; }
[self.audioStream playFromURL:[NSURL URLWithString:relaxModel.audio_url]]; self.audioStream.url = [NSURL URLWithString:relaxModel.audio_url];
if (isStartPlay) { [self.audioStream play]; }
} }
#pragma mark - UIGestureRecognizerDelegate #pragma mark - UIGestureRecognizerDelegate
...@@ -224,7 +219,7 @@ ...@@ -224,7 +219,7 @@
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RelaxTrainCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([RelaxTrainCell class]) forIndexPath:indexPath]; RelaxTrainCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([RelaxTrainCell class]) forIndexPath:indexPath];
cell.trainModel = self.relaxList[indexPath.row]; [cell updateRelaxCell:self.relaxList[indexPath.row] isShowPlayIcon:(self.curIndex == indexPath.row)];
return cell; return cell;
} }
...@@ -234,7 +229,8 @@ ...@@ -234,7 +229,8 @@
} }
self.curIndex = indexPath.row; self.curIndex = indexPath.row;
RelaxTrainModel *relaxModel = [self.relaxList objectAtIndex:indexPath.row]; RelaxTrainModel *relaxModel = [self.relaxList objectAtIndex:indexPath.row];
[self refreshTopData:relaxModel]; [self refreshTopData:relaxModel isStartPlay:YES];
[self.relaxCollectionView reloadData];
} }
#pragma mark - lazy #pragma mark - lazy
...@@ -337,6 +333,17 @@ ...@@ -337,6 +333,17 @@
case kFsAudioStreamPlaying: case kFsAudioStreamPlaying:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
DSLog(@"播放ing..."); DSLog(@"播放ing...");
// 更新腹式呼吸放松法任务状态
if (weakSelf.isUpdateTask == NO) {
#warning - 需要梳理业务逻辑
[RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
weakSelf.isUpdateTask = YES;
}
}];
}
break; break;
case kFsAudioStreamFailed: case kFsAudioStreamFailed:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
......
...@@ -12,7 +12,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -12,7 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 放松训练音频cell /// 放松训练音频cell
@interface RelaxTrainCell : UICollectionViewCell @interface RelaxTrainCell : UICollectionViewCell
@property (nonatomic, strong) RelaxTrainModel *trainModel;
- (void)updateRelaxCell:(RelaxTrainModel *)trainModel isShowPlayIcon:(BOOL)isShowPlayIcon;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -14,20 +14,22 @@ ...@@ -14,20 +14,22 @@
@property (nonatomic, strong) UILabel *audioNameLab; @property (nonatomic, strong) UILabel *audioNameLab;
@property (nonatomic, strong) UIImageView *recIcon; @property (nonatomic, strong) UIImageView *recIcon;
@property (nonatomic, strong) UILabel *recLab; @property (nonatomic, strong) UILabel *recLab;
@property (nonatomic, strong) UIImageView *playIcon;
@end @end
@implementation RelaxTrainCell @implementation RelaxTrainCell
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) { if (self = [super initWithFrame:frame]) {
[self addSubview:self.homeIV]; [self.contentView addSubview:self.homeIV];
[self addSubview:self.audioNameLab]; [self.contentView addSubview:self.audioNameLab];
[self addSubview:self.recIcon]; [self.contentView addSubview:self.recIcon];
[self addSubview:self.recLab]; [self.contentView addSubview:self.recLab];
[self.contentView addSubview:self.playIcon];
[self.homeIV mas_makeConstraints:^(MASConstraintMaker *make) { [self.homeIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView); make.top.equalTo(self.contentView);
make.left.equalTo(self); make.left.equalTo(self.contentView);
make.width.height.equalTo(@(120)); make.width.height.equalTo(@(120));
}]; }];
[self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) { [self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
...@@ -41,16 +43,19 @@ ...@@ -41,16 +43,19 @@
[self.recLab mas_makeConstraints:^(MASConstraintMaker *make) { [self.recLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.recIcon); make.left.top.right.equalTo(self.recIcon);
}]; }];
[self.playIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.homeIV);
}];
} }
return self; return self;
} }
- (void)setTrainModel:(RelaxTrainModel *)trainModel { - (void)updateRelaxCell:(RelaxTrainModel *)trainModel isShowPlayIcon:(BOOL)isShowPlayIcon {
_trainModel = trainModel;
[self.homeIV yy_setImageWithURL:[NSURL URLWithString:trainModel.bg_url] placeholder:[UIImage imageNamed:@"basicPlaceholder"]]; [self.homeIV yy_setImageWithURL:[NSURL URLWithString:trainModel.bg_url] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.audioNameLab.text = trainModel.audio_name; self.audioNameLab.text = trainModel.audio_name;
self.recIcon.hidden = [trainModel.is_recommend isEqualToString:@"0"]; self.recIcon.hidden = [trainModel.is_recommend isEqualToString:@"0"];
self.recLab.hidden = [trainModel.is_recommend isEqualToString:@"0"]; self.recLab.hidden = [trainModel.is_recommend isEqualToString:@"0"];
self.playIcon.hidden = !isShowPlayIcon;
} }
#pragma mark - lazy #pragma mark - lazy
...@@ -87,4 +92,11 @@ ...@@ -87,4 +92,11 @@
return _recLab; return _recLab;
} }
- (UIImageView *)playIcon {
if (!_playIcon) {
_playIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"relax_play_show"]];
}
return _playIcon;
}
@end @end
...@@ -9,9 +9,14 @@ ...@@ -9,9 +9,14 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@protocol RelaxTrainControllerDelegate <NSObject>
/// 刷新AI睡眠教练页面
- (void)reloadAIPage;
@end
/// 放松训练、腹式呼吸法页面 /// 放松训练、腹式呼吸法页面
@interface RelaxTrainController : DSBaseViewController @interface RelaxTrainController : DSBaseViewController
@property (nonatomic, weak) id<RelaxTrainControllerDelegate> refreshDelegate;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -53,17 +53,15 @@ ...@@ -53,17 +53,15 @@
} }
} }
}]; }];
#warning - 需要梳理业务逻辑
[RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
}];
} }
#pragma mark - Actions #pragma mark - Actions
- (void)backAction { - (void)backAction {
[super backAction]; [super backAction];
[self.bodyView stopAudio]; [self.bodyView stopAudio];
if (self.refreshDelegate && [self.refreshDelegate respondsToSelector:@selector(reloadAIPage)]) {
[self.refreshDelegate reloadAIPage];
}
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
......
...@@ -180,7 +180,7 @@ ...@@ -180,7 +180,7 @@
break; break;
case 2: // 播放暂停 case 2: // 播放暂停
{ {
if (self.streamState == kFsAudioStreamStopped) { if (self.streamState == kFsAudioStreamStopped || self.streamState == kFsAudioStreamRetrievingURL) {
[self.audioStream play]; [self.audioStream play];
} else if (self.streamState == kFsAudioStreamPlaying) { } else if (self.streamState == kFsAudioStreamPlaying) {
// 暂停播放 // 暂停播放
...@@ -237,7 +237,7 @@ ...@@ -237,7 +237,7 @@
// 点击当前传过来音频 // 点击当前传过来音频
if (self.currentIndex == index) { if (self.currentIndex == index) {
if (self.streamState == kFsAudioStreamStopped) { if (self.streamState == kFsAudioStreamStopped || self.streamState == kFsAudioStreamRetrievingURL) {
[self.audioStream play]; [self.audioStream play];
} else if (self.streamState == kFsAudioStreamPaused) { } else if (self.streamState == kFsAudioStreamPaused) {
// 恢复播放 // 恢复播放
......
{
"images" : [
{
"filename" : "relax_play_show.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "relax_play_show@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "relax_play_show@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!