Commit c9f76e02 cgx

完成白噪音数据同步

1 个父辈 848187e6
正在显示 20 个修改的文件 包含 195 行增加126 行删除
...@@ -38,11 +38,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -38,11 +38,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)debugViewShowBorderWithColor:(UIColor *)color; - (void)debugViewShowBorderWithColor:(UIColor *)color;
/// 设置圆角 /// 设置圆角方法1
/// @param radius radius /// @param radius radius
- (void)cornerRadius:(CGFloat)radius; - (void)cornerRadius:(CGFloat)radius;
// 添加遮罩 // 设置圆角方法2
- (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius; - (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius;
// 添加遮罩 // 添加遮罩
...@@ -50,6 +50,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -50,6 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
// 移除遮罩 // 移除遮罩
- (void)removeMask; - (void)removeMask;
// 设置圆角方法3
- (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius; - (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius;
// 生成渐变色 // 生成渐变色
......
...@@ -33,8 +33,12 @@ FOUNDATION_EXTERN NSString * const HasUpdateUserDataNoti; ...@@ -33,8 +33,12 @@ FOUNDATION_EXTERN NSString * const HasUpdateUserDataNoti;
FOUNDATION_EXTERN NSString * const NeedUpdateHomePage; FOUNDATION_EXTERN NSString * const NeedUpdateHomePage;
// 需要暂停所有白噪音播放 // 需要暂停所有白噪音播放
FOUNDATION_EXTERN NSString * const NeedPauseAllNoise; FOUNDATION_EXTERN NSString * const NeedPauseAllNoise;
// 首页白噪音播放列表变化通知 // 白噪音播放列表变化通知
FOUNDATION_EXTERN NSString * const NoisePlaylistHasChange; FOUNDATION_EXTERN NSString * const NoisePlaylistHasChange;
// 白噪音音频状态变化通知
FOUNDATION_EXTERN NSString * const NoiseAudioStateHasChanged;
// 首页白噪音播放按钮状态变化通知
FOUNDATION_EXTERN NSString * const PlayStatusHasChanged;
// 首页白噪音定时器被点击通知 // 首页白噪音定时器被点击通知
FOUNDATION_EXTERN NSString * const NoiseTimingDidClick; FOUNDATION_EXTERN NSString * const NoiseTimingDidClick;
// Unity // Unity
......
...@@ -24,6 +24,8 @@ NSString * const HasUpdateUserDataNoti = @"hasUpdateUserDataNoti"; ...@@ -24,6 +24,8 @@ NSString * const HasUpdateUserDataNoti = @"hasUpdateUserDataNoti";
NSString * const NeedUpdateHomePage = @"NeedUpdateHomePageNoti"; NSString * const NeedUpdateHomePage = @"NeedUpdateHomePageNoti";
NSString * const NeedPauseAllNoise = @"NeedPauseAllNoiseNoti"; NSString * const NeedPauseAllNoise = @"NeedPauseAllNoiseNoti";
NSString * const NoisePlaylistHasChange = @"NoisePlaylistHasChangeNoti"; NSString * const NoisePlaylistHasChange = @"NoisePlaylistHasChangeNoti";
NSString * const NoiseAudioStateHasChanged = @"NoiseAudioStateHasChangedNoti";
NSString * const PlayStatusHasChanged = @"PlayStatusHasChangedNoti";
NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti"; NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti";
NSString * const ExitCoaxSleep = @"ExitCoaxSleepNoti"; NSString * const ExitCoaxSleep = @"ExitCoaxSleepNoti";
NSString * const NeedUpdateAICoach = @"NeedUpdateAICoachNoti"; NSString * const NeedUpdateAICoach = @"NeedUpdateAICoachNoti";
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "DsMaskView.h" #import "DsMaskView.h"
#import "RelaxTrainController.h" #import "RelaxTrainController.h"
#import "UnityGameController.h" #import "UnityGameController.h"
#import "SleepReadyController.h"
@interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, DsWebControllerDelegate, RelaxTrainControllerDelegate> @interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, DsWebControllerDelegate, RelaxTrainControllerDelegate>
@property (strong, nonatomic) WKWebView *aiWebView; @property (strong, nonatomic) WKWebView *aiWebView;
...@@ -198,9 +199,13 @@ ...@@ -198,9 +199,13 @@
break; break;
case 3: // 轻拍哄睡 case 3: // 轻拍哄睡
{ {
UnityGameController *gameVC = [UnityGameController new]; // UnityGameController *gameVC = [UnityGameController new];
gameVC.gameType = GameTypeCoax; // gameVC.gameType = GameTypeCoax;
[self.navigationController pushViewController:gameVC animated:YES]; // [self.navigationController pushViewController:gameVC animated:YES];
#warning - 临时测试
SleepReadyController *srVC = [SleepReadyController new];
[self.navigationController pushViewController:srVC animated:YES];
} }
break; break;
case 4: // 安心记事本 case 4: // 安心记事本
...@@ -216,6 +221,12 @@ ...@@ -216,6 +221,12 @@
[self.navigationController pushViewController:relaxVC animated:YES]; [self.navigationController pushViewController:relaxVC animated:YES];
} }
break; break;
case 6: // 安睡准备
{
SleepReadyController *srVC = [SleepReadyController new];
[self.navigationController pushViewController:srVC animated:YES];
}
break;
default: default:
break; break;
} }
......
...@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -14,6 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)refreshNoiseTypeData:(NSArray *)data; - (void)refreshNoiseTypeData:(NSArray *)data;
- (void)showMusicView;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
#import "NoisePlayBar.h" #import "NoisePlayBar.h"
#import "GoodSleepHeadView.h" #import "GoodSleepHeadView.h"
@interface SRMusicView () <GoodSleepHeadViewDelegate> @interface SRMusicView () <GoodSleepHeadViewDelegate, UIGestureRecognizerDelegate>
@property (nonatomic, strong) UIView *alertView;
@property (nonatomic, strong) GoodSleepHeadView *goodSleepHeadView; @property (nonatomic, strong) GoodSleepHeadView *goodSleepHeadView;
@property (nonatomic, strong) NoiseView *noiseView; @property (nonatomic, strong) NoiseView *noiseView;
@property (nonatomic, strong) NoisePlayBar *noisePlayBar; @property (nonatomic, strong) NoisePlayBar *noisePlayBar;
...@@ -19,19 +20,15 @@ ...@@ -19,19 +20,15 @@
@implementation SRMusicView @implementation SRMusicView
- (instancetype)initWithFrame:(CGRect)frame { - (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) { if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
[self setCornerRadiusRect:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadius:24.0]; self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0x6F7587), DSClearColor, DSWhite);
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
[self addSubview:self.goodSleepHeadView];
[self addSubview:self.noiseView];
[self addSubview:self.noisePlayBar];
[self.noisePlayBar mas_makeConstraints:^(MASConstraintMaker *make) { UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
make.left.equalTo(self).offset(15); tapGR.delegate = self;
make.right.equalTo(self).offset(-15); [self addGestureRecognizer:tapGR];
make.bottom.equalTo(self).offset(-15);
make.height.equalTo(@50); [self addSubview:self.alertView];
}];
} }
return self; return self;
} }
...@@ -40,14 +37,61 @@ ...@@ -40,14 +37,61 @@
[self.noiseView refreshNoiseTypeData:data]; [self.noiseView refreshNoiseTypeData:data];
} }
#pragma mark - GoodSleepHeadViewDelegate - (void)showMusicView {
- (void)closeAction { [DSKeyWindow addSubview:self];
[UIView animateWithDuration:.3 animations:^{ [UIView animateWithDuration:.3 animations:^{
self.y = kScreenHeight; self.alertView.y = kScreenHeight - self.alertView.height;
}]; }];
[[NSNotificationCenter defaultCenter] postNotificationName:NoisePlaylistHasChange object:nil];
}
- (void)dismissMusicView {
[UIView animateWithDuration:.3 animations:^{
self.alertView.y = kScreenHeight;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
- (void)tapAction {
[self dismissMusicView];
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[self class]]) {
return YES;
}
return NO;
}
#pragma mark - GoodSleepHeadViewDelegate
- (void)closeAction {
[self dismissMusicView];
} }
#pragma mark - lazy #pragma mark - lazy
- (UIView *)alertView {
if (!_alertView) {
_alertView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, 68 + 40 + 327 + 70 + Bottom_SafeArea_Height)];
_alertView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_alertView setCornerRadiusRect:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadius:24.0];
[_alertView addSubview:self.goodSleepHeadView];
[_alertView addSubview:self.noiseView];
[_alertView addSubview:self.noisePlayBar];
[self.noisePlayBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_alertView).offset(15);
make.right.equalTo(_alertView).offset(-15);
make.bottom.equalTo(_alertView).offset(-15-Bottom_SafeArea_Height);
make.height.equalTo(@50);
}];
}
return _alertView;
}
- (GoodSleepHeadView *)goodSleepHeadView { - (GoodSleepHeadView *)goodSleepHeadView {
if (!_goodSleepHeadView) { if (!_goodSleepHeadView) {
_goodSleepHeadView = [[GoodSleepHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 68) headType:GSHeadTypeSR]; _goodSleepHeadView = [[GoodSleepHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 68) headType:GSHeadTypeSR];
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
[self.view insertSubview:self.headIV atIndex:0]; [self.view insertSubview:self.headIV atIndex:0];
[self.view addSubview:self.startBtn]; [self.view addSubview:self.startBtn];
[self.view addSubview:self.musicBtn]; [self.view addSubview:self.musicBtn];
[self.view addSubview:self.musicView];
[self.tipsBtn mas_makeConstraints:^(MASConstraintMaker *make) { [self.tipsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.titleLab); make.centerY.equalTo(self.titleLab);
...@@ -65,6 +64,9 @@ ...@@ -65,6 +64,9 @@
make.right.equalTo(self.view).offset(-15); make.right.equalTo(self.view).offset(-15);
}]; }];
// 暂停白噪音
[[NSNotificationCenter defaultCenter] postNotificationName:NeedPauseAllNoise object:nil];
[self queryRelaxWhiteNoiseType]; [self queryRelaxWhiteNoiseType];
} }
...@@ -79,8 +81,8 @@ ...@@ -79,8 +81,8 @@
} }
- (void)backAction { - (void)backAction {
// 重置白噪音播放 // 暂停白噪音
[[NoisePlayerManager sharedNoisePlayerManager] removeAllNoiseAudioCell]; [[NSNotificationCenter defaultCenter] postNotificationName:NeedPauseAllNoise object:nil];
[super backAction]; [super backAction];
} }
...@@ -130,13 +132,11 @@ ...@@ -130,13 +132,11 @@
- (UIButton *)startBtn { - (UIButton *)startBtn {
if (!_startBtn) { if (!_startBtn) {
// WS(weakSelf);
_startBtn = [UIButton btnWithTitle:@"开始仪式" font:BoldFont(16.0)]; _startBtn = [UIButton btnWithTitle:@"开始仪式" font:BoldFont(16.0)];
[_startBtn cornerRadius:20.0]; [_startBtn cornerRadius:20.0];
[_startBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)]; [_startBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(BrandColor, SubNaviDarkColor, DSWhite)];
[_startBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal]; [_startBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_startBtn addTouchUpInsideHandler:^(NSInteger tag) { [_startBtn addTouchUpInsideHandler:^(NSInteger tag) {
// [weakSelf dismissTipsAlertView];
}]; }];
} }
return _startBtn; return _startBtn;
...@@ -148,9 +148,7 @@ ...@@ -148,9 +148,7 @@
_musicBtn = [UIButton new]; _musicBtn = [UIButton new];
[_musicBtn setImage:[UIImage imageNamed:@"ic_zhunbei_baizaoyin"] forState:UIControlStateNormal]; [_musicBtn setImage:[UIImage imageNamed:@"ic_zhunbei_baizaoyin"] forState:UIControlStateNormal];
[_musicBtn addTouchUpInsideHandler:^(NSInteger tag) { [_musicBtn addTouchUpInsideHandler:^(NSInteger tag) {
[UIView animateWithDuration:.3 animations:^{ [weakSelf.musicView showMusicView];
weakSelf.musicView.y = kScreenHeight - weakSelf.musicView.height;
}];
}]; }];
} }
return _musicBtn; return _musicBtn;
...@@ -158,7 +156,7 @@ ...@@ -158,7 +156,7 @@
- (SRMusicView *)musicView { - (SRMusicView *)musicView {
if (!_musicView) { if (!_musicView) {
_musicView = [[SRMusicView alloc] initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, 68 + 40 + 327 + 70)]; _musicView = [[SRMusicView alloc] initWithFrame:CGRectZero];
} }
return _musicView; return _musicView;
} }
......
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
[self.homeTV updateNoiseAllTypeData:self.noiseTypeArr]; [self.homeTV updateNoiseAllTypeData:self.noiseTypeArr];
// 重置白噪音播放 // 重置白噪音播放
[[NoisePlayerManager sharedNoisePlayerManager] removeAllNoiseAudioCell]; [[NoisePlayerManager sharedNoisePlayerManager] removeAllNoisePlayItem];
}); });
}); });
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "NoiseListController.h" #import "NoiseListController.h"
#import "WhiteNoiseRequestModel.h" #import "WhiteNoiseRequestModel.h"
#import "NoisePlayerManager.h" #import "NoisePlayerManager.h"
#import "NoiseAudioCell.h"
@interface NoiseListController () <UICollectionViewDelegate, UICollectionViewDataSource> @interface NoiseListController () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *noiseAudioView; @property (nonatomic, strong) UICollectionView *noiseAudioView;
...@@ -73,24 +74,24 @@ ...@@ -73,24 +74,24 @@
// 白噪音未被选择则添加到播放列表 // 白噪音未被选择则添加到播放列表
if (cell.audioIV.selected == NO) { if (cell.audioIV.selected == NO) {
if ([NoisePlayerManager sharedNoisePlayerManager].playCellList.count >= 8) { if ([NoisePlayerManager sharedNoisePlayerManager].playItemList.count >= 8) {
[DSProgressHUD showToast:@"音频最多同时播放8个"]; [DSProgressHUD showToast:@"音频最多同时播放8个"];
return; return;
} }
NoisePlayItem *playItem = [[NoisePlayItem alloc] initWithUrl:model.audio_url volume:.5]; NoisePlayItem *playItem = [[NoisePlayItem alloc] initWithUrl:model.audio_url volume:.5];
playItem.noise_audio_id = model.noise_audio_id;
playItem.audio_name = model.audio_name;
playItem.audio_pic = model.audio_pic;
playItem.isSeamlessLoopPlayback = YES; playItem.isSeamlessLoopPlayback = YES;
cell.playItem = playItem; [[NoisePlayerManager sharedNoisePlayerManager] addNoisePlayItem:playItem];
[[NoisePlayerManager sharedNoisePlayerManager] addNoiseAudioCell:cell];
[DataStatisticsUtil event:White_Noise_Click attributes:@{@"typeName":self.sub_name, @"audioName":model.audio_name}]; [DataStatisticsUtil event:White_Noise_Click attributes:@{@"typeName":self.sub_name, @"audioName":model.audio_name}];
// 执行白噪音点击任务 // 执行白噪音点击任务
[DsTaskManager excuteGeneralTaskWithType:TaskTypeDaily taskItem:TaskItemGood]; [DsTaskManager excuteGeneralTaskWithType:TaskTypeDaily taskItem:TaskItemGood];
} else { } else {
cell.playItem = nil; [[NoisePlayerManager sharedNoisePlayerManager] removeNoisePlayItemWithAudioID:model.noise_audio_id];
[[NoisePlayerManager sharedNoisePlayerManager] removeNoiseAudioCell:cell];
} }
cell.audioIV.selected = !cell.audioIV.selected;
} }
#pragma mark - lazy #pragma mark - lazy
......
...@@ -11,6 +11,12 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,6 +11,12 @@ NS_ASSUME_NONNULL_BEGIN
/// 白噪音播放对象 /// 白噪音播放对象
@interface NoisePlayItem : NSObject @interface NoisePlayItem : NSObject
/// 白噪音音频id(用于标识cell)
@property (nonatomic, assign) int noise_audio_id;
/// 名称
@property (nonatomic, copy) NSString *audio_name;
/// 选中图标
@property (nonatomic, copy) NSString *audio_pic;
/// 播放状态(YES:正在播放中...,NO:未播放) /// 播放状态(YES:正在播放中...,NO:未播放)
@property (nonatomic, assign) BOOL isPlaying; @property (nonatomic, assign) BOOL isPlaying;
/// 是否循环播放 /// 是否循环播放
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "NoiseAudioCell.h" #import "NoisePlayItem.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
...@@ -14,23 +14,22 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -14,23 +14,22 @@ NS_ASSUME_NONNULL_BEGIN
@interface NoisePlayerManager : NSObject @interface NoisePlayerManager : NSObject
SingletonH(NoisePlayerManager) SingletonH(NoisePlayerManager)
/// 播放列表,存放被选中的cell对象 /// 播放列表,存放NoisePlayItem对象(数据共享)
@property (nonatomic, strong, readonly) NSArray<NoiseAudioCell *> *playCellList; @property (nonatomic, strong, readonly) NSArray<NoisePlayItem *> *playItemList;
/// 播放状态(所有播放列表中只要有1个在播放则为YES,全部暂停为NO) /// 播放状态(所有播放列表中只要有1个在播放则为YES,全部暂停为NO)
@property (nonatomic, assign) BOOL isPlaying; @property (nonatomic, assign) BOOL isPlaying;
/// 一键播放 /// 一键播放
- (void)playAll; - (void)playAll;
/// 一键暂停 /// 一键暂停
- (void)pauseAll; - (void)pauseAll;
/// 一键停止 /// 一键停止
- (void)stopAll; - (void)stopAll;
- (BOOL)addNoiseAudioCell:(NoiseAudioCell *)cell; - (void)addNoisePlayItem:(NoisePlayItem *)item;
- (BOOL)removeNoiseAudioCell:(NoiseAudioCell *)cell; - (void)removeNoisePlayItemWithAudioID:(int)noise_audio_id;
- (void)removeAllNoiseAudioCell; - (void)removeAllNoisePlayItem;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -9,28 +9,33 @@ ...@@ -9,28 +9,33 @@
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
@interface NoisePlayerManager () @interface NoisePlayerManager ()
/// 临时操作使用的可变数组 @property (nonatomic, strong) NSMutableArray *tmpPlayItemArr;
@property (nonatomic, strong) NSMutableArray *tmpArry;
@end @end
@implementation NoisePlayerManager @implementation NoisePlayerManager
SingletonM(NoisePlayerManager) SingletonM(NoisePlayerManager)
#pragma mark - setter/getter
- (void)setIsPlaying:(BOOL)isPlaying { - (void)setIsPlaying:(BOOL)isPlaying {
_isPlaying = isPlaying; _isPlaying = isPlaying;
[[NSNotificationCenter defaultCenter] postNotificationName:@"playStatusNoti" object:nil userInfo:@{@"isPlaying":@(self.isPlaying)}]; [[NSNotificationCenter defaultCenter] postNotificationName:PlayStatusHasChanged object:nil userInfo:@{@"isPlaying":@(self.isPlaying)}];
[self addNoti]; [self addNoti];
} }
- (NSMutableArray *)tmpArry { - (NSArray<NoisePlayItem *> *)playItemList {
if (!_tmpArry) { return [self.tmpPlayItemArr copy];
_tmpArry = [NSMutableArray array]; }
- (NSMutableArray *)tmpPlayItemArr {
if (!_tmpPlayItemArr) {
_tmpPlayItemArr = [NSMutableArray array];
} }
return _tmpArry; return _tmpPlayItemArr;
} }
#pragma mark - noti
- (void)addNoti { - (void)addNoti {
// 监听音频被其他APP打断通知 // 监听音频被其他APP打断通知
AVAudioSession *sessionInstance = [AVAudioSession sharedInstance]; AVAudioSession *sessionInstance = [AVAudioSession sharedInstance];
...@@ -56,14 +61,15 @@ SingletonM(NoisePlayerManager) ...@@ -56,14 +61,15 @@ SingletonM(NoisePlayerManager)
self.isPlaying = NO; self.isPlaying = NO;
} }
- (NSArray<NoiseAudioCell *> *)playCellList { - (void)sendNoti:(id)object {
return [self.tmpArry copy]; [[NSNotificationCenter defaultCenter] postNotificationName:NoiseAudioStateHasChanged object:object];
[[NSNotificationCenter defaultCenter] postNotificationName:NoisePlaylistHasChange object:nil];
} }
#pragma mark - public
- (void)playAll { - (void)playAll {
BOOL isPlaying = NO; BOOL isPlaying = NO;
for (NoiseAudioCell *cell in self.playCellList) { for (NoisePlayItem *item in self.playItemList) {
NoisePlayItem *item = cell.playItem;
// 该状态存在不及时 // 该状态存在不及时
isPlaying = item.isPlaying; isPlaying = item.isPlaying;
[item play]; [item play];
...@@ -74,8 +80,7 @@ SingletonM(NoisePlayerManager) ...@@ -74,8 +80,7 @@ SingletonM(NoisePlayerManager)
} }
- (void)pauseAll { - (void)pauseAll {
for (NoiseAudioCell *cell in self.playCellList) { for (NoisePlayItem *item in self.playItemList) {
NoisePlayItem *item = cell.playItem;
[item pause]; [item pause];
} }
self.isPlaying = NO; self.isPlaying = NO;
...@@ -84,9 +89,7 @@ SingletonM(NoisePlayerManager) ...@@ -84,9 +89,7 @@ SingletonM(NoisePlayerManager)
} }
- (void)stopAll { - (void)stopAll {
for (NoiseAudioCell *cell in self.playCellList) { for (NoisePlayItem *item in self.playItemList) {
cell.audioIV.selected = NO;
NoisePlayItem *item = cell.playItem;
[item stop]; [item stop];
} }
self.isPlaying = NO; self.isPlaying = NO;
...@@ -94,25 +97,26 @@ SingletonM(NoisePlayerManager) ...@@ -94,25 +97,26 @@ SingletonM(NoisePlayerManager)
[self removeNoti]; [self removeNoti];
} }
- (BOOL)addNoiseAudioCell:(NoiseAudioCell *)cell { - (void)addNoisePlayItem:(NoisePlayItem *)item {
[self.tmpArry addObject:cell]; [self.tmpPlayItemArr addObject:item];
[cell.playItem play]; [self playAll];
[[NSNotificationCenter defaultCenter] postNotificationName:NoisePlaylistHasChange object:nil]; [self sendNoti:@(item.noise_audio_id)];
return YES;
} }
- (BOOL)removeNoiseAudioCell:(NoiseAudioCell *)cell { - (void)removeNoisePlayItemWithAudioID:(int)noise_audio_id {
if (![self.tmpArry containsObject:cell]) { return NO; } [self.tmpPlayItemArr enumerateObjectsUsingBlock:^(NoisePlayItem * item, NSUInteger idx, BOOL * _Nonnull stop) {
[cell.playItem stop]; if (noise_audio_id == item.noise_audio_id) {
[self.tmpArry removeObject:cell]; [item stop];
[[NSNotificationCenter defaultCenter] postNotificationName:NoisePlaylistHasChange object:nil]; [self.tmpPlayItemArr removeObject:item];
return YES; [self sendNoti:@(item.noise_audio_id)];
}
}];
} }
- (void)removeAllNoiseAudioCell { - (void)removeAllNoisePlayItem {
[self stopAll]; [self stopAll];
[self.tmpArry removeAllObjects]; [self.tmpPlayItemArr removeAllObjects];
[[NSNotificationCenter defaultCenter] postNotificationName:NoisePlaylistHasChange object:nil]; [self sendNoti:nil];
} }
@end @end
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "NoiseAudioModel.h" #import "NoiseAudioModel.h"
#import "NoisePlayItem.h"
/// 白噪音小音频cell /// 白噪音小音频cell
@interface NoiseAudioCell : UICollectionViewCell @interface NoiseAudioCell : UICollectionViewCell
...@@ -15,6 +14,4 @@ ...@@ -15,6 +14,4 @@
@property (nonatomic, strong) UIButton *audioIV; @property (nonatomic, strong) UIButton *audioIV;
/// 数据model /// 数据model
@property (nonatomic, strong) NoiseAudioModel *model; @property (nonatomic, strong) NoiseAudioModel *model;
/// 播放器
@property (nonatomic, strong) NoisePlayItem *playItem;
@end @end
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
#import "NoiseAudioCell.h" #import "NoiseAudioCell.h"
#import "NoisePlayerManager.h"
@interface NoiseAudioCell () @interface NoiseAudioCell ()
/// 白噪音音频名称 /// 白噪音音频名称
...@@ -24,10 +25,29 @@ ...@@ -24,10 +25,29 @@
make.top.equalTo(self.contentView).offset(5); make.top.equalTo(self.contentView).offset(5);
make.size.mas_equalTo(CGSizeMake(30, 30)); make.size.mas_equalTo(CGSizeMake(30, 30));
}]; }];
// 对每个白噪音cell进行监听
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noiseAudioStateHasChanged:) name:NoiseAudioStateHasChanged object:nil];
} }
return self; return self;
} }
- (void)noiseAudioStateHasChanged:(NSNotification *)noti {
if (noti.object) {
int noise_id = [noti.object intValue];
if (noise_id == self.model.noise_audio_id) {
self.audioIV.selected = !self.audioIV.selected;
}
} else {
// 清除全部触发
self.audioIV.selected = NO;
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NoiseAudioStateHasChanged object:nil];
}
- (void)setModel:(NoiseAudioModel *)model { - (void)setModel:(NoiseAudioModel *)model {
_model = model; _model = model;
...@@ -39,6 +59,12 @@ ...@@ -39,6 +59,12 @@
make.top.equalTo(self.audioIV.mas_bottom).offset(3); make.top.equalTo(self.audioIV.mas_bottom).offset(3);
make.centerX.equalTo(self.audioIV); make.centerX.equalTo(self.audioIV);
}]; }];
for (NoisePlayItem *item in [NoisePlayerManager sharedNoisePlayerManager].playItemList) {
if (item.noise_audio_id == model.noise_audio_id) {
self.audioIV.selected = YES;
}
}
} }
#pragma mark - lazy #pragma mark - lazy
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
// 添加对单例对象白噪音播放列表变化通知 // 添加对单例对象白噪音播放列表变化通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noisePlaylistHasChange:) name:NoisePlaylistHasChange object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noisePlaylistHasChange:) name:NoisePlaylistHasChange object:nil];
// 监听播放按钮状态通知 // 监听播放按钮状态通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playStatusNoti:) name:@"playStatusNoti" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playStatusNoti:) name:PlayStatusHasChanged object:nil];
// 监听定时按钮被点击事件通知 // 监听定时按钮被点击事件通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTimingView) name:NoiseTimingDidClick object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTimingView) name:NoiseTimingDidClick object:nil];
} }
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NoisePlaylistHasChange object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NoisePlaylistHasChange object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"playStatusNoti" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:PlayStatusHasChanged object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NoiseTimingDidClick object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NoiseTimingDidClick object:nil];
[_timer invalidate]; [_timer invalidate];
...@@ -91,12 +91,12 @@ ...@@ -91,12 +91,12 @@
#pragma mark - noti #pragma mark - noti
- (void)noisePlaylistHasChange:(NSNotification *)noti { - (void)noisePlaylistHasChange:(NSNotification *)noti {
NSArray *playList = [NoisePlayerManager sharedNoisePlayerManager].playCellList; NSArray *playList = [NoisePlayerManager sharedNoisePlayerManager].playItemList;
self.hidden = !(playList.count > 0); self.hidden = !(playList.count > 0);
NSMutableString *mStr = [NSMutableString string]; NSMutableString *mStr = [NSMutableString string];
for (int i = 0; i < playList.count; i++) { for (int i = 0; i < playList.count; i++) {
NoiseAudioCell *audioCell = playList[i]; NoisePlayItem *item = playList[i];
[mStr appendFormat:@"%@%@", audioCell.model.audio_name, (i == playList.count - 1) ? @"" : @","]; [mStr appendFormat:@"%@%@", item.audio_name, (i == playList.count - 1) ? @"" : @","];
self.playBtn.selected = [NoisePlayerManager sharedNoisePlayerManager].isPlaying; self.playBtn.selected = [NoisePlayerManager sharedNoisePlayerManager].isPlaying;
} }
self.audioLab.text = [mStr copy]; self.audioLab.text = [mStr copy];
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "NoiseAudioModel.h" #import "NoisePlayItem.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
...@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface NoisePlayCell : UITableViewCell @interface NoisePlayCell : UITableViewCell
@property (nonatomic, weak) id<NoisePlayCellDelegate> delegate; @property (nonatomic, weak) id<NoisePlayCellDelegate> delegate;
@property (nonatomic, strong) NoiseAudioModel *model; @property (nonatomic, strong) NoisePlayItem *item;
@property (nonatomic, assign) float volumn; @property (nonatomic, assign) float volumn;
@property (nonatomic, strong) NSIndexPath *indexPath; @property (nonatomic, strong) NSIndexPath *indexPath;
@end @end
......
...@@ -68,16 +68,12 @@ ...@@ -68,16 +68,12 @@
return self; return self;
} }
- (void)setModel:(NoiseAudioModel *)model { - (void)setItem:(NoisePlayItem *)item {
_model = model; _item = item;
[self.audioIcon yy_setImageWithURL:[NSURL URLWithString:model.audio_pic] placeholder:[UIImage imageNamed:@"basicPlaceholder"]]; [self.audioIcon yy_setImageWithURL:[NSURL URLWithString:item.audio_pic] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.nameLab.text = model.audio_name; self.nameLab.text = item.audio_name;
} self.volumeSlider.value = item.volume;
- (void)setVolumn:(float)volumn {
_volumn = volumn;
self.volumeSlider.value = volumn;
} }
- (void)setIndexPath:(NSIndexPath *)indexPath { - (void)setIndexPath:(NSIndexPath *)indexPath {
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import "NoisePlayView.h" #import "NoisePlayView.h"
#import "NoisePlayCell.h" #import "NoisePlayCell.h"
#import "NoiseAudioCell.h"
#import "NoisePlayerManager.h" #import "NoisePlayerManager.h"
@interface NoisePlayView () <UITableViewDelegate, UITableViewDataSource, NoisePlayCellDelegate> @interface NoisePlayView () <UITableViewDelegate, UITableViewDataSource, NoisePlayCellDelegate>
...@@ -39,7 +38,7 @@ ...@@ -39,7 +38,7 @@
- (void)showNoisePlayViewWith:(BOOL)selected { - (void)showNoisePlayViewWith:(BOOL)selected {
[DSKeyWindow addSubview:self]; [DSKeyWindow addSubview:self];
NSArray *playCellList = [NoisePlayerManager sharedNoisePlayerManager].playCellList; NSArray *playCellList = [NoisePlayerManager sharedNoisePlayerManager].playItemList;
if (playCellList) { if (playCellList) {
self.audioArr = playCellList; self.audioArr = playCellList;
[self.playListView reloadData]; [self.playListView reloadData];
...@@ -64,7 +63,7 @@ ...@@ -64,7 +63,7 @@
} }
- (void)clearAllAction:(UIButton *)sender { - (void)clearAllAction:(UIButton *)sender {
[[NoisePlayerManager sharedNoisePlayerManager] removeAllNoiseAudioCell]; [[NoisePlayerManager sharedNoisePlayerManager] removeAllNoisePlayItem];
self.audioArr = @[]; self.audioArr = @[];
[self.playListView reloadData]; [self.playListView reloadData];
[self removeFromSuperview]; [self removeFromSuperview];
...@@ -86,9 +85,8 @@ ...@@ -86,9 +85,8 @@
cell = [[NoisePlayCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell = [[NoisePlayCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
} }
cell.delegate = self; cell.delegate = self;
NoiseAudioCell *audioCell = self.audioArr[indexPath.row]; NoisePlayItem *item = self.audioArr[indexPath.row];
cell.model = audioCell.model; cell.item = item;
cell.volumn = audioCell.playItem.volume;
cell.indexPath = indexPath; cell.indexPath = indexPath;
return cell; return cell;
} }
...@@ -115,14 +113,12 @@ ...@@ -115,14 +113,12 @@
#pragma mark - NoisePlayCellDelegate #pragma mark - NoisePlayCellDelegate
- (void)didRemoveItem:(NSIndexPath *)indexPath { - (void)didRemoveItem:(NSIndexPath *)indexPath {
// 将要删除的音频停止播放并且设置为非选中状态 NoisePlayItem *item = self.audioArr[indexPath.row];
NoiseAudioCell *audioCell = self.audioArr[indexPath.row];
audioCell.audioIV.selected = NO;
// 删除数据源 // 删除数据源
NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:self.audioArr]; NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:self.audioArr];
[tmpArr removeObjectAtIndex:indexPath.row]; [tmpArr removeObjectAtIndex:indexPath.row];
self.audioArr = [tmpArr copy]; self.audioArr = [tmpArr copy];
[[NoisePlayerManager sharedNoisePlayerManager] removeNoiseAudioCell:audioCell]; [[NoisePlayerManager sharedNoisePlayerManager] removeNoisePlayItemWithAudioID:item.noise_audio_id];
// 执行删除动画 // 执行删除动画
[self.playListView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; [self.playListView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
dispatch_after(.3, dispatch_get_main_queue(), ^{ dispatch_after(.3, dispatch_get_main_queue(), ^{
...@@ -132,8 +128,8 @@ ...@@ -132,8 +128,8 @@
} }
- (void)didSetVolume:(float)volume indexPath:(NSIndexPath *)indexPath { - (void)didSetVolume:(float)volume indexPath:(NSIndexPath *)indexPath {
NoiseAudioCell *audioCell = self.audioArr[indexPath.row]; NoisePlayItem *item = self.audioArr[indexPath.row];
audioCell.playItem.volume = volume; item.volume = volume;
} }
#pragma mark - lazy #pragma mark - lazy
......
...@@ -38,7 +38,7 @@ typedef NS_ENUM(NSInteger, PageCellWidthType) { ...@@ -38,7 +38,7 @@ typedef NS_ENUM(NSInteger, PageCellWidthType) {
/** /**
下划线在条目切换时的动态表现类型 下划线在条目切换时的动态表现类型
- LineScrollTypeDynamicAnimation: 滑动即时的下划线动态动画 - LineScrollTypeDynamicAnimation: 滑动即时的下划线动态动画
- LineScrollTypeDynamicLinear: 滑动即时的下划线线性动画 - LineScrollTypeDynamicLinear: 滑动即时的下划线线性动画
- LineScrollTypeFinishedLinear: 滑动完成后的下划线线性动画 - LineScrollTypeFinishedLinear: 滑动完成后的下划线线性动画
......
...@@ -551,24 +551,6 @@ static float oldOffsetX; ...@@ -551,24 +551,6 @@ static float oldOffsetX;
}]; }];
} }
// if (_pageTitleColorChangeType == PageTitleColorChangeTypeScrolling) {
// NSArray *rgba0 = [self getRGBValueFromColor:_titleColor];
// NSArray *rgba1 = [self getRGBValueFromColor:_titleSelectedColor];
// CGFloat diffR = xInScreen / kScreenWidth * ([rgba1[0] floatValue] - [rgba0[0] floatValue]);
// CGFloat diffG = xInScreen / kScreenWidth * ([rgba1[1] floatValue] - [rgba0[1] floatValue]);
// CGFloat diffB = xInScreen / kScreenWidth * ([rgba1[2] floatValue] - [rgba0[2] floatValue]);
// CGFloat runingRed0 = [rgba0[0] floatValue] + diffR;
// CGFloat runingGreen0 = [rgba0[1] floatValue] + diffG;
// CGFloat runingBlue0 = [rgba0[2] floatValue] + diffB;
// CGFloat runingred1 = [rgba1[0] floatValue] - diffR;
// CGFloat runinGreen1 = [rgba1[1] floatValue] - diffG;
// CGFloat runingBlue1 = [rgba1[2] floatValue] - diffB;
// UIColor *runtimeColor0 = [UIColor colorWithRed:runingRed0 green:runingGreen0 blue:runingBlue0 alpha:1.0];
// UIColor *runtimeColor1 = [UIColor colorWithRed:runingred1 green:runinGreen1 blue:runingBlue1 alpha:1.0];
// oldCell.titleLabel.textColor = runtimeColor1;
// newCell.titleLabel.textColor = runtimeColor0;
// }
} }
/** 系统API获取UIColor的RGBA值 */ /** 系统API获取UIColor的RGBA值 */
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!