// // nasLastFileViewController.m // Private-X // // Created by xd h on 2024/7/9. // #import "nasLastFileViewController.h" #import "lastFileTableViewCell.h" #import "editTypeHeadView.h" #import "editTypeBottomView.h" #import "downloadManager.h" #import "uploadFileRecordViewController.h" #import "queryShareModel.h" #import "audioPlayerViewController.h" #import "videoPlayByAVPlayerViewController.h" #import "imageDetailsScrollViewController.h" #import "editShareView.h" #import "ComontAlretDeleteTypeViewController.h" @interface nasLastFileViewController () { BOOL canShareType; } @property(nonatomic,strong) UITableView*tableView; @property (nonatomic,strong) NSMutableArray *lastFileDataArr; @property(nonatomic,assign) BOOL isEditType; @property(nonatomic,strong) editTypeHeadView*curEditTypeHeadView; @property(nonatomic,strong) editTypeBottomView*curEditTypeBottomView; @property (nonatomic, strong) NSMutableArray*didSelectListArr;//选中的数据 @end @implementation nasLastFileViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor whiteColor]; //[self.view setBackgroundColor:[UIColor hwColor:@"#F6F8FA"]]; [self.view setBackgroundColor:[UIColor whiteColor]]; self.titleLabel.text = NSLocalizedString(@"NAS_last_file",nil); [self drawAnyView]; _didSelectListArr = [NSMutableArray new]; //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:2 withEventValue:@"Recently"]; } - (void)drawAnyView{ [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); //make.bottom.mas_equalTo(-(safeArea)); make.bottom.mas_equalTo(0); make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); }]; _curEditTypeHeadView = [[editTypeHeadView alloc] init]; _curEditTypeHeadView.hidden = YES; [self.navBarBGView addSubview:_curEditTypeHeadView]; [_curEditTypeHeadView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(NAVIHEIGHT - AdaptNaviHeight); }]; #pragma mark 编辑状态的 取消 和全选按钮 响应事件 KWeakSelf _curEditTypeHeadView.didClickButtonFun = ^(NSInteger tag) { if(tag==1){ [weakSelf userCancelEditTypeFun]; } }; _curEditTypeHeadView.didClickSelectAllFun = ^(UIButton * _Nonnull but) { [weakSelf didClickSelectAllButton:but]; }; _curEditTypeBottomView = [[editTypeBottomView alloc] init]; _curEditTypeBottomView.hidden = YES; [self.view addSubview:_curEditTypeBottomView]; [_curEditTypeBottomView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.height.mas_equalTo(60 + AdaptTabHeight); }]; #pragma mark 编辑状态的 下载 分享 删除 响应事件 _curEditTypeBottomView.didClickButtonFun = ^(NSInteger tag) { if(tag==1){ [weakSelf gotoDownLoadFileFun]; } else if(tag==2){ [weakSelf gotoShareViewFun]; } else if(tag==3){ [weakSelf showDeleteAlearViewFun]; } }; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); //make.bottom.mas_equalTo(-(safeArea)); make.bottom.mas_equalTo(0); make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); }]; } #pragma mark - 懒加载 - (UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.showsVerticalScrollIndicator = NO; _tableView.showsHorizontalScrollIndicator = NO; // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0); [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; [_tableView setSeparatorColor:[UIColor clearColor]]; [_tableView setBackgroundColor:[UIColor clearColor]]; [_tableView setTableFooterView:[UIView new]]; [_tableView setBounces:YES]; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } //空数据引入第三方开源处理 _tableView.emptyDataSetSource = self; _tableView.emptyDataSetDelegate = self; } return _tableView; } #pragma mark - 列表委托 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(!_lastFileDataArr){ return 0; } return _lastFileDataArr.count; } - (lastFileTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ __block NSInteger row = indexPath.row; static NSString *identifier = @"lastFileTableViewCell"; lastFileTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; if (!cell){ cell = [[lastFileTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setBackgroundColor:[UIColor clearColor]]; [cell setAccessoryType:(UITableViewCellAccessoryNone)]; [cell hideCheckButtonBy:NO]; } if(row < _lastFileDataArr.count){ lastFileModel* dataModel = _lastFileDataArr[row]; cell.curLastFileModel = dataModel; KWeakSelf cell.didClickSwitch = ^(BOOL SwitchOn) { [weakSelf userCheckFilePreviewByRow:row]; }; } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 84; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = indexPath.row; if(row < _lastFileDataArr.count){ lastFileModel* dataModel = _lastFileDataArr[row]; if([dataModel.type isEqualToString:@"video"]){ videoPlayByAVPlayerViewController *vc = [videoPlayByAVPlayerViewController new]; vc.VideoDataMode = (NASFileAndFolderDataModel*)dataModel; [self.navigationController pushViewController:vc animated:YES]; KWeakSelf vc.didNeedDeleteFile = ^(NSString * _Nonnull filePath) { [weakSelf getLastFileDataFun]; }; } else if([dataModel.type isEqualToString:@"audio"]){ // NSMutableArray *audioDataArr = [NSMutableArray new]; // NSInteger index = 0; // // for (int i=0; i<_lastFileDataArr.count; i++) { // lastFileModel* audioDataModel = _lastFileDataArr[i]; // if([dataModel.type isEqualToString:@"audio"]){ // // if(i == row){ // index = audioDataArr.count; // } // // [audioDataArr addObject:audioDataModel]; // } // } audioPlayerViewController *vc = [audioPlayerViewController new]; vc.isfirstEnterType = YES; vc.outSideDataModel = (NASFileAudioDataModel *)dataModel; [self.navigationController pushViewController:vc animated:YES]; KWeakSelf vc.didNeedDeleteFile = ^(NSString * _Nonnull filePath) { [weakSelf getLastFileDataFun]; }; } else if([dataModel.type containsString:@"jpg"]){ NSMutableArray *jpgDataArr = [NSMutableArray new]; NSInteger index = 0; for (int i=0; i<_lastFileDataArr.count; i++) { lastFileModel* jpgDataModel = _lastFileDataArr[i]; if([dataModel.type containsString:@"jpg"]){ if(i == row){ index = jpgDataArr.count; } [jpgDataArr addObject:jpgDataModel]; } } imageDetailsScrollViewController *vc = [imageDetailsScrollViewController new]; vc.index = index; vc.totalDataArr = jpgDataArr; [self.navigationController pushViewController:vc animated:YES]; vc.canShareType = canShareType; } } } #pragma mark 空数据 - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView { NSString *imageName = @"nas_not_data"; return [UIImage imageNamed:imageName]; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = NSLocalizedString(@"NAS_last_file_not_data_tip",nil); NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f], NSForegroundColorAttributeName: HW999999Color}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; } //调整图片位置 - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView { return -150; } #pragma mark 用户长按图片进入编辑 - (void)setViewEditTypeFun { _isEditType = YES; //[self.tableView reloadData]; _curEditTypeHeadView.hidden = NO; _curEditTypeBottomView.hidden = NO; [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(_curEditTypeBottomView.mas_top); make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); }]; } #pragma mark 用户取消编辑编辑 - (void)userCancelEditTypeFun { //数据还原 for (lastFileModel*model in _didSelectListArr) { model.isSelectType = NO; } [_didSelectListArr removeAllObjects]; _isEditType = NO; [self.tableView reloadData]; _curEditTypeHeadView.hidden = YES; _curEditTypeBottomView.hidden = YES; [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.equalTo(self.navBarBGView.mas_bottom).offset(10.f); }]; } - (void)userCheckFilePreviewByRow:(NSInteger)row { if(row < _lastFileDataArr.count){ lastFileModel* dataModel = _lastFileDataArr[row]; if(dataModel.isSelectType){ [_didSelectListArr removeObject:dataModel]; } else{ [_didSelectListArr addObject:dataModel]; } dataModel.isSelectType = !dataModel.isSelectType; [self setEditTypeTitleFun]; } } - (void)didClickSelectAllButton:(UIButton*)button { //button.selected = !button.selected; [_didSelectListArr removeAllObjects]; for (lastFileModel* dataModel in _lastFileDataArr) { if(!button.selected){ dataModel.isSelectType = button.selected; } else{ [_didSelectListArr addObject:dataModel]; dataModel.isSelectType = button.selected; } } [self.tableView reloadData]; [self setEditTypeTitleFun]; } #pragma mark 设置选中标题 - (void)setEditTypeTitleFun { [_curEditTypeHeadView setTitleLabetextByNumbers:_didSelectListArr.count]; if(_didSelectListArr.count > 0){ [self setViewEditTypeFun]; } else{ [self userCancelEditTypeFun]; } } #pragma mark 删除图片 - (void)showDeleteAlearViewFun { NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil); NSString *tipStr = NSLocalizedString(@"NAS_last_file_del_tip",nil); KWeakSelf ComontAlretDeleteTypeViewController *curAlretVC= [[ComontAlretDeleteTypeViewController alloc] initWithTitle:titleStr msg:tipStr imageStr:nil cancelTitle:NSLocalizedString(@"other_cancel",nil) okTitle:NSLocalizedString(@"other_confirm",nil) otherTitle:NSLocalizedString(@"NAS_last_file_del_cloudFile_tip",nil) isOkBtnHighlight:YES didClickOk:^(BOOL isDeleteAll) { [weakSelf didClickDeleteOkButBy:isDeleteAll]; } didClickCancel:^{ }]; curAlretVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:curAlretVC animated:YES completion:^{ curAlretVC.view.superview.backgroundColor = [UIColor clearColor]; }]; } - (void)didClickDeleteOkButBy:(NSInteger)isDeleteCloudFile { //1.删除本地数据 for (NASFilePicDataArrModel *dataModel in _didSelectListArr) { [[lastFileManager shareManager] deleteFileInfoWithUrl:dataModel.path]; } //2.删除云机文件 if(isDeleteCloudFile){ [self delFileListFun]; } else{ [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show]; [self didDeleteSucFun]; } } #pragma mark 删除文件数据 - (void)delFileListFun { //处理数据埋点 NSString * firstFileType = nil; BOOL isSameFileType = YES; for (NASFilePicDataArrModel *dataModel in _didSelectListArr) { if(!firstFileType){ firstFileType = dataModel.type; } else if(![firstFileType isEqualToString:dataModel.type]){ isSameFileType = NO; break; } } if(!isSameFileType){ //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"]; } else if([firstFileType containsString:@"jpg"]){ //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Image_delete"]; } else if([firstFileType isEqualToString:@"video"]){ //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"]; } else if([firstFileType isEqualToString:@"audio"]){ //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Music_delete"]; } else{ //数据埋点 [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"File_delete"]; } NSMutableDictionary*paraDict = [NSMutableDictionary new]; NSMutableArray *pathArr = [NSMutableArray new]; for (NASFilePicDataArrModel *dataModel in _didSelectListArr) { [pathArr addObject:dataModel.path]; } [paraDict setValue:pathArr forKey:@"path"]; [self showNewIndicatorWithCanBack:YES canTouch:NO]; //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC] KWeakSelf //@"delFile" [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) { [weakSelf removeNewIndicator]; SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil]; if(model && model.status == 0){ [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show]; [weakSelf didDeleteSucFun]; } else{ } } failure:^(NSError * _Nonnull error) { [weakSelf removeNewIndicator]; }]; } #pragma mark 删除成功 - (void)didDeleteSucFun { [_didSelectListArr removeAllObjects]; [self setEditTypeTitleFun]; [self getLastFileDataFun]; } #pragma mark 文件下载 - (void)gotoDownLoadFileFun { if(_didSelectListArr.count == 0){ [[iToast makeText:@""] show]; return; } NSMutableArray *arr = [NSMutableArray new]; for (lastFileModel *dataModel in _didSelectListArr) { couldPhoneFileModel* fileModel = [couldPhoneFileModel new]; fileModel.fileType = dataModel.type; fileModel.path = dataModel.path; fileModel.name = dataModel.name; fileModel.length = dataModel.size; fileModel.time = dataModel.duration; [arr addObject:fileModel]; } uploadFileRecordViewController *vc = [uploadFileRecordViewController new]; [self.navigationController pushViewController:vc animated:YES]; vc.isDownloadingType = YES; [vc gotoDownloadFile:arr]; } #pragma mark 用户点击分享 - (void)gotoShareViewFun { if (_didSelectListArr.count > 5) { [[iToast makeText:NSLocalizedString(@"share_max_count_tip2",nil)] show]; return; } editShareView *editShareV = [[editShareView alloc] init]; editShareV.didSelectListArr = _didSelectListArr; editShareV.shareFileType = @"6"; editShareV.isLastFileType = YES; [self.view addSubview:editShareV]; [editShareV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(0); make.top.mas_equalTo(0); }]; } #pragma mark 获取分享开关 -(void)queryShareSwitchFunFun { NSMutableDictionary *paraDict = [NSMutableDictionary new]; [paraDict setValue:@7 forKey:@"type"]; KWeakSelf [[netWorkManager shareInstance] CommonGetWithCallBackCode:queryShareSwitchFun Parameters:paraDict success:^(id _Nonnull responseObject){ queryShareModel *queryShareMod = [[queryShareModel alloc] initWithDictionary:responseObject error:nil]; if(queryShareMod){ self->canShareType = queryShareMod.data.configValue; [weakSelf.curEditTypeBottomView setCanShaewFunBy:queryShareMod.data.configValue]; } } failure:^(NSError * _Nonnull error) { }]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self getLastFileDataFun]; [self queryShareSwitchFunFun]; } #pragma mark 获取最近文件数据 - (void)getLastFileDataFun { _lastFileDataArr = [lastFileManager shareManager].lastFileListArr; //HLog(@"%@",_lastFileDataArr); [self.tableView reloadData]; } @end