// // YOUPAILZSelectedMusicListVC.m // VQU // // Created by CY on 2021/6/25. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZSelectedMusicListVC.h" #import "YOUPAILZLiveMusicItemCell.h" @interface YOUPAILZSelectedMusicListVC () @property (nonatomic, weak) UITableView *youpaiptableView; @end @implementation YOUPAILZSelectedMusicListVC - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifcurrentMusicNotification:) name:@"CurrentMusicChangeNotification" object:nil]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"已点歌单"; [self youpaifinitUI]; if (self.youpaipcurrentMusic != nil) { [self youpaifsetupCurrentMusic]; }else{ [self.youpaiptableView reloadData]; } } - (void)youpaifinitUI{ self.view.backgroundColor = [HexColorFromRGB(0x2E2B40) colorWithAlphaComponent:0.94f]; 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; [tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.bottom.right.offset(0.0f); make.top.offset(44.0f); }]; } /// 当前歌曲 - (void)youpaifcurrentMusicNotification:(NSNotification *)notification{ self.youpaipcurrentMusic = notification.object; [self youpaifsetupCurrentMusic]; } - (void)youpaifsetupCurrentMusic{ if (self.youpaipcurrentMusic == nil) { return; } for (YOUPAILZMusicListItemModel *itemModel in self.youpaipmusicList) { if ([itemModel.youpaipsongCode isEqual:self.youpaipcurrentMusic.youpaipsongCode]) { itemModel.youpaipisPlay = YES; }else{ itemModel.youpaipisPlay = NO; } } [self.youpaiptableView reloadData]; } #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipmusicList.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.youpaipmusicList[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.youpaipmusicList[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]; } @end