// // recordFileCell.m // 双子星云手机 // // Created by xd h on 2025/3/31. // #import "recordFileCell.h" @interface recordFileCell () @property(nonatomic,strong)UIView *cellBgView; @property(nonatomic,strong)UILabel *nameLabel;//名称 @property(nonatomic,strong)UILabel *dataLabel;//日期 @property(nonatomic,strong)UILabel *timeAndSizeLabel;//时长和大小 @property(nonatomic, strong) UIButton *checkButton; @property(nonatomic,strong)UIView *cellBg2View;// @property(nonatomic,strong)UIView *progressBgView;//进度被拒 @property(nonatomic,strong)UIView *progressingView;//进度条 @property(nonatomic,strong)UIView *progressYuanView;//进度小圆点 @property(nonatomic,strong)UILabel *progressingLabel;//已经播放的时长 @property(nonatomic,strong)UILabel *totaltimeLabel;//总时间 @property(nonatomic,strong)UIButton *editButton;//编辑 @property(nonatomic,strong)UIButton *deleteButton;//删除 @property(nonatomic,strong)UIButton *backwardButton;//后退 @property(nonatomic,strong)UIButton *playOrPauseButton;//播放或暂停 @property(nonatomic,strong)UIButton *forwardButton;//前进 @end @implementation recordFileCell @synthesize cellBgView; @synthesize checkButton; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self drawView]; } return self; } - (void)drawView { cellBgView = [[UIView alloc] init]; cellBgView.layer.cornerRadius = 12; cellBgView.layer.masksToBounds = YES; [self.contentView addSubview:cellBgView]; cellBgView.backgroundColor = [UIColor whiteColor]; [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15.f); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(SCREEN_W - 2*15.f); }]; checkButton = [[UIButton alloc] init]; [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal]; [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected]; [cellBgView addSubview:checkButton]; checkButton.hidden = YES; [checkButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(5.f); make.centerY.equalTo(cellBgView.mas_centerY); make.width.mas_equalTo(36.f); make.height.mas_equalTo(36.f); }]; [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)]; /**标题*/ _nameLabel = [[UILabel alloc] init]; [cellBgView addSubview:_nameLabel]; _nameLabel.font = [UIFont boldSystemFontOfSize:16.f]; //_nameLabel.numberOfLines = 3; [_nameLabel setTextColor:HW0A132BColor]; [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.top.mas_equalTo(10.0); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; //日期 _dataLabel = [[UILabel alloc] init]; [cellBgView addSubview:_dataLabel]; _dataLabel.font = [UIFont systemFontOfSize:12.f]; [_dataLabel setTextColor:[UIColor hwColor:@"979797"]]; [_dataLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.top.equalTo(_nameLabel.mas_bottom).offset(5); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; //时长和大小 _timeAndSizeLabel = [[UILabel alloc] init]; [cellBgView addSubview:_timeAndSizeLabel]; _timeAndSizeLabel.font = [UIFont systemFontOfSize:12.f]; _timeAndSizeLabel.textAlignment = NSTextAlignmentRight; [_timeAndSizeLabel setTextColor:[UIColor hwColor:@"979797"]]; [_timeAndSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12.0); make.top.equalTo(_nameLabel.mas_bottom).offset(5); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; /********************************************************************************************/ //第二部分 _cellBg2View = [[UIView alloc] init]; [cellBgView addSubview:_cellBg2View]; //_cellBg2View.backgroundColor = [UIColor greenColor]; [_cellBg2View mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.f); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(85.f); }]; _progressBgView = [[UIView alloc] init]; [_cellBg2View addSubview:_progressBgView]; _progressBgView.layer.cornerRadius =1.0; _progressBgView.layer.masksToBounds = YES; _progressBgView.backgroundColor = [UIColor hwColor:@"#EEEEEE"]; [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.f); make.right.mas_equalTo(-12); make.top.mas_equalTo(5); make.height.mas_equalTo(2.f); }]; _progressingView = [[UIView alloc] init]; [_progressBgView addSubview:_progressingView]; _progressingView.layer.cornerRadius =1.0; _progressingView.layer.masksToBounds = YES; _progressingView.backgroundColor = [UIColor hwColor:@"#333333"]; [_progressingView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.f); make.width.mas_equalTo(0); make.top.mas_equalTo(0); make.height.mas_equalTo(2.f); }]; // _progressYuanView = [[UIView alloc] init]; [_cellBg2View addSubview:_progressYuanView]; _progressYuanView.layer.cornerRadius = 3.0; _progressYuanView.layer.masksToBounds = YES; _progressYuanView.backgroundColor = [UIColor hwColor:@"#333333"]; [_progressYuanView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_progressBgView.mas_left).offset(0.0); make.centerY.equalTo(_progressingView.mas_centerY); make.width.mas_equalTo(6.f); make.height.mas_equalTo(6.f); }]; //已经播放的时长 _progressingLabel = [[UILabel alloc] init]; [_cellBg2View addSubview:_progressingLabel]; _progressingLabel.font = [UIFont systemFontOfSize:12.f]; [_progressingLabel setTextColor:[UIColor hwColor:@"979797"]]; [_progressingLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.top.equalTo(_progressYuanView.mas_bottom).offset(5); make.height.mas_equalTo(15.0); }]; //已经播放的时长 _totaltimeLabel = [[UILabel alloc] init]; [_cellBg2View addSubview:_totaltimeLabel]; _totaltimeLabel.font = [UIFont systemFontOfSize:12.f]; _totaltimeLabel.textAlignment = NSTextAlignmentRight; [_totaltimeLabel setTextColor:[UIColor hwColor:@"979797"]]; [_totaltimeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12.0); make.top.equalTo(_progressYuanView.mas_bottom).offset(5); make.height.mas_equalTo(15.0); }]; //编辑 _editButton = [[UIButton alloc] init]; [_editButton setImage:[UIImage imageNamed:@"record_edit_icon"] forState:UIControlStateNormal]; _editButton.tag = 1; [_editButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [_cellBg2View addSubview:_editButton]; [_editButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.bottom.mas_equalTo(-10.0); make.height.mas_equalTo(24.0); make.width.mas_equalTo(24.0); }]; //删除 _deleteButton = [[UIButton alloc] init]; [_deleteButton setImage:[UIImage imageNamed:@"record_delete_icon"] forState:UIControlStateNormal]; _deleteButton.tag = 2; [_deleteButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [_cellBg2View addSubview:_deleteButton]; [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12.0); make.bottom.mas_equalTo(-10.0); make.height.mas_equalTo(24.0); make.width.mas_equalTo(24.0); }]; //播放或暂停 _playOrPauseButton = [[UIButton alloc] init]; [_playOrPauseButton setImage:[UIImage imageNamed:@"record_player_icon"] forState:UIControlStateNormal]; [_playOrPauseButton setImage:[UIImage imageNamed:@"record_pause_icon"] forState:UIControlStateSelected]; _playOrPauseButton.tag = 10; [_playOrPauseButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [_cellBg2View addSubview:_playOrPauseButton]; [_playOrPauseButton mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(0.0); make.centerY.equalTo(_editButton.mas_centerY).offset(0); make.height.mas_equalTo(24.0); make.width.mas_equalTo(24.0); }]; //后退 _backwardButton = [[UIButton alloc] init]; [_backwardButton setImage:[UIImage imageNamed:@"record_backward_icon"] forState:UIControlStateNormal]; _backwardButton.tag = 11; [_backwardButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [_cellBg2View addSubview:_backwardButton]; [_backwardButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(_playOrPauseButton.mas_left).offset(-32); make.centerY.equalTo(_editButton.mas_centerY).offset(0); make.height.mas_equalTo(20.0); make.width.mas_equalTo(20.0); }]; //前进 _forwardButton = [[UIButton alloc] init]; [_forwardButton setImage:[UIImage imageNamed:@"record_forward_icon"] forState:UIControlStateNormal]; _forwardButton.tag = 12; [_forwardButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [_cellBg2View addSubview:_forwardButton]; [_forwardButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_playOrPauseButton.mas_right).offset(32); make.centerY.equalTo(_editButton.mas_centerY).offset(0); make.height.mas_equalTo(20.0); make.width.mas_equalTo(20.0); }]; } #pragma mark 按钮点击事件 - (void)didClickButFun:(UIButton*)but { NSInteger tag = but.tag; if(but == _playOrPauseButton){ if (_playOrPauseButton.selected) { tag = 100; } _playOrPauseButton.selected = !_playOrPauseButton.selected; } if (_didClickRecordButFun) { _didClickRecordButFun(tag); } } - (void)setCurRecordFileModel:(recordFileModel *)curRecordFileModel { _curRecordFileModel = curRecordFileModel; if(_curRecordFileModel.showAllType){ _cellBg2View.hidden = NO; } else{ _cellBg2View.hidden = YES; } _nameLabel.text = _curRecordFileModel.fileName; // 创建日期格式化器 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // 设置日期格式 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // 将NSDate转换为NSString NSString *dateString = [dateFormatter stringFromDate:_curRecordFileModel.modificationDate]; _dataLabel.text = dateString; //大小 NSString * totalSizeStr = nil; NSInteger totalSize_k = _curRecordFileModel.fileSize / 1024; if(totalSize_k < 1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k]; } else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0]; } else{ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0]; } if (_curRecordFileModel.isPlayingType) { _playOrPauseButton.selected = YES; } else{ _playOrPauseButton.selected = NO; } // 时长 totalTime NSInteger hour = 0; NSInteger min = 0; NSInteger second = 0; hour = _curRecordFileModel.totalTime / 60 /60; min = (_curRecordFileModel.totalTime -60*hour)/60; second = _curRecordFileModel.totalTime -60*hour - 60 *min; NSString* totalTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",hour,min,second]; _timeAndSizeLabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalTimeStr,totalSizeStr]; _totaltimeLabel.text = totalTimeStr; //进度相关 // 播放时长 curPlayerTime NSInteger playerhour = 0; NSInteger playerMin = 0; NSInteger playerSecond = 0; if (_curRecordFileModel.curPlayerTime == 0) { _progressingLabel.text = @"00:00:00"; } else{ playerhour = _curRecordFileModel.curPlayerTime / 60 /60; playerMin = (_curRecordFileModel.curPlayerTime -60*playerhour)/60; playerSecond = _curRecordFileModel.curPlayerTime -60*playerhour - 60 *playerMin; NSString* playingTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",playerhour,playerMin,playerSecond]; _progressingLabel.text = playingTimeStr; CGFloat progress = _curRecordFileModel.curPlayerTime *1.0 /_curRecordFileModel.totalTime; CGFloat BgWidth = _progressBgView.hw_w; CGFloat progressingWidth = BgWidth* progress; [_progressingView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0.f); make.width.mas_equalTo(progressingWidth); make.top.mas_equalTo(0); make.height.mas_equalTo(2.f); }]; [_progressYuanView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_progressingView.mas_right).offset(-2); make.centerY.equalTo(_progressingView.mas_centerY); make.width.mas_equalTo(6.f); make.height.mas_equalTo(6.f); }]; } if(curRecordFileModel.isEditType){ checkButton.hidden = NO; checkButton.selected = curRecordFileModel.isSelectType; [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(checkButton.mas_right).offset(10); make.top.mas_equalTo(10.0); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; //日期 [_dataLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(checkButton.mas_right).offset(10); make.top.equalTo(_nameLabel.mas_bottom).offset(5); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; } else{ checkButton.hidden = YES; [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.top.mas_equalTo(10.0); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; //日期 [_dataLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12.0); make.top.equalTo(_nameLabel.mas_bottom).offset(5); make.height.mas_equalTo(20.0); //make.top.mas_equalTo(15.f); }]; } } - (void)maskSwitchPressed:(UIButton *)maskSwitch{ maskSwitch.selected = !maskSwitch.selected; if(_didClickSwitch){ _didClickSwitch(maskSwitch.selected); } } @end