nasLastFileViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. //
  2. // nasLastFileViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/9.
  6. //
  7. #import "nasLastFileViewController.h"
  8. #import "lastFileTableViewCell.h"
  9. #import "editTypeHeadView.h"
  10. #import "editTypeBottomView.h"
  11. #import "downloadManager.h"
  12. #import "uploadFileRecordViewController.h"
  13. #import "queryShareModel.h"
  14. #import "audioPlayerViewController.h"
  15. #import "videoPlayByAVPlayerViewController.h"
  16. #import "imageDetailsScrollViewController.h"
  17. #import "editShareView.h"
  18. #import "ComontAlretDeleteTypeViewController.h"
  19. @interface nasLastFileViewController ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  20. {
  21. BOOL canShareType;
  22. }
  23. @property(nonatomic,strong) UITableView*tableView;
  24. @property (nonatomic,strong) NSMutableArray *lastFileDataArr;
  25. @property(nonatomic,assign) BOOL isEditType;
  26. @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView;
  27. @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView;
  28. @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据
  29. @end
  30. @implementation nasLastFileViewController
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. // Do any additional setup after loading the view.
  34. [self.toolBar setHidden:YES];
  35. [self.navigationBar setHidden:YES];
  36. [self.navBarBGView setHidden:NO];
  37. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  38. //[self.view setBackgroundColor:[UIColor hwColor:@"#F6F8FA"]];
  39. [self.view setBackgroundColor:[UIColor whiteColor]];
  40. self.titleLabel.text = NSLocalizedString(@"NAS_last_file",nil);
  41. [self drawAnyView];
  42. _didSelectListArr = [NSMutableArray new];
  43. //数据埋点
  44. [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Recently"];
  45. }
  46. - (void)drawAnyView{
  47. [self.view addSubview:self.tableView];
  48. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(0);
  50. make.right.mas_equalTo(0);
  51. //make.bottom.mas_equalTo(-(safeArea));
  52. make.bottom.mas_equalTo(0);
  53. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  54. }];
  55. _curEditTypeHeadView = [[editTypeHeadView alloc] init];
  56. _curEditTypeHeadView.hidden = YES;
  57. [self.navBarBGView addSubview:_curEditTypeHeadView];
  58. [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(0);
  60. make.right.mas_equalTo(0);
  61. make.bottom.mas_equalTo(0);
  62. make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight);
  63. }];
  64. #pragma mark 编辑状态的 取消 和全选按钮 响应事件
  65. KWeakSelf
  66. _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) {
  67. if(tag==1){
  68. [weakSelf userCancelEditTypeFun];
  69. }
  70. };
  71. _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) {
  72. [weakSelf didClickSelectAllButton:but];
  73. };
  74. _curEditTypeBottomView = [[editTypeBottomView alloc] init];
  75. _curEditTypeBottomView.hidden = YES;
  76. [self.view addSubview:_curEditTypeBottomView];
  77. [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(0);
  79. make.right.mas_equalTo(0);
  80. make.bottom.mas_equalTo(0);
  81. make.height.mas_equalTo(60 + AdaptTabHeight);
  82. }];
  83. #pragma mark 编辑状态的 下载 分享 删除 响应事件
  84. _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) {
  85. if(tag==1){
  86. [weakSelf gotoDownLoadFileFun];
  87. }
  88. else if(tag==2){
  89. [weakSelf gotoShareViewFun];
  90. }
  91. else if(tag==3){
  92. [weakSelf showDeleteAlearViewFun];
  93. }
  94. };
  95. [self.view addSubview:self.tableView];
  96. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(0);
  98. make.right.mas_equalTo(0);
  99. //make.bottom.mas_equalTo(-(safeArea));
  100. make.bottom.mas_equalTo(0);
  101. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  102. }];
  103. }
  104. #pragma mark - 懒加载
  105. - (UITableView *)tableView{
  106. if (!_tableView) {
  107. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
  108. _tableView.delegate = self;
  109. _tableView.dataSource = self;
  110. _tableView.showsVerticalScrollIndicator = NO;
  111. _tableView.showsHorizontalScrollIndicator = NO;
  112. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  113. [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  114. [_tableView setSeparatorColor:[UIColor clearColor]];
  115. [_tableView setBackgroundColor:[UIColor clearColor]];
  116. [_tableView setTableFooterView:[UIView new]];
  117. [_tableView setBounces:YES];
  118. if (@available(iOS 15.0, *)) {
  119. _tableView.sectionHeaderTopPadding = 0;
  120. }
  121. //空数据引入第三方开源处理
  122. _tableView.emptyDataSetSource = self;
  123. _tableView.emptyDataSetDelegate = self;
  124. }
  125. return _tableView;
  126. }
  127. #pragma mark - 列表委托
  128. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  129. return 1;
  130. }
  131. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  132. if(!_lastFileDataArr){
  133. return 0;
  134. }
  135. return _lastFileDataArr.count;
  136. }
  137. - (lastFileTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  138. __block NSInteger row = indexPath.row;
  139. static NSString *identifier = @"lastFileTableViewCell";
  140. lastFileTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  141. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  142. if (!cell){
  143. cell = [[lastFileTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  144. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  145. [cell setBackgroundColor:[UIColor clearColor]];
  146. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  147. [cell hideCheckButtonBy:NO];
  148. }
  149. if(row < _lastFileDataArr.count){
  150. lastFileModel* dataModel = _lastFileDataArr[row];
  151. cell.curLastFileModel = dataModel;
  152. KWeakSelf
  153. cell.didClickSwitch = ^(BOOL SwitchOn) {
  154. [weakSelf userCheckFilePreviewByRow:row];
  155. };
  156. }
  157. return cell;
  158. }
  159. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  160. return 84;
  161. }
  162. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  163. {
  164. NSInteger row = indexPath.row;
  165. if(row < _lastFileDataArr.count){
  166. lastFileModel* dataModel = _lastFileDataArr[row];
  167. if([dataModel.type isEqualToString:@"video"]){
  168. videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new];
  169. vc.VideoDataMode = (NASFileAndFolderDataModel*)dataModel;
  170. [self.navigationController pushViewController:vc animated:YES];
  171. KWeakSelf
  172. vc.didNeedDeleteFile = ^(NSString * _Nonnull filePath) {
  173. [weakSelf getLastFileDataFun];
  174. };
  175. }
  176. else if([dataModel.type isEqualToString:@"audio"]){
  177. // NSMutableArray *audioDataArr = [NSMutableArray new];
  178. // NSInteger index = 0;
  179. //
  180. // for (int i=0; i<_lastFileDataArr.count; i++) {
  181. // lastFileModel* audioDataModel = _lastFileDataArr[i];
  182. // if([dataModel.type isEqualToString:@"audio"]){
  183. //
  184. // if(i == row){
  185. // index = audioDataArr.count;
  186. // }
  187. //
  188. // [audioDataArr addObject:audioDataModel];
  189. // }
  190. // }
  191. audioPlayerViewController *vc = [audioPlayerViewController new];
  192. vc.isfirstEnterType = YES;
  193. vc.outSideDataModel = (NASFileAudioDataModel *)dataModel;
  194. [self.navigationController pushViewController:vc animated:YES];
  195. KWeakSelf
  196. vc.didNeedDeleteFile = ^(NSString * _Nonnull filePath) {
  197. [weakSelf getLastFileDataFun];
  198. };
  199. }
  200. else if([dataModel.type containsString:@"jpg"]){
  201. NSMutableArray *jpgDataArr = [NSMutableArray new];
  202. NSInteger index = 0;
  203. for (int i=0; i<_lastFileDataArr.count; i++) {
  204. lastFileModel* jpgDataModel = _lastFileDataArr[i];
  205. if([dataModel.type containsString:@"jpg"]){
  206. if(i == row){
  207. index = jpgDataArr.count;
  208. }
  209. [jpgDataArr addObject:jpgDataModel];
  210. }
  211. }
  212. imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new];
  213. vc.index = index;
  214. vc.totalDataArr = jpgDataArr;
  215. [self.navigationController pushViewController:vc animated:YES];
  216. vc.canShareType = canShareType;
  217. }
  218. }
  219. }
  220. #pragma mark 空数据
  221. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  222. NSString *imageName = @"nas_not_data";
  223. return [UIImage imageNamed:imageName];
  224. }
  225. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  226. NSString *text = NSLocalizedString(@"NAS_last_file_not_data_tip",nil);
  227. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  228. NSForegroundColorAttributeName: HW999999Color};
  229. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  230. }
  231. //调整图片位置
  232. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  233. return -150;
  234. }
  235. #pragma mark 用户长按图片进入编辑
  236. - (void)setViewEditTypeFun
  237. {
  238. _isEditType = YES;
  239. //[self.tableView reloadData];
  240. _curEditTypeHeadView.hidden = NO;
  241. _curEditTypeBottomView.hidden = NO;
  242. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  243. make.left.mas_equalTo(0);
  244. make.right.mas_equalTo(0);
  245. make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top);
  246. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  247. }];
  248. }
  249. #pragma mark 用户取消编辑编辑
  250. - (void)userCancelEditTypeFun
  251. {
  252. //数据还原
  253. for (lastFileModel*model in _didSelectListArr) {
  254. model.isSelectType = NO;
  255. }
  256. [_didSelectListArr removeAllObjects];
  257. _isEditType = NO;
  258. [self.tableView reloadData];
  259. _curEditTypeHeadView.hidden = YES;
  260. _curEditTypeBottomView.hidden = YES;
  261. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  262. make.left.mas_equalTo(0);
  263. make.right.mas_equalTo(0);
  264. make.bottom.mas_equalTo(0);
  265. make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f);
  266. }];
  267. }
  268. - (void)userCheckFilePreviewByRow:(NSInteger)row
  269. {
  270. if(row < _lastFileDataArr.count){
  271. lastFileModel* dataModel = _lastFileDataArr[row];
  272. if(dataModel.isSelectType){
  273. [_didSelectListArr removeObject:dataModel];
  274. }
  275. else{
  276. [_didSelectListArr addObject:dataModel];
  277. }
  278. dataModel.isSelectType = !dataModel.isSelectType;
  279. [self setEditTypeTitleFun];
  280. }
  281. }
  282. - (void)didClickSelectAllButton:(UIButton*)button
  283. {
  284. //button.selected = !button.selected;
  285. [_didSelectListArr removeAllObjects];
  286. for (lastFileModel* dataModel in _lastFileDataArr) {
  287. if(!button.selected){
  288. dataModel.isSelectType = button.selected;
  289. }
  290. else{
  291. [_didSelectListArr addObject:dataModel];
  292. dataModel.isSelectType = button.selected;
  293. }
  294. }
  295. [self.tableView reloadData];
  296. [self setEditTypeTitleFun];
  297. }
  298. #pragma mark 设置选中标题
  299. - (void)setEditTypeTitleFun
  300. {
  301. [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count];
  302. if(_didSelectListArr.count > 0){
  303. [self setViewEditTypeFun];
  304. }
  305. else{
  306. [self userCancelEditTypeFun];
  307. }
  308. }
  309. #pragma mark 删除图片
  310. - (void)showDeleteAlearViewFun
  311. {
  312. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  313. NSString *tipStr = NSLocalizedString(@"NAS_last_file_del_tip",nil);
  314. KWeakSelf
  315. ComontAlretDeleteTypeViewController *curAlretVC= [[ComontAlretDeleteTypeViewController alloc]
  316. initWithTitle:titleStr
  317. msg:tipStr
  318. imageStr:nil
  319. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  320. okTitle:NSLocalizedString(@"other_confirm",nil)
  321. otherTitle:NSLocalizedString(@"NAS_last_file_del_cloudFile_tip",nil)
  322. isOkBtnHighlight:YES
  323. didClickOk:^(BOOL isDeleteAll) {
  324. [weakSelf didClickDeleteOkButBy:isDeleteAll];
  325. } didClickCancel:^{
  326. }];
  327. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  328. [self presentViewController:curAlretVC animated:YES completion:^{
  329. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  330. }];
  331. }
  332. - (void)didClickDeleteOkButBy:(NSInteger)isDeleteCloudFile
  333. {
  334. //1.删除本地数据
  335. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  336. [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path];
  337. }
  338. //2.删除云机文件
  339. if(isDeleteCloudFile){
  340. [self delFileListFun];
  341. }
  342. else{
  343. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  344. [self didDeleteSucFun];
  345. }
  346. }
  347. #pragma mark 删除文件数据
  348. - (void)delFileListFun
  349. {
  350. //处理数据埋点
  351. NSString * firstFileType = nil;
  352. BOOL isSameFileType = YES;
  353. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  354. if(!firstFileType){
  355. firstFileType = dataModel.type;
  356. }
  357. else if(![firstFileType isEqualToString:dataModel.type]){
  358. isSameFileType = NO;
  359. break;
  360. }
  361. }
  362. if(!isSameFileType){
  363. //数据埋点
  364. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  365. }
  366. else if([firstFileType containsString:@"jpg"]){
  367. //数据埋点
  368. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"];
  369. }
  370. else if([firstFileType isEqualToString:@"video"]){
  371. //数据埋点
  372. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"];
  373. }
  374. else if([firstFileType isEqualToString:@"audio"]){
  375. //数据埋点
  376. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Music_delete"];
  377. }
  378. else{
  379. //数据埋点
  380. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"];
  381. }
  382. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  383. NSMutableArray *pathArr = [NSMutableArray new];
  384. for (NASFilePicDataArrModel *dataModel in _didSelectListArr) {
  385. [pathArr addObject:dataModel.path];
  386. }
  387. [paraDict setValue:pathArr forKey:@"path"];
  388. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  389. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  390. KWeakSelf //@"delFile"
  391. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  392. [weakSelf removeNewIndicator];
  393. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  394. if(model && model.status == 0){
  395. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  396. [weakSelf didDeleteSucFun];
  397. }
  398. else{
  399. }
  400. } failure:^(NSError * _Nonnull error) {
  401. [weakSelf removeNewIndicator];
  402. }];
  403. }
  404. #pragma mark 删除成功
  405. - (void)didDeleteSucFun
  406. {
  407. [_didSelectListArr removeAllObjects];
  408. [self setEditTypeTitleFun];
  409. [self getLastFileDataFun];
  410. }
  411. #pragma mark 文件下载
  412. - (void)gotoDownLoadFileFun
  413. {
  414. if(_didSelectListArr.count == 0){
  415. [[iToast makeText:@""] show];
  416. return;
  417. }
  418. NSMutableArray *arr = [NSMutableArray new];
  419. for (lastFileModel *dataModel in _didSelectListArr) {
  420. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  421. fileModel.fileType = dataModel.type;
  422. fileModel.path = dataModel.path;
  423. fileModel.name = dataModel.name;
  424. fileModel.length = dataModel.size;
  425. fileModel.time = dataModel.duration;
  426. [arr addObject:fileModel];
  427. }
  428. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  429. [self.navigationController pushViewController:vc animated:YES];
  430. vc.isDownloadingType = YES;
  431. [vc gotoDownloadFile:arr];
  432. }
  433. #pragma mark 用户点击分享
  434. - (void)gotoShareViewFun
  435. {
  436. if (_didSelectListArr.count > 5) {
  437. [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show];
  438. return;
  439. }
  440. editShareView *editShareV = [[editShareView alloc] init];
  441. editShareV.didSelectListArr = _didSelectListArr;
  442. editShareV.shareFileType = @"6";
  443. editShareV.isLastFileType = YES;
  444. [self.view addSubview:editShareV];
  445. [editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  446. make.left.mas_equalTo(0);
  447. make.right.mas_equalTo(0);
  448. make.bottom.mas_equalTo(0);
  449. make.top.mas_equalTo(0);
  450. }];
  451. }
  452. #pragma mark 获取分享开关
  453. -(void)queryShareSwitchFunFun
  454. {
  455. NSMutableDictionary *paraDict = [NSMutableDictionary new];
  456. [paraDict setValue:@7 forKey:@"type"];
  457. KWeakSelf
  458. [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){
  459. queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil];
  460. if(queryShareMod){
  461. self->canShareType = queryShareMod.data.configValue;
  462. [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue];
  463. }
  464. } failure:^(NSError * _Nonnull error) {
  465. }];
  466. }
  467. - (void)viewWillAppear:(BOOL)animated{
  468. [super viewWillAppear:animated];
  469. [self getLastFileDataFun];
  470. [self queryShareSwitchFunFun];
  471. }
  472. #pragma mark 获取最近文件数据
  473. - (void)getLastFileDataFun
  474. {
  475. _lastFileDataArr = [lastFileManager shareManager].lastFileListArr;
  476. //HLog(@"%@",_lastFileDataArr);
  477. [self.tableView reloadData];
  478. }
  479. @end