123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- //
- // uploadFileRecordTableView.m
- // 隐私保护
- //
- // Created by xd h on 2023/11/22.
- //
- #import "uploadFileRecordTableView.h"
- #import "uploadFileRecordCell.h"
- #import "UIScrollView+EmptyDataSet.h"
- #import "uploadFileManager.h"
- #import "uploadFileRecordTableViewHeadView.h"
- @interface uploadFileRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- {
-
- }
- @property (nonatomic, strong) NSMutableArray *curDataArr;
- @end
- @implementation uploadFileRecordTableView
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initCommon];
- [self initTableHeaderInSectionFun];
- _selectModelArr = [NSMutableArray new];
- _curDataArr = [NSMutableArray new];
- _isfirstRefreshType = YES;
- }
- 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)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
-
- if(!outSideDataArr || outSideDataArr.count != 3){
- return;
- }
-
- _outSideDataArr = outSideDataArr;
-
- _uploadingArr = outSideDataArr[0];
- _uploadDoneArr = outSideDataArr[1];
- _uploadfailArr = outSideDataArr[2];
-
- [self RefreshAllDataFun];
- }
- - (void)RefreshAllDataFun
- {
- NSMutableArray *totalArr = [NSMutableArray new];
-
- if(_uploadingArr.count>0){
- [totalArr addObject:_uploadingArr];
- }
-
- if(_uploadfailArr.count>0){
- [totalArr addObject:_uploadfailArr];
- }
-
- if(_uploadDoneArr.count>0){
- [totalArr addObject:_uploadDoneArr];
- }
-
- _curDataArr = totalArr;
-
- [self reloadDataFun];
- }
- #pragma mark - 列表委托
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return _curDataArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- if(section < _curDataArr.count){
- 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 = @"uploadFileRecordCell";
-
- uploadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (!cell){
- cell = [[uploadFileRecordCell 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){
- uploadFileDataModel *model = curArr[row];
- cell.curUploadFileDataModel = 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.curUploadStateType == uploadStateUploading){
- model.curUploadStateType = uploadStateSuspend;
- [weakSelf handleUploadingStateTapFunBy:YES with:model];
- }
- else if(model.curUploadStateType == uploadStateSuspend){
- model.curUploadStateType = uploadStateUploading;
- [weakSelf handleUploadingStateTapFunBy:NO with:model];
- }
- else if(model.curUploadStateType == uploadStateFail){
- [weakSelf handleUploadFailStateWith:model];
- }
- };
- }
- }
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 70;
- }
- - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- NSInteger curType = 0;// 0 上传中 1 失败 2 完成
- if(section == 2){
- curType = 2;
- }
- else if(section == 1){
- if(_uploadingArr.count == 0){
- curType = 2;
- }
- else if(_uploadfailArr.count == 0){
- curType = 2;
- }
- else{
- curType = 1;
- }
- }
- else{
- if(_uploadingArr.count > 0){
- curType = 0;
- }
- else if(_uploadfailArr.count > 0){
- curType = 1;
- }
- else{
- curType = 2;
- }
- }
-
-
- [self RefresHeadUIFun];
-
- if(curType == 2){
- return _doneHeadView;
- }
- else if(curType == 1){
- return _failHeadView;
- }
- else{
- return _uploadingHeadView;
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 40;
- }
- - (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)initTableHeaderInSectionFun
- {
- KWeakSelf
- if(!_uploadingHeadView){
- _uploadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- 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,_uploadingArr.count];
- _uploadingHeadView.titleLabel.text = titleStr;
- [_uploadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
- [_uploadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
-
- _uploadingHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:0];
- };
- }
-
- if(!_failHeadView){
- _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_upload_fail",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadfailArr.count];
- _failHeadView.titleLabel.text = titleStr;
- [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- _failHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:2];
- };
- }
-
- if(!_doneHeadView){
- _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- 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,_uploadDoneArr.count];
- _doneHeadView.titleLabel.text = titleStr;
- [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- _doneHeadView.didClickButFun = ^{
- [weakSelf didClickRightButtonFun:1];
- };
- }
-
-
- }
- #pragma mark 点击头部右边按钮
- - (void)didClickRightButtonFun:(NSInteger)section
- {
- if(_uploadingHeadView.rightButton.selected){
- for (uploadFileDataModel*model in _uploadingArr) {
- model.curUploadStateType = uploadStateSuspend;
- }
- }
-
- if(_didClickSectionHeadViewRightButton){
- _didClickSectionHeadViewRightButton(section);
- }
-
- [self reloadData];
- }
- #pragma mark 刷新头部数据
- -(void)RefresHeadUIFun
- {
- if(_uploadingHeadView){
- 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,_uploadingArr.count];
- _uploadingHeadView.titleLabel.text = titleStr;
- [_uploadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
- [_uploadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
-
- if(_uploadingArr.count == 0){
- _uploadingHeadView.hidden = YES;
- }
- else{
- _uploadingHeadView.hidden = NO;
-
- if(_isfirstRefreshType){
- BOOL isAllUploadingType = NO;
-
- // if([nasMixUploadManager shareManager].isUploadIngType){
- // isAllUploadingType = YES;
- // }
-
- HLog(@"上传刷新头部按钮 开始遍历")
- @synchronized (self) {
- for (uploadFileDataModel*model in _uploadingArr) {
- if(model.curUploadStateType != uploadStateUploading){
- isAllUploadingType = YES;
- break;
- }
- }
- _uploadingHeadView.rightButton.selected = isAllUploadingType;
-
- _isfirstRefreshType = NO;
- }
-
- HLog(@"上传刷新头部按钮 结束遍历")
- }
- }
- }
-
-
- if(_failHeadView){
- NSString *leftStr = NSLocalizedString(@"File_upload_Record_upload_fail",nil);
- NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
- NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadfailArr.count];
- _failHeadView.titleLabel.text = titleStr;
- [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- if(_uploadfailArr.count == 0){
- _failHeadView.hidden = YES;
- }
- else{
- _failHeadView.hidden = NO;
- }
- }
-
- if(_doneHeadView){
- 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,_uploadDoneArr.count];
- _doneHeadView.titleLabel.text = titleStr;
- [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
-
- if(_uploadDoneArr.count == 0){
- _doneHeadView.hidden = YES;
- }
- else{
- _doneHeadView.hidden = NO;
- }
- }
- }
- #pragma mark 点击全选
- - (void)setIsSelectAllType:(BOOL)isSelectAllType
- {
- //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
-
- _selectModelArr = [NSMutableArray new];
-
- if(isSelectAllType){
- [_selectModelArr addObjectsFromArray:_uploadingArr];
- [_selectModelArr addObjectsFromArray:_uploadfailArr];
- [_selectModelArr addObjectsFromArray:_uploadDoneArr];
- }
-
- [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){
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- });
- return;
- }
-
- KWeakSelf
- [[nasUploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
- HLog(@"isSuccess:%d",isSuccess);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [SVProgressHUD dismiss];
- });
- if(isSuccess){
- // NSMutableArray *curArr = self->_curDataArr;
- // [curArr removeObjectsInArray:self->_selectModelArr];
- // [weakSelf reloadDataFun];
- self->_selectModelArr = [NSMutableArray new];
-
- //重新拿数据
- [weakSelf refreshGetDatabaseFun];
- }
- }];
- }
- #pragma mark 删除后重新拿数据
- - (void)refreshGetDatabaseFun
- {
- if(_didNeedRefreshGetDatabaseFun){
- _didNeedRefreshGetDatabaseFun();
- }
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
- {
- if (isSuspendType) {
- //[[uploadFileManager shareInstance] suspendUploadFileFun:NO withModel:model];
- [[nasUploadFileManager shareInstance] suspendUploadFileFun:NO withModel:model];
- }
- else{
- NSMutableArray*arr = [NSMutableArray new];
- [arr addObject:model];
- //[[uploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
- [[nasUploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
- }
-
- [self reloadDataFun];
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
-
- if(_uploadfailArr && _uploadfailArr.count > 0){
- [_uploadfailArr removeObject:model];
- }
-
- //添加到上传中的列表
- if(!_uploadingArr){
- _uploadingArr = [NSMutableArray new];
- }
- model.curUploadStateType = uploadStateUploading;
- [_uploadingArr addObject:model];
-
- [self RefreshAllDataFun];
-
- if(_didClickReUploadBlock){
- _didClickReUploadBlock(model);
- }
-
- NSMutableArray*arr = [NSMutableArray new];
- model.curUploadStateType = uploadStateUploading;
- [arr addObject:model];
- //[[uploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
- [[nasUploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
-
- }
- @end
|