YOUPAILZMyMusicVC.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // YOUPAILZMyMusicVC.m
  3. // YOUQU
  4. //
  5. // Created by CY on 2021/12/10.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZMyMusicVC.h"
  9. #import "YOUPAILZMyMusicCell.h"
  10. @interface YOUPAILZMyMusicVC ()<UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic, weak) UITableView *youpaiptableView;
  12. @end
  13. @implementation YOUPAILZMyMusicVC
  14. - (void)viewWillAppear:(BOOL)animated{
  15. [super viewWillAppear:animated];
  16. [self reloadTableView];
  17. }
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self _initUI];
  21. }
  22. - (void)_initUI{
  23. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  24. tableView.delegate = self;
  25. tableView.dataSource = self;
  26. tableView.rowHeight = 60.0f;
  27. tableView.estimatedRowHeight = 60.0f;
  28. tableView.estimatedSectionHeaderHeight = 0.0f;
  29. tableView.estimatedSectionFooterHeight = 0.0f;
  30. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  31. tableView.backgroundColor = [UIColor clearColor];
  32. tableView.showsVerticalScrollIndicator = NO;
  33. [self.view addSubview:tableView];
  34. self.youpaiptableView = tableView;
  35. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.right.top.offset(0.0f);
  37. make.bottom.offset(-SafeHeight);
  38. }];
  39. }
  40. - (void)reloadTableView{
  41. [self.youpaiptableView reloadData];
  42. if ([YOUPAILZMusicManager shareManager].youpaipmusics.count == 0) {
  43. [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无歌曲" btnTitle:@"快去添加吧~" btnColor:HexColorFromRGB(0xFF3065) block:self.goHotMusicListBlock];
  44. }else{
  45. [self.youpaiptableView lz_hideEmptyView];
  46. }
  47. }
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  49. NSInteger count = [YOUPAILZMusicManager shareManager].youpaipmusics.count;
  50. return count;
  51. }
  52. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  53. NSString *cellID = @"YOUPAILZMyMusicCell";
  54. YOUPAILZMyMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  55. if (cell == nil) {
  56. cell = [[YOUPAILZMyMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  57. }
  58. [cell youpaifreloadWithModel:[YOUPAILZMusicManager shareManager].youpaipmusics[indexPath.row]];
  59. @weakify(self);
  60. [cell setMoreBtnClickBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) {
  61. @strongify(self);
  62. NSMutableArray* actionArray = [NSMutableArray array];
  63. ZCAlertAction *removeAction = [ZCAlertAction actionWithTitle:@"移除" andblock:^{
  64. @strongify(self);
  65. [[YOUPAILZMusicManager shareManager] youpaifremoveMusic:model];
  66. [self reloadTableView];
  67. [LCHttpHelper requestWithURLString:DelMySong parameters:@{@"songCode":model.youpaipsongCode} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  68. } failure:^(NSError *error) {
  69. }];
  70. }];
  71. [actionArray addObject:removeAction];
  72. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray];
  73. alertSheet.alertWindow.hidden = NO;
  74. [alertSheet show];
  75. }];
  76. return cell;
  77. }
  78. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  79. return CGFLOAT_MIN;
  80. }
  81. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  82. return CGFLOAT_MIN;
  83. }
  84. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  85. [self handleCellEventWithUserInteractionEnabled:NO];
  86. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  87. [self handleCellEventWithUserInteractionEnabled:YES];
  88. });
  89. [[YOUPAILZMusicManager shareManager] youpaifplayMusic:[YOUPAILZMusicManager shareManager].youpaipmusics[indexPath.row]];
  90. [self.youpaiptableView reloadData];
  91. }
  92. - (void)handleCellEventWithUserInteractionEnabled:(BOOL)userInteractionEnabled{
  93. for (NSInteger i = 0; i < [YOUPAILZMusicManager shareManager].youpaipmusics.count; i ++) {
  94. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
  95. UITableViewCell *cell = [self.youpaiptableView cellForRowAtIndexPath:indexPath];
  96. cell.userInteractionEnabled = userInteractionEnabled;
  97. }
  98. }
  99. #pragma mark - JXCategoryListContentViewDelegate
  100. - (UIView *)listView{
  101. return self.view;
  102. }
  103. @end