123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458 |
- //
- // 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) uploadFileRecordTableViewHeadView *uploadingHeadView;
- @property (nonatomic,strong) uploadFileRecordTableViewHeadView *failHeadView;
- @property (nonatomic,strong) uploadFileRecordTableViewHeadView *doneHeadView;
- @property (nonatomic, strong) NSMutableArray *curDataArr;
- @end
- @implementation uploadFileRecordTableView
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initCommon];
- _selectModelArr = [NSMutableArray new];
- _curDataArr = [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)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){
- [weakSelf handleUploadingStateTapFunBy:YES with:model];
- }
- else if(model.curUploadStateType == uploadStateSuspend){
- [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;
- }
- }
-
- uploadFileRecordTableViewHeadView *headView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
- //headView.backgroundColor = [UIColor greenColor];
-
- headView.didClickButFun = ^{
- //[weakSelf didClickAllSuspendInLoadingFun];
- };
-
- if(curType == 2){
-
- if(_doneHeadView){
- return _doneHeadView;
- }
- else{
- _doneHeadView = headView;
- }
-
- }
- else if(curType == 1){
-
- if(_failHeadView){
- return _failHeadView;
- }
- else{
- _failHeadView = headView;
- }
-
- }
- else{
- if(_uploadingHeadView){
- return _uploadingHeadView;
- }
- else{
- _uploadingHeadView = headView;
- }
-
- }
-
- [self RefresHeadUIFun];
-
- return headView;
- }
- - (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)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(_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(_failHeadView){
- 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,_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];
- [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)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
- {
- if (isSuspendType) {
- [[uploadFileManager shareInstance] suspendUploadFileFun:NO];
- }
- else{
- NSMutableArray*arr = [NSMutableArray new];
- [arr addObject:model];
- [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
- }
-
- }
- #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
|