YOUPAILZSelectedMusicListVC.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // YOUPAILZSelectedMusicListVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/6/25.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZSelectedMusicListVC.h"
  9. #import "YOUPAILZLiveMusicItemCell.h"
  10. @interface YOUPAILZSelectedMusicListVC ()<UITableViewDataSource,UITableViewDelegate>
  11. @property (nonatomic, weak) UITableView *youpaiptableView;
  12. @end
  13. @implementation YOUPAILZSelectedMusicListVC
  14. - (void)viewWillAppear:(BOOL)animated{
  15. [super viewWillAppear:animated];
  16. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifcurrentMusicNotification:) name:@"CurrentMusicChangeNotification" object:nil];
  17. }
  18. - (void)viewWillDisappear:(BOOL)animated{
  19. [super viewWillDisappear:animated];
  20. [[NSNotificationCenter defaultCenter] removeObserver:self];
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"已点歌单";
  25. [self youpaifinitUI];
  26. if (self.youpaipcurrentMusic != nil) {
  27. [self youpaifsetupCurrentMusic];
  28. }else{
  29. [self.youpaiptableView reloadData];
  30. }
  31. }
  32. - (void)youpaifinitUI{
  33. self.view.backgroundColor = [HexColorFromRGB(0x2E2B40) colorWithAlphaComponent:0.94f];
  34. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  35. tableView.delegate = self;
  36. tableView.dataSource = self;
  37. tableView.rowHeight = 56.0f;
  38. tableView.estimatedRowHeight = 56.0f;
  39. tableView.estimatedSectionHeaderHeight = 0.0f;
  40. tableView.estimatedSectionFooterHeight = 0.0f;
  41. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  42. tableView.backgroundColor = [UIColor clearColor];
  43. tableView.showsVerticalScrollIndicator = NO;
  44. [self.view addSubview:tableView];
  45. self.youpaiptableView = tableView;
  46. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.left.bottom.right.offset(0.0f);
  48. make.top.offset(44.0f);
  49. }];
  50. }
  51. /// 当前歌曲
  52. - (void)youpaifcurrentMusicNotification:(NSNotification *)notification{
  53. self.youpaipcurrentMusic = notification.object;
  54. [self youpaifsetupCurrentMusic];
  55. }
  56. - (void)youpaifsetupCurrentMusic{
  57. if (self.youpaipcurrentMusic == nil) {
  58. return;
  59. }
  60. for (YOUPAILZMusicListItemModel *itemModel in self.youpaipmusicList) {
  61. if ([itemModel.youpaipsongCode isEqual:self.youpaipcurrentMusic.youpaipsongCode]) {
  62. itemModel.youpaipisPlay = YES;
  63. }else{
  64. itemModel.youpaipisPlay = NO;
  65. }
  66. }
  67. [self.youpaiptableView reloadData];
  68. }
  69. #pragma mark - UITableViewDataSource
  70. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  71. return self.youpaipmusicList.count;
  72. }
  73. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  74. NSString *cellID = @"YOUPAILZLiveMusicItemCell";
  75. YOUPAILZLiveMusicItemCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  76. if (cell == nil) {
  77. cell = [[YOUPAILZLiveMusicItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  78. }
  79. [cell youpaifreloadWithModel:self.youpaipmusicList[indexPath.row]];
  80. WeakSelf;
  81. [cell setYoupaipaddMusicBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) {
  82. BOOL youpaipisContains = NO;
  83. for (YOUPAILZMusicListItemModel *itemModel in weakSelf.youpaipmusicList) {
  84. if ([itemModel.youpaipsongCode isEqual:model.youpaipsongCode]) {
  85. youpaipisContains = YES;
  86. break;
  87. }
  88. }
  89. if (!youpaipisContains) {
  90. [weakSelf.youpaipmusicList insertObject:model atIndex:0];
  91. }
  92. }];
  93. return cell;
  94. }
  95. #pragma mark - UITableViewDelegate
  96. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  97. return CGFLOAT_MIN;
  98. }
  99. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  100. return CGFLOAT_MIN;
  101. }
  102. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  103. YOUPAILZMusicListItemModel *model = self.youpaipmusicList[indexPath.row];
  104. BOOL youpaipisContains = NO;
  105. for (YOUPAILZMusicListItemModel *itemModel in self.youpaipmusicList) {
  106. if ([itemModel.youpaipsongCode isEqual:model.youpaipsongCode]) {
  107. youpaipisContains = YES;
  108. break;
  109. }
  110. }
  111. if (!youpaipisContains) {
  112. [self.youpaipmusicList insertObject:model atIndex:0];
  113. }
  114. if (self.youpaipplayMusicBlock) {
  115. self.youpaipplayMusicBlock(model);
  116. }
  117. [self.youpaiptableView reloadData];
  118. }
  119. @end