recordViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. //
  2. // recordViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2025/3/28.
  6. //
  7. #import "recordViewController.h"
  8. #import "recordBottomView.h"
  9. #import "recordingView.h"
  10. #import <AVFoundation/AVFoundation.h>
  11. #import "recordFileModel.h"
  12. #import "recordFileCell.h"
  13. #import "reNameRecordFileView.h"
  14. #import "ComontAlretViewController.h"
  15. #import "editTypeHeadView.h"
  16. #import "recordEditBottomView.h"
  17. #import "uploadFileRecordViewController.h"
  18. @interface recordViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  19. @property (nonatomic, strong) UIButton *rightButton;//编辑
  20. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  21. @property(nonatomic,strong) recordEditBottomView*curEditTypeBottomView;
  22. @property(nonatomic,strong) NSMutableArray* didSelectListArr;
  23. @property(nonatomic,assign) BOOL isEditType;
  24. @property (nonatomic, strong) UITableView *tableView;
  25. @property(nonatomic,strong)NSMutableArray *audioArr;//音频数据
  26. @property(nonatomic,strong)recordBottomView *recordBottomV;//底部视图
  27. @property(nonatomic,strong)recordingView *recordingV;//录音中
  28. @property(nonatomic,strong)reNameRecordFileView * reNameRecordFileV;
  29. @end
  30. @implementation recordViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. // Do any additional setup after loading the view.
  34. _audioArr = [NSMutableArray new];
  35. _didSelectListArr = [NSMutableArray new];
  36. [self drawAnyView];
  37. [self getRecordDataFun];
  38. }
  39. - (void)drawAnyView
  40. {
  41. [self.view setBackgroundColor:HWF5F7FAColor];
  42. self.navBarBGView.hidden = NO;
  43. [self.navigationBar setHidden:YES];
  44. [self.toolBar setHidden:YES];
  45. [self.titleLabel setText:NSLocalizedString(@"mine_record_title",nil)];
  46. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  47. //编辑
  48. _rightButton = [[UIButton alloc] init];
  49. [_rightButton setTitle:NSLocalizedString(@"edit_common",nil) forState:UIControlStateNormal];
  50. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA"] forState:UIControlStateNormal];
  51. _rightButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
  52. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  53. [_rightButton addTarget:self action:@selector(didClickEditFun) forControlEvents:UIControlEventTouchUpInside];
  54. [self.navBarBGView addSubview:_rightButton];
  55. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.right.mas_equalTo(-15.f);
  57. make.width.mas_equalTo(40.f);
  58. make.centerY.equalTo(self.titleLabel.mas_centerY).offset(0.0);
  59. make.height.mas_equalTo(30);
  60. }];
  61. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  62. _curEditTypeHeadView.hidden = YES;
  63. [self.navBarBGView addSubview:_curEditTypeHeadView];
  64. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(0);
  66. make.right.mas_equalTo(0);
  67. make.bottom.mas_equalTo(0);
  68. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  69. }];
  70. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  71. KWeakSelf
  72. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  73. if(tag==1){
  74. [weakSelf userCancelEditTypeFun];
  75. }
  76. };
  77. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  78. [weakSelf didClickSelectAllButton:but];
  79. };
  80. _curEditTypeBottomView = [[recordEditBottomView alloc] init];
  81. _curEditTypeBottomView.hidden = YES;
  82. [self.view addSubview:_curEditTypeBottomView];
  83. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.mas_equalTo(0);
  85. make.right.mas_equalTo(0);
  86. make.bottom.mas_equalTo(0);
  87. make.height.mas_equalTo(60 + AdaptTabHeight);
  88. }];
  89. #pragma mark 编辑状态的 下载 删除 响应事件
  90. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  91. if(tag==1){
  92. [weakSelf gotoUpLoadFileFun];
  93. }
  94. else if(tag==3){
  95. [weakSelf showDeleteAlearViewFun];
  96. }
  97. };
  98. //底部视图
  99. _recordBottomV = [[recordBottomView alloc] init];
  100. [self.view addSubview:_recordBottomV];
  101. [_recordBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.mas_equalTo(0.f);
  103. make.right.mas_equalTo(0.f);
  104. make.bottom.mas_equalTo(0.f);
  105. make.height.mas_equalTo(100.f + AdaptTabHeight);
  106. }];
  107. //KWeakSelf
  108. _recordBottomV.didClickRecordFun = ^{
  109. [weakSelf didClickRecordFun];
  110. };
  111. [self.view addSubview:self.tableView];
  112. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.mas_equalTo(0);
  114. make.right.mas_equalTo(0);
  115. make.bottom.equalTo(self.recordBottomV.mas_top).offset(0.f);
  116. //make.bottom.mas_equalTo(0);
  117. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  118. }];
  119. }
  120. #pragma mark - 懒加载
  121. - (UITableView *)tableView{
  122. if (!_tableView) {
  123. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
  124. _tableView.delegate = self;
  125. _tableView.dataSource = self;
  126. _tableView.showsVerticalScrollIndicator = NO;
  127. _tableView.showsHorizontalScrollIndicator = NO;
  128. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  129. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  130. [_tableView setSeparatorColor:[UIColor clearColor]];
  131. [_tableView setBackgroundColor:[UIColor clearColor]];
  132. [_tableView setTableFooterView:[UIView new]];
  133. [_tableView setBounces:YES];
  134. if (@available(iOS 15.0, *)) {
  135. _tableView.sectionHeaderTopPadding = 0;
  136. }
  137. //空数据引入第三方开源处理
  138. _tableView.emptyDataSetSource = self;
  139. _tableView.emptyDataSetDelegate = self;
  140. // 下拉追加
  141. // MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  142. // [self getMoreNetWorkData];
  143. // }];
  144. //
  145. // NSString *text = NSLocalizedString(@"NAS_bottom_tip",nil);
  146. // [footer setTitle:text forState:MJRefreshStateNoMoreData];
  147. // _tableView.mj_footer = footer;
  148. }
  149. return _tableView;
  150. }
  151. #pragma mark - 列表委托
  152. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  153. if(!_audioArr){
  154. return 0;
  155. }
  156. return _audioArr.count;
  157. }
  158. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  159. return 1;
  160. }
  161. - (recordFileCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  162. __block NSInteger row = indexPath.section;
  163. static NSString *identifier = @"recordFileCell";
  164. recordFileCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  165. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  166. if (!cell){
  167. cell = [[recordFileCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  168. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  169. [cell setBackgroundColor:[UIColor clearColor]];
  170. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  171. }
  172. if(row < _audioArr.count){
  173. recordFileModel* dataModel = _audioArr[row];
  174. cell.curRecordFileModel = dataModel;
  175. KWeakSelf
  176. cell.didClickRecordButFun = ^(NSInteger index) {
  177. [weakSelf didClickCellFunBy:index withRow:row];
  178. };
  179. cell.didClickSwitch = ^(BOOL SwitchOn) {
  180. [weakSelf userCheckFilePreviewByRow:row];
  181. };
  182. }
  183. return cell;
  184. }
  185. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  186. NSInteger row = indexPath.section;
  187. if(row >=_audioArr.count){
  188. return 0.0;
  189. }
  190. recordFileModel *model = _audioArr[row];
  191. if (model.showAllType) {
  192. return 150;
  193. }
  194. return 65;
  195. }
  196. - (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  197. {
  198. return [UIView new];
  199. }
  200. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  201. return 12.0;
  202. }
  203. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  204. {
  205. if (_isEditType) {
  206. return;
  207. }
  208. NSInteger row = indexPath.section;
  209. if(row < _audioArr.count){
  210. recordFileModel *model = _audioArr[row];
  211. if(!model.showAllType){
  212. model.showAllType = YES;
  213. [tableView reloadData];
  214. }
  215. }
  216. }
  217. #pragma mark 空数据
  218. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  219. NSString *imageName = @"common_no_data_pic";
  220. return [UIImage imageNamed:imageName];
  221. }
  222. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  223. NSString *text = NSLocalizedString(@"record_no_data_tip",nil);
  224. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  225. NSForegroundColorAttributeName: HW999999Color};
  226. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  227. }
  228. //调整图片位置
  229. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  230. return -150;
  231. }
  232. #pragma mark 读取本地数据
  233. - (void)getRecordDataFun
  234. {
  235. NSString *documentsDirectory = kSHPath_Record;
  236. NSFileManager *fileManager = [NSFileManager defaultManager];
  237. NSError *error = nil;
  238. NSArray *fileList = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error];
  239. if (error) {
  240. HLog(@"Error reading contents of directory: %@", error.localizedDescription);
  241. }
  242. NSMutableArray *dataArr = [NSMutableArray new];
  243. //BOOL isFirstType = YES;
  244. for (NSString *fileName in fileList) {
  245. NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];
  246. // 获取文件属性
  247. NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:filePath error:&error];
  248. if (error) {
  249. NSLog(@"获取文件属性出错: %@ - %@", fileName, error.localizedDescription);
  250. error = nil;
  251. continue;
  252. }
  253. // 判断是否是目录
  254. BOOL isDirectory = [fileAttributes[NSFileType] isEqualToString:NSFileTypeDirectory];
  255. // 获取文件大小
  256. unsigned long long fileSize = [fileAttributes[NSFileSize] unsignedLongLongValue];
  257. recordFileModel *model = [recordFileModel new];
  258. model.fileName = fileName;
  259. model.filePath = filePath;
  260. model.fileSize = fileSize;
  261. model.isDirectory = isDirectory;
  262. model.modificationDate = fileAttributes[NSFileModificationDate] ?: [NSDate date];
  263. NSURL *fileUrl = [NSURL URLWithString:model.filePath];
  264. NSTimeInterval time = [self getDurationOfAudioFile:fileUrl];
  265. model.totalTime = (NSInteger)ceil(time); // 结果为 5;
  266. model.showAllType = NO;
  267. // if (isFirstType) {
  268. // model.showAllType = YES;
  269. // isFirstType = NO;
  270. // }
  271. // else{
  272. // model.showAllType = NO;
  273. // }
  274. // 创建文件信息字典
  275. // NSDictionary *fileInfo = @{
  276. // @"name": fileName,
  277. // @"path": filePath,
  278. // @"size": @(fileSize),
  279. // @"isDirectory": @(isDirectory),
  280. // @"modificationDate": fileAttributes[NSFileModificationDate] ?: [NSDate date]
  281. // };
  282. [dataArr addObject:model];
  283. }
  284. // 假设你的对象有一个名为 dateProperty 的 NSDate 属性
  285. NSArray *sortedArray = [dataArr sortedArrayUsingComparator:^NSComparisonResult(recordFileModel* obj1, recordFileModel* obj2) {
  286. return [obj2.modificationDate compare:obj1.modificationDate];
  287. }];
  288. [_audioArr removeAllObjects];
  289. [_audioArr addObjectsFromArray:sortedArray];
  290. recordFileModel *firstModel = _audioArr.firstObject;
  291. firstModel.showAllType = YES;
  292. }
  293. #pragma mark 获取录音文件的时长
  294. - (NSTimeInterval)getDurationOfAudioFile:(NSURL *)fileURL {
  295. NSError *error;
  296. AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
  297. if (error) {
  298. HLog(@"Error: %@", error.localizedDescription);
  299. return 0;
  300. }
  301. return player.duration;
  302. }
  303. #pragma mark 点击了录音
  304. - (void)didClickRecordFun
  305. {
  306. if(_recordingV){
  307. return;
  308. }
  309. //检测麦克风权限
  310. AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];
  311. // MicrophonePermissionStatus status;
  312. // switch (permissionStatus) {
  313. // case AVAudioSessionRecordPermissionUndetermined:
  314. // status = MicrophonePermissionStatusNotDetermined;
  315. // break;
  316. // case AVAudioSessionRecordPermissionDenied:
  317. // status = MicrophonePermissionStatusDenied;
  318. // break;
  319. // case AVAudioSessionRecordPermissionGranted:
  320. // status = MicrophonePermissionStatusGranted;
  321. // break;
  322. // }
  323. if (permissionStatus == AVAudioSessionRecordPermissionDenied) {
  324. NSString *tip = NSLocalizedString(@"mine_record_microphone_tip",nil);
  325. [[iToast makeText:tip] show];
  326. return;
  327. }
  328. else if(permissionStatus == AVAudioSessionRecordPermissionUndetermined) {
  329. KWeakSelf
  330. [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
  331. dispatch_async(dispatch_get_main_queue(), ^{
  332. if (granted) {
  333. [weakSelf beginRecordFun];
  334. } else {
  335. }
  336. });
  337. }];
  338. return;
  339. }
  340. [self beginRecordFun];
  341. }
  342. #pragma mark 弹起录音功能
  343. - (void)beginRecordFun
  344. {
  345. _recordingV = [[recordingView alloc] init];
  346. [ksharedAppDelegate.window addSubview:_recordingV];
  347. [_recordingV mas_makeConstraints:^(MASConstraintMaker *make) {
  348. make.left.mas_equalTo(0.f);
  349. make.right.mas_equalTo(0.f);
  350. make.bottom.mas_equalTo(0.f);
  351. make.top.mas_equalTo(0);
  352. }];
  353. NSInteger index = _audioArr.count + 1;
  354. [_recordingV beginRecordFunWith:index];
  355. KWeakSelf
  356. _recordingV.didClickRecordEndFun = ^{
  357. [weakSelf deleteRecordingViewFun];
  358. };
  359. }
  360. #pragma mark 删除录音中界面
  361. - (void)deleteRecordingViewFun
  362. {
  363. [_recordingV removeFromSuperview];
  364. _recordingV = nil;
  365. [self getRecordDataFun];
  366. [self.tableView reloadData];
  367. }
  368. #pragma mark 点击cell里面的按钮事件 //index 1 编辑 2 删除 10 播放 11 后退 12 前进
  369. - (void)didClickCellFunBy:(NSInteger)index withRow:(NSInteger)row
  370. {
  371. switch (index) {
  372. case 1:
  373. [self didClickEditFunWithRow:row];
  374. break;
  375. case 2:
  376. [self deleteFileByRow:row];
  377. default:
  378. break;
  379. }
  380. }
  381. #pragma mark 点击编辑
  382. - (void)didClickEditFunWithRow:(NSInteger)row
  383. {
  384. recordFileModel *model = nil;
  385. if (_audioArr.count > row) {
  386. model = _audioArr[row];
  387. }
  388. else{
  389. return;
  390. }
  391. if (_reNameRecordFileV) {
  392. [_reNameRecordFileV removeFromSuperview];
  393. }
  394. _reNameRecordFileV = [[reNameRecordFileView alloc] init];
  395. [ksharedAppDelegate.window addSubview:_reNameRecordFileV];
  396. _reNameRecordFileV.fileName = model.fileName;
  397. [_reNameRecordFileV mas_makeConstraints:^(MASConstraintMaker *make) {
  398. make.left.mas_equalTo(0.0);
  399. make.right.mas_equalTo(0.0);
  400. make.top.mas_equalTo(0.0);
  401. make.bottom.mas_equalTo(0.0);
  402. }];
  403. KWeakSelf
  404. _reNameRecordFileV.didClickOkButtonFun = ^(NSString * _Nonnull newName) {
  405. [weakSelf checkRenameByNewName:newName withRow:row];
  406. };
  407. }
  408. #pragma mark 重命名逻辑
  409. - (void)checkRenameByNewName:(NSString*)newName withRow:(NSInteger)row
  410. {
  411. [_reNameRecordFileV removeFromSuperview];
  412. if (!newName || newName.length == 0) {
  413. NSString *tip = NSLocalizedString(@"record_reName_error_tip",nil);
  414. [[iToast makeText:tip] show];
  415. return;
  416. }
  417. recordFileModel *model = nil;
  418. if (_audioArr.count > row) {
  419. model = _audioArr[row];
  420. }
  421. else{
  422. return;
  423. }
  424. BOOL isRepeatType = NO;
  425. for (int i=0; i<_audioArr.count; i++) {
  426. if (i != row) {
  427. recordFileModel *preModel = _audioArr[i];
  428. if ([preModel.fileName isEqualToString:newName]) {
  429. isRepeatType = YES;
  430. break;
  431. }
  432. }
  433. }
  434. if (isRepeatType) {
  435. NSString *tip = NSLocalizedString(@"record_reName_error_repeat_tip",nil);
  436. [[iToast makeText:tip] show];
  437. return;
  438. }
  439. //[_reNameRecordFileV removeFromSuperview];
  440. // 获取文件管理器
  441. NSFileManager *fileManager = [NSFileManager defaultManager];
  442. // 原始文件路径
  443. NSString *documentsPath = kSHPath_Record;
  444. NSString *oldFilePath = [documentsPath stringByAppendingPathComponent:model.fileName];
  445. // 新文件路径
  446. NSString *newFilePath = [documentsPath stringByAppendingPathComponent:newName];
  447. NSError *error = nil;
  448. // 重命名/移动文件
  449. BOOL success = [fileManager moveItemAtPath:oldFilePath toPath:newFilePath error:&error];
  450. if (!success) {
  451. NSString *tip = NSLocalizedString(@"record_reName_error_title",nil);
  452. [[iToast makeText:tip] show];
  453. } else {
  454. NSString *tip = NSLocalizedString(@"record_reName_ok_title",nil);
  455. [[iToast makeText:tip] show];
  456. model.fileName = newName;
  457. [_tableView reloadData];
  458. }
  459. }
  460. #pragma mark 文件删除弹框
  461. - (void)showDeleteAlearViewFun
  462. {
  463. [self deleteFileByRow:-1];
  464. }
  465. #pragma mark 文件删除
  466. - (void)deleteFileByRow:(NSInteger)row
  467. {
  468. KWeakSelf
  469. /*弹窗提示重启*/
  470. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"delete_file_title_msg",nil)
  471. msg:NSLocalizedString(@"delete_file_tip_msg",nil)
  472. imageStr:@""
  473. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  474. okTitle:NSLocalizedString(@"delete_file_title_msg",nil) isOkBtnHighlight:YES
  475. didClickOk:^{
  476. [weakSelf sureDeleteFileByRow:row];
  477. } didClickCancel:^{
  478. }];
  479. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  480. [self presentViewController:nextVC animated:YES completion:^{
  481. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  482. }];
  483. }
  484. #pragma mark 文件删除
  485. - (void)sureDeleteFileByRow:(NSInteger)row
  486. {
  487. if (row == -1) {//删除编辑状态选中的旋转
  488. [self deleteSelectFileFun];
  489. return;
  490. }
  491. recordFileModel *model = nil;
  492. if (_audioArr.count > row) {
  493. model = _audioArr[row];
  494. }
  495. else{
  496. return;
  497. }
  498. NSFileManager *fileManager = [NSFileManager defaultManager];
  499. NSString *filePath = model.filePath; // 获取要删除的文件路径
  500. NSError *error = nil;
  501. BOOL success = [fileManager removeItemAtPath:filePath error:&error];
  502. if (!success) {
  503. //NSLog(@"删除文件失败: %@", error.localizedDescription);
  504. [[iToast makeText:NSLocalizedString(@"record_deleteFile_fail",nil)] show];
  505. } else {
  506. //NSLog(@"文件删除成功");
  507. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  508. [_audioArr removeObject:model];
  509. recordFileModel *firstModel = _audioArr.firstObject;
  510. firstModel.showAllType = YES;
  511. [_tableView reloadData];
  512. }
  513. }
  514. #pragma mark 删除编辑状态选中的旋转
  515. - (void)deleteSelectFileFun
  516. {
  517. NSFileManager *fileManager = [NSFileManager defaultManager];
  518. for (recordFileModel*delModel in _didSelectListArr) {
  519. NSString *filePath = delModel.filePath; // 获取要删除的文件路径
  520. NSError *error = nil;
  521. BOOL success = [fileManager removeItemAtPath:filePath error:&error];
  522. if (!success) {
  523. //NSLog(@"删除文件失败: %@", error.localizedDescription);
  524. //[[iToast makeText:NSLocalizedString(@"record_deleteFile_fail",nil)] show];
  525. } else {
  526. //NSLog(@"文件删除成功");
  527. //[[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  528. [_audioArr removeObject:delModel];
  529. }
  530. }
  531. // recordFileModel *firstModel = _audioArr.firstObject;
  532. // firstModel.showAllType = YES;
  533. [_tableView reloadData];
  534. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  535. [_didSelectListArr removeAllObjects];
  536. [self setEditTypeTitleFun];
  537. }
  538. #pragma mark 点击了编辑按钮
  539. - (void)didClickEditFun
  540. {
  541. _isEditType = YES;
  542. _curEditTypeHeadView.hidden = NO;
  543. _curEditTypeBottomView.hidden = NO;
  544. _recordBottomV.hidden = YES;
  545. [self setEditTypeTitleFun];
  546. for (recordFileModel*model in _audioArr) {
  547. model.showAllType = NO;
  548. model.isEditType = YES;
  549. }
  550. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  551. make.left.mas_equalTo(0);
  552. make.right.mas_equalTo(0);
  553. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  554. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  555. }];
  556. [self.tableView reloadData];
  557. }
  558. #pragma mark 用户取消编辑编辑
  559. - (void)userCancelEditTypeFun
  560. {
  561. //数据还原
  562. for (recordFileModel*model in _didSelectListArr) {
  563. model.isSelectType = NO;
  564. }
  565. [_didSelectListArr removeAllObjects];
  566. for (recordFileModel*model in _audioArr) {
  567. model.isEditType = NO;
  568. }
  569. recordFileModel*firstModel = _audioArr.firstObject;
  570. firstModel.showAllType = YES;
  571. _isEditType = NO;
  572. [self.tableView reloadData];
  573. _curEditTypeHeadView.hidden = YES;
  574. _curEditTypeBottomView.hidden = YES;
  575. _recordBottomV.hidden = NO;
  576. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  577. make.left.mas_equalTo(0);
  578. make.right.mas_equalTo(0);
  579. make.bottom.equalTo(self.recordBottomV.mas_top).offset(0.f);
  580. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);;
  581. }];
  582. }
  583. - (void)didClickSelectAllButton:(UIButton*)button
  584. {
  585. //button.selected = !button.selected;
  586. [_didSelectListArr removeAllObjects];
  587. for (recordFileModel* dataModel in _audioArr) {
  588. if(!button.selected){
  589. dataModel.isSelectType = button.selected;
  590. }
  591. else{
  592. [_didSelectListArr addObject:dataModel];
  593. dataModel.isSelectType = button.selected;
  594. }
  595. }
  596. [self.tableView reloadData];
  597. [self setEditTypeTitleFun];
  598. }
  599. - (void)userCheckFilePreviewByRow:(NSInteger)row
  600. {
  601. if(row < _audioArr.count){
  602. recordFileModel* dataModel = _audioArr[row];
  603. if(dataModel.isSelectType){
  604. [_didSelectListArr removeObject:dataModel];
  605. }
  606. else{
  607. [_didSelectListArr addObject:dataModel];
  608. }
  609. dataModel.isSelectType = !dataModel.isSelectType;
  610. [self setEditTypeTitleFun];
  611. }
  612. }
  613. #pragma mark 设置选中标题
  614. - (void)setEditTypeTitleFun
  615. {
  616. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  617. if (_didSelectListArr.count > 0) {
  618. [_curEditTypeBottomView setButtonStateFunBy:YES];
  619. }
  620. else{
  621. [_curEditTypeBottomView setButtonStateFunBy:NO];
  622. }
  623. }
  624. #pragma mark 处理上传
  625. - (void)gotoUpLoadFileFun{
  626. if (_didSelectListArr.count <= 0) {
  627. return;
  628. }
  629. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  630. [self.navigationController pushViewController:vc animated:YES];
  631. vc.isUploadingType = YES;
  632. [vc gotoUploadFileByRecord:_didSelectListArr];
  633. }
  634. @end