123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- //
- // YOUPAILZSelectedMusicListVC.m
- // VQU
- //
- // Created by CY on 2021/6/25.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZSelectedMusicListVC.h"
- #import "YOUPAILZLiveMusicItemCell.h"
- @interface YOUPAILZSelectedMusicListVC ()<UITableViewDataSource,UITableViewDelegate>
- @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
|