// // backupsFilerecordTableView.m // 隐私保护 // // Created by xd h on 2024/1/4. // #import "backupsFilerecordTableView.h" #import "UIScrollView+EmptyDataSet.h" #import "backupsFileManager.h" #import "backupsFileRecordCell.h" @interface backupsFilerecordTableView() { NSMutableArray *backupsingArr; NSMutableArray *backupsfailArr; NSMutableArray *backupsDoneArr; } @property (nonatomic, strong) NSMutableArray *curDataArr; @end @implementation backupsFilerecordTableView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initCommon]; _selectModelArr = [NSMutableArray new]; _curDataArr = [NSMutableArray new]; backupsingArr = [NSMutableArray new]; backupsfailArr = [NSMutableArray new]; backupsDoneArr = [NSMutableArray new]; } return self; } - (void)initCommon { self.delegate = self; self.dataSource = self; self.showsVerticalScrollIndicator = NO; self.showsHorizontalScrollIndicator = NO; [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)]; [self setSeparatorColor:[UIColor clearColor]]; [self setBackgroundColor:[UIColor clearColor]]; [self setTableFooterView:[UIView new]]; [self setBounces:YES]; if (@available(iOS 15.0, *)) { self.sectionHeaderTopPadding = 0; } //空数据引入第三方开源处理 self.emptyDataSetSource = self; self.emptyDataSetDelegate = self; } - (void)setPhotosBackupsIngTaskModel:(photosBackupsTaskModel *)photosBackupsIngTaskModel { _photosBackupsIngTaskModel = photosBackupsIngTaskModel; // if(_photosBackupsIngTaskModel.curBackupsState == backupsStateDone){ // NSInteger i; // } if(backupsingArr.count >=1){ if(_photosBackupsIngTaskModel.curBackupsState == backupsStateUploading || _photosBackupsIngTaskModel.curBackupsState == backupsStateSuspend){ [backupsingArr replaceObjectAtIndex:0 withObject:_photosBackupsIngTaskModel]; } else if (_photosBackupsIngTaskModel.curBackupsState == backupsStateFail){ [backupsingArr removeObjectAtIndex:0]; [backupsfailArr insertObject:_photosBackupsIngTaskModel atIndex:0]; } else if (_photosBackupsIngTaskModel.curBackupsState == backupsStateDone){ [backupsingArr removeObjectAtIndex:0]; [backupsDoneArr insertObject:_photosBackupsIngTaskModel atIndex:0]; } } else if(_photosBackupsIngTaskModel.curBackupsState == backupsStateUploading) {//先进界面 再备份 [backupsingArr addObject:_photosBackupsIngTaskModel]; } NSMutableArray*newDataArr = [NSMutableArray new]; if(backupsingArr.count > 0){ [newDataArr addObject:backupsingArr]; } if(backupsfailArr.count > 0){ [newDataArr addObject:backupsfailArr]; } if(backupsDoneArr.count > 0){ [newDataArr addObject:backupsDoneArr]; } _curDataArr = newDataArr; [self reloadDataFun]; } -(void)setOutSideDataArr:(NSArray *)outSideDataArr { _outSideDataArr = outSideDataArr; [backupsingArr removeAllObjects]; [backupsfailArr removeAllObjects]; [backupsDoneArr removeAllObjects]; if(outSideDataArr && outSideDataArr.count >0){ for (photosBackupsTaskModel*model in outSideDataArr) { if(model.curBackupsState == backupsStateUploading ||model.curBackupsState == backupsStateSuspend){ [backupsingArr addObject:model]; } else if(model.curBackupsState == backupsStateFail){ [backupsfailArr addObject:model]; } else{ [backupsDoneArr addObject:model]; } } } if(backupsingArr.count > 0){ [_curDataArr addObject:backupsingArr]; } if(backupsfailArr.count > 0){ [_curDataArr addObject:backupsfailArr]; } if(backupsDoneArr.count > 0){ [_curDataArr addObject:backupsDoneArr]; } [self reloadDataFun]; } #pragma mark - 列表委托 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _curDataArr.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(_curDataArr.count > section){ NSArray *curArr = _curDataArr[section]; return curArr.count; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger row = indexPath.row; NSInteger section = indexPath.section; static NSString *identifier = @"backupsFileRecordCell"; backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; if (!cell){ cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setBackgroundColor:[UIColor clearColor]]; [cell setAccessoryType:(UITableViewCellAccessoryNone)]; } if(section <_curDataArr.count){ NSMutableArray *curArr = _curDataArr[section]; if(row < curArr.count){ photosBackupsTaskModel *model = curArr[row]; cell.curPhotosBackupsTaskModel = model; //cell.isEditType = _isEditType; if(_isEditType){ if([_selectModelArr containsObject:model]){ cell.isSelectType = YES; } else{ cell.isSelectType = NO; } } KWeakSelf cell.didLongPressClick = ^{ //[weakSelf didLongPressClickFun]; }; cell.didClckSelectBut = ^(BOOL isSelect) { //[weakSelf selectModelOneByOne:model BySelect:isSelect]; }; cell.didTapPressClick = ^{ if(model.curBackupsState == backupsStateUploading){ [weakSelf handleBackupsingStateTapFunBy:YES with:model]; } else if(model.curBackupsState == backupsStateSuspend){ [weakSelf handleBackupsingStateTapFunBy:NO with:model]; } }; } } return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70; } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* headView = [UIView new]; headView.backgroundColor = [UIColor whiteColor]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)]; titleLabel.font = [UIFont systemFontOfSize:12.0]; titleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0]; [headView addSubview:titleLabel]; NSInteger curType = 0;// 0 上传中 1 失败 2 完成 if(section == 2){ curType = 2; } else if(section == 1){ if(backupsingArr.count == 0){ curType = 2; } else if(backupsfailArr.count == 0){ curType = 2; } else{ curType = 1; } } else{ if(backupsingArr.count > 0){ curType = 0; } else if(backupsfailArr.count > 0){ curType = 1; } else{ curType = 2; } } NSString *text = @""; if(curType == 0){ text = NSLocalizedString(@"File_Transfer_List_head_title_ing",nil); text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsingArr.count]; } else if(curType == 1){ text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil); text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsfailArr.count]; } else{ text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil); text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsDoneArr.count]; } titleLabel.text = text; return headView; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 50; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; } #pragma mark 空数据 - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView { NSString *imageName = @"uploadFile_noData"; if(self.tag == 101){ imageName = @"uploadFile_noData"; } else if(self.tag == 102){ imageName = @"uploadFile_noData"; } return [UIImage imageNamed:imageName]; } - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView { NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil); if(self.tag == 101){ text = NSLocalizedString(@"File_download_Record_no_data",nil); } else if(self.tag == 102){ text = NSLocalizedString(@"File_backups_Record_no_data",nil); } NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f], NSForegroundColorAttributeName: HW999999Color}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; } //调整图片位置 - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView { return -150; } -(void)reloadDataFun{ mainBlock(^{ [self RefresHeadUIFun]; [self reloadData]; }); } #pragma mark 熟悉头部数据 -(void)RefresHeadUIFun { uploadFileRecordTableViewHeadView *headView = (uploadFileRecordTableViewHeadView *)self.tableHeaderView; if(!headView || ![headView isKindOfClass:[uploadFileRecordTableViewHeadView class]]){ return; } if(!_curDataArr ||_curDataArr.count ==0){ headView.hidden = YES; return; } headView.hidden = NO; NSInteger tag = self.tag; if(tag == 100){ NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil); NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil); NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil); NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count]; headView.titleLabel.text = titleStr; [headView.rightButton setTitle:rightStr forState:UIControlStateNormal]; [headView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected]; } else if(tag == 101){ NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil); NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil); NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count]; headView.titleLabel.text = titleStr; [headView.rightButton setTitle:rightStr forState:UIControlStateNormal]; } else if(tag == 102){ NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil); NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil); NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count]; headView.titleLabel.text = titleStr; [headView.rightButton setTitle:rightStr forState:UIControlStateNormal]; } } #pragma mark 点击全选 - (void)setIsSelectAllType:(BOOL)isSelectAllType { _selectModelArr = [NSMutableArray arrayWithArray:_curDataArr]; [self reloadDataFun]; } -(void)setIsEditType:(BOOL)isEditType { _isEditType = isEditType; if(_isEditType){ //_bgScrollV.scrollEnabled = NO; } else{ //_bgScrollV.scrollEnabled = YES; [_selectModelArr removeAllObjects]; } [self reloadDataFun]; } #pragma mark cell长按时间 - (void)didLongPressClickFun{ self.isEditType = YES; if(self->_didLongPressClick){ self->_didLongPressClick(); } } #pragma mark 单个点击选中 取消 - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet { if(isSelcet){ [_selectModelArr addObject:model]; } else{ [_selectModelArr removeObject:model]; } } #pragma mark 单个点击选中后删除 - (void)deleteModelOneByOneFun{ // if(!_selectModelArr || _selectModelArr.count==0){ // // return; // } // // KWeakSelf // [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) { // HLog(@"isSuccess:%d",isSuccess); // // if(isSuccess){ // NSMutableArray *curArr = self->_curDataArr; // [curArr removeObjectsInArray:self->_selectModelArr]; // [weakSelf reloadDataFun]; // self->_selectModelArr = [NSMutableArray new]; // } // }]; } #pragma mark 处理上传中的 状态点击事件 - (void)handleBackupsingStateTapFunBy:(BOOL)isSuspendType with:(photosBackupsTaskModel*)model { if (isSuspendType) { model.isSuspendType = YES; model.curBackupsState = backupsStateSuspend; [[backupsFileManager shareInstance] suspendBackupsFileFun]; } else{ [[backupsFileManager shareInstance] reBackupsFileFunBy:model]; } } #pragma mark 处理上传中的 状态点击事件 - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{ // [_curDataArr removeObject:model]; // [self reloadDataFun]; // // if(_didClickReUploadBlock){ // _didClickReUploadBlock(model); // } // // NSMutableArray*arr = [NSMutableArray new]; // model.curUploadStateType = uploadStateWait; // [arr addObject:model]; // [[uploadFileManager shareInstance] reUploadFileFunBy:arr]; } @end