// // YOUPAILZMyMusicVC.m // YOUQU // // Created by CY on 2021/12/10. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZMyMusicVC.h" #import "YOUPAILZMyMusicCell.h" @interface YOUPAILZMyMusicVC () @property (nonatomic, weak) UITableView *youpaiptableView; @end @implementation YOUPAILZMyMusicVC - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self reloadTableView]; } - (void)viewDidLoad { [super viewDidLoad]; [self _initUI]; } - (void)_initUI{ UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; tableView.delegate = self; tableView.dataSource = self; tableView.rowHeight = 60.0f; tableView.estimatedRowHeight = 60.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.right.top.offset(0.0f); make.bottom.offset(-SafeHeight); }]; } - (void)reloadTableView{ [self.youpaiptableView reloadData]; if ([YOUPAILZMusicManager shareManager].youpaipmusics.count == 0) { [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无歌曲" btnTitle:@"快去添加吧~" btnColor:HexColorFromRGB(0xFF3065) block:self.goHotMusicListBlock]; }else{ [self.youpaiptableView lz_hideEmptyView]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ NSInteger count = [YOUPAILZMusicManager shareManager].youpaipmusics.count; return count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *cellID = @"YOUPAILZMyMusicCell"; YOUPAILZMyMusicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[YOUPAILZMyMusicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } [cell youpaifreloadWithModel:[YOUPAILZMusicManager shareManager].youpaipmusics[indexPath.row]]; @weakify(self); [cell setMoreBtnClickBlock:^(YOUPAILZMusicListItemModel * _Nonnull model) { @strongify(self); NSMutableArray* actionArray = [NSMutableArray array]; ZCAlertAction *removeAction = [ZCAlertAction actionWithTitle:@"移除" andblock:^{ @strongify(self); [[YOUPAILZMusicManager shareManager] youpaifremoveMusic:model]; [self reloadTableView]; [LCHttpHelper requestWithURLString:DelMySong parameters:@{@"songCode":model.youpaipsongCode} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { } failure:^(NSError *error) { }]; }]; [actionArray addObject:removeAction]; ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray]; alertSheet.alertWindow.hidden = NO; [alertSheet show]; }]; return cell; } - (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{ [self handleCellEventWithUserInteractionEnabled:NO]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self handleCellEventWithUserInteractionEnabled:YES]; }); [[YOUPAILZMusicManager shareManager] youpaifplayMusic:[YOUPAILZMusicManager shareManager].youpaipmusics[indexPath.row]]; [self.youpaiptableView reloadData]; } - (void)handleCellEventWithUserInteractionEnabled:(BOOL)userInteractionEnabled{ for (NSInteger i = 0; i < [YOUPAILZMusicManager shareManager].youpaipmusics.count; i ++) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0]; UITableViewCell *cell = [self.youpaiptableView cellForRowAtIndexPath:indexPath]; cell.userInteractionEnabled = userInteractionEnabled; } } #pragma mark - JXCategoryListContentViewDelegate - (UIView *)listView{ return self.view; } @end