123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- //
- // YOUPAILZLiveMusicListWindow.m
- // VQU
- //
- // Created by CY on 2021/6/25.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZLiveMusicListWindow.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAILZLiveMusicItemCell.h"
- #import "YOUPAILZSelectedMusicListVC.h"
- @interface YOUPAILZLiveMusicListWindow () <UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, weak) UIButton *youpaipplayBtn; // 播放暂停
- @property (nonatomic, weak) UIButton *youpaiplyricBtn; // 歌词
- @property (nonatomic, weak) UITableView *youpaiptableView;
- @property (nonatomic, assign) NSInteger youpaippage;
- @property (nonatomic, strong) NSMutableArray <YOUPAILZMusicListItemModel *>*youpaipdataSource;
- @end
- @implementation YOUPAILZLiveMusicListWindow
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifcurrentMusicNotification:) name:@"CurrentMusicChangeNotification" object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifmusicPlayStateChangeNotification:) name:@"MusicPlayStateChangeNotification" object:nil];
-
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationController.navigationBarHidden = YES;
- [self youpaifinitUI];
- [self youpaifrequestMusicListWithStatus:kRefreshNormal];
- }
- - (void)youpaifinitUI{
- self.view.backgroundColor = [HexColorFromRGB(0x2E2B40) colorWithAlphaComponent:0.94f];
- UIView *playBgV = [[UIView alloc] init];
- [self.view addSubview:playBgV];
- [playBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.offset(0.0f);
- make.height.offset(64.0f);
- }];
-
- UIButton *sheetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- sheetBtn.layer.cornerRadius = 8.0f;
- sheetBtn.clipsToBounds = YES;
- sheetBtn.layer.borderColor = ZYPinkColor.CGColor;
- sheetBtn.layer.borderWidth = 1.0f;
- sheetBtn.titleLabel.font = LCFont14;
- [sheetBtn setTitle:@"已点" forState:UIControlStateNormal];
- [sheetBtn setTitleColor:ZYPinkColor forState:UIControlStateNormal];
- [sheetBtn addTarget:self action:@selector(youpaifsheetBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [playBgV addSubview:sheetBtn];
- [sheetBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(playBgV);
- make.left.offset(16.0f);
- make.size.mas_offset(CGSizeMake(48, 28));
- }];
-
- UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipcloseBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateNormal];
- [youpaipcloseBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_L_live_window_close"] forState:UIControlStateHighlighted];
- [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [playBgV addSubview:youpaipcloseBtn];
- [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(playBgV);
- make.right.offset(-7.0f);
- make.size.mas_offset(CGSizeMake(28, 28));
- }];
-
-
- UIView *playV = [[UIView alloc] init];
- [playBgV addSubview:playV];
- [playV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(playBgV);
- make.top.bottom.offset(0.0f);
- }];
-
- UIButton *youpaipplayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipplayBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_music_player_play"] forState:UIControlStateNormal];
- [youpaipplayBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_music_player_suspend"] forState:UIControlStateSelected];
- // youpaipplayBtn.selected = self.youpaipmusicPlayState != AgoraAudioMixingStatePlaying;
- [youpaipplayBtn addTarget:self action:@selector(youpaifplayBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [playV addSubview:youpaipplayBtn];
- self.youpaipplayBtn = youpaipplayBtn;
- [youpaipplayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(playV);
- make.left.offset(0.0f);
- make.size.mas_offset(CGSizeMake(40, 40));
- }];
-
- UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [nextBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_music_next"] forState:UIControlStateNormal];
- [nextBtn setImage:[UIImage imageNamed:@"vqu_images_L_live_music_next"] forState:UIControlStateNormal];
- [nextBtn addTarget:self action:@selector(youpaifnextBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [playV addSubview:nextBtn];
- [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(playV);
- make.left.equalTo(youpaipplayBtn.mas_right).offset(16.0f);
- make.size.mas_offset(CGSizeMake(40, 40));
- }];
-
- UIButton *youpaiplyricBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- youpaiplyricBtn.layer.cornerRadius = 20.0f;
- youpaiplyricBtn.clipsToBounds = YES;
- youpaiplyricBtn.layer.borderColor = [UIColor whiteColor].CGColor;
- youpaiplyricBtn.layer.borderWidth = 1.0f;
- youpaiplyricBtn.titleLabel.font = LCFont16;
- [youpaiplyricBtn setTitle:@"词" forState:UIControlStateNormal];
- [youpaiplyricBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [youpaiplyricBtn setTitleColor:ZYPinkColor forState:UIControlStateSelected];
- youpaiplyricBtn.selected = self.showLyric;
- youpaiplyricBtn.layer.borderColor = youpaiplyricBtn.selected ? ZYPinkColor.CGColor :[UIColor whiteColor].CGColor;
- [youpaiplyricBtn addTarget:self action:@selector(youpaiflyricBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [playV addSubview:youpaiplyricBtn];
- self.youpaiplyricBtn = youpaiplyricBtn;
- [youpaiplyricBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(playV);
- make.left.equalTo(nextBtn.mas_right).offset(16.0f);
- make.right.offset(0.0f);
- make.size.mas_offset(CGSizeMake(40, 40));
- }];
-
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- tableView.delegate = self;
- tableView.dataSource = self;
- tableView.rowHeight = 56.0f;
- tableView.estimatedRowHeight = 56.0f;
- tableView.estimatedSectionHeaderHeight = 0.0f;
- tableView.estimatedSectionFooterHeight = 0.0f;
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
- tableView.showsVerticalScrollIndicator = NO;
- [self.view addSubview:tableView];
- self.youpaiptableView = tableView;
- __weak typeof(self) weakSelf = self;
- [tableView setRefreshHeaderWithBlock:^{
- [weakSelf youpaifrequestMusicListWithStatus:kRefreshHeader];
- }];
- [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.offset(0.0f);
- make.top.equalTo(playBgV.mas_bottom).offset(0.0f);
- }];
- }
- /// 当前播放歌曲发生改变
- - (void)youpaifcurrentMusicNotification:(NSNotification *)notification{
- self.youpaipcurrentMusic = notification.object;
- [self youpaifsetupCurrentMusic];
- }
- - (void)youpaifsetupCurrentMusic{
- if (self.youpaipcurrentMusic == nil) {
- return;
- }
- for (YOUPAILZMusicListItemModel *itemModel in self.youpaipdataSource) {
- if ([itemModel.youpaipsongCode isEqual:self.youpaipcurrentMusic.youpaipsongCode]) {
- itemModel.youpaipisPlay = YES;
- }else{
- itemModel.youpaipisPlay = NO;
- }
- }
- [self.youpaiptableView reloadData];
- }
- /// 播放状态发生改变
- - (void)youpaifmusicPlayStateChangeNotification:(NSNotification *)notification{
- // self.youpaipmusicPlayState = [notification.object integerValue];
- // self.youpaipplayBtn.selected = self.youpaipmusicPlayState != AgoraAudioMixingStatePlaying;
- }
- #pragma mark - UITableViewDataSource
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.youpaipdataSource.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSString *cellID = @"YOUPAILZLiveMusicItemCell";
- YOUPAILZLiveMusicItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
- if (cell == nil) {
- cell = [[YOUPAILZLiveMusicItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
- }
- [cell youpaifreloadWithModel:self.youpaipdataSource[indexPath.row]];
- WeakSelf;
- [cell setYoupaipaddMusicBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) {
- BOOL youpaipisContains = NO;
- for (YOUPAILZMusicListItemModel *itemModel in weakSelf.youpaipmusicList) {
- if ([itemModel.youpaipsongCode isEqual:model.youpaipsongCode]) {
- youpaipisContains = YES;
- break;
- }
- }
- if (!youpaipisContains) {
- [weakSelf.youpaipmusicList insertObject:model atIndex:0];
- }
- }];
- return cell;
- }
- #pragma mark - UITableViewDelegate
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZMusicListItemModel *model = self.youpaipdataSource[indexPath.row];
- BOOL youpaipisContains = NO;
- for (YOUPAILZMusicListItemModel *itemModel in self.youpaipmusicList) {
- if ([itemModel.youpaipsongCode isEqual:model.youpaipsongCode]) {
- youpaipisContains = YES;
- break;
- }
- }
- if (!youpaipisContains) {
- [self.youpaipmusicList insertObject:model atIndex:0];
- }
- if (self.youpaipplayMusicBlock) {
- self.youpaipplayMusicBlock(model);
- }
- [self.youpaiptableView reloadData];
-
- }
- // 已点歌曲
- - (void)youpaifsheetBtnClick{
- YOUPAILZSelectedMusicListVC *vc = [[YOUPAILZSelectedMusicListVC alloc] init];
- vc.youpaipmusicList = self.youpaipmusicList;
- vc.youpaipcurrentMusic = self.youpaipcurrentMusic;
- WeakSelf;
- [vc setYoupaipplayMusicBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) {
- if (weakSelf.youpaipplayMusicBlock != nil) {
- weakSelf.youpaipplayMusicBlock(model);
- }
- }];
- [self.navigationController pushViewController:vc animated:YES];
- }
- // 播放暂停
- - (void)youpaifplayBtnClick:(UIButton *)sender{
- if (self.youpaipsuspendMusicBlock) {
- self.youpaipsuspendMusicBlock();
- }
- }
- // 下一曲
- - (void)youpaifnextBtnClick{
- if (self.youpaipnextMusicBlock) {
- self.youpaipnextMusicBlock();
- }
- }
- // 歌词
- - (void)youpaiflyricBtnClick:(UIButton *)sender{
- sender.selected = !sender.selected;
- self.youpaiplyricBtn.layer.borderColor = sender.selected ? ZYPinkColor.CGColor :[UIColor whiteColor].CGColor;
- if (self.showLyricBlock != nil) {
- self.showLyricBlock(sender.selected);
- }
- }
- // 退出
- - (void)youpaifcloseBtnClick{
- if (self.youpaipcloseBlock != nil) {
- self.youpaipcloseBlock();
- }
- [self dismissViewControllerAnimated:NO completion:nil];
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaiptableView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestMusicListWithStatus:kRefreshFooter];
- }];
- }
- /// 获取列表数据
- - (void)youpaifrequestMusicListWithStatus:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.youpaippage ++;
- }else{
- self.youpaippage = 1;
- }
- WeakSelf;
- [LCHttpHelper requestWithURLString:MusicBaseHot parameters:@{@"page":@(self.youpaippage),@"pageSize":@(10)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [weakSelf.youpaipdataSource removeAllObjects];
- }
- NSDictionary *data = [dict objectForKey:@"data"];
- NSArray <YOUPAILZMusicListItemModel *>*list = [YOUPAILZMusicListItemModel mj_objectArrayWithKeyValuesArray:[data objectForKey:@"record"]];
- [weakSelf.youpaipdataSource addObjectsFromArray:list];
- [weakSelf.youpaiptableView reloadData];
- [weakSelf youpaifsetupCurrentMusic];
- NSInteger totalCount = [[[data objectForKey:@"meta"] objectForKey:@"totalCount"] integerValue];
- [weakSelf youpaifrefreshFooterWithHidden:weakSelf.youpaippage * 10 >= totalCount];
- }
- } failure:^(NSError *error) {
- [weakSelf.youpaiptableView endRefreshing:kRefreshAll];
- }];
- }
- - (NSMutableArray<YOUPAILZMusicListItemModel *> *)youpaipdataSource{
- if (!_youpaipdataSource) {
- _youpaipdataSource = [NSMutableArray array];
- }
- return _youpaipdataSource;
- }
- @end
|