Commit 03525e60 cgx

梳理业务逻辑

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