// // uoloadFileRecordViewController.m // 隐私保护 // // Created by xd h on 2023/11/13. // #import "uploadFileRecordViewController.h" #import "uploadFileManager.h" #import "uploadFileDataModel.h" #import "uploadFileRecordheadView.h" #import "uploadFileRecordBodyView.h" #import "uploadFileRecordEditBottomView.h" @interface uploadFileRecordViewController () //选中的项 @property (nonatomic, strong) NSMutableArray *indexPathsForSelectedItems; @property (nonatomic, strong) uploadFileRecordheadView *uploadFileRecordheadV; @property (nonatomic, strong) uploadFileRecordBodyView *uploadFileRecordBodyV; @property (nonatomic, strong) NSMutableArray *allDataArr; @property (nonatomic, strong) UIButton *leftButton; @property (nonatomic, strong) UIButton *rightButton; @property (nonatomic, strong) uploadFileRecordEditBottomView *uploadFileRecordEditBottomV; @property (nonatomic,assign) BOOL isEditType; @end @implementation uploadFileRecordViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //[self.view setBackgroundColor:HWF5F7FAColor]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:) name:uploadFileRefreshNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileDeteleFun:) name:uploadFileDeteleNotification object:nil]; [self.view setBackgroundColor:[UIColor whiteColor]]; self.titleLabel.text = NSLocalizedString(@"my_set_no_File_upload_record",nil) ; [self.toolBar setHidden:YES]; [self.navigationBar setHidden:YES]; [self.navBarBGView setHidden:NO]; self.navBarBGView.backgroundColor = [UIColor whiteColor]; [self initbaseUIFun]; [self getDataInDatabaseFun]; } #pragma mark UI - (void)initbaseUIFun { _uploadFileRecordheadV = [[uploadFileRecordheadView alloc] init]; [self.view addSubview:_uploadFileRecordheadV]; [_uploadFileRecordheadV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(15.0); make.height.mas_equalTo(50); }]; KWeakSelf #pragma mark 头部点击事件 _uploadFileRecordheadV.didClickButFun = ^(NSInteger index) { [weakSelf didClickHeadFun: index]; }; _uploadFileRecordBodyV = [[uploadFileRecordBodyView alloc] init]; _uploadFileRecordBodyV.curVC = self; [self.view addSubview:_uploadFileRecordBodyV]; [_uploadFileRecordBodyV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0); make.bottom.mas_equalTo(0); }]; _uploadFileRecordBodyV.didScrollFun = ^(NSInteger index) { [weakSelf didScorllBodyFun:index]; }; _uploadFileRecordBodyV.didLongPressClick = ^{ weakSelf.isEditType = YES; }; _leftButton = [[UIButton alloc] init]; [_leftButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal]; _leftButton.titleLabel.font = [UIFont systemFontOfSize:18.0]; _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_leftButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; _leftButton.tag = 1; [_leftButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal]; _leftButton.hidden = YES; [self.navBarBGView addSubview:_leftButton]; [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(80); make.left.mas_equalTo(15); make.height.mas_equalTo(self.backBtn.mas_height); make.centerY.mas_equalTo(self.backBtn.mas_centerY); }]; _rightButton = [[UIButton alloc] init]; [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal]; _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0]; _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; [_rightButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; _rightButton.tag = 2; [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal]; _rightButton.hidden = YES; [self.navBarBGView addSubview:_rightButton]; [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(80); make.right.mas_equalTo(-15); make.height.mas_equalTo(self.backBtn.mas_height); make.centerY.mas_equalTo(self.backBtn.mas_centerY); }]; _uploadFileRecordEditBottomV = [[uploadFileRecordEditBottomView alloc] init]; _uploadFileRecordEditBottomV.hidden = YES; [self.view addSubview:_uploadFileRecordEditBottomV]; [_uploadFileRecordEditBottomV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(60 + safeArea); make.bottom.mas_equalTo(0); }]; _uploadFileRecordEditBottomV.didClickButFun = ^{ [weakSelf.uploadFileRecordBodyV deleteModelOneByOneFun]; }; } #pragma mark 头部点击 背景滚动 - (void)didClickHeadFun:(NSInteger)index { _uploadFileRecordBodyV.selectIndex = index; } - (void)didScorllBodyFun:(NSInteger)index { _uploadFileRecordheadV.selectIndex = index; } -(void)gotoUploadFile:(NSMutableArray*)indexPathsForSelectedItems { _indexPathsForSelectedItems = [[uploadFileManager shareInstance] handlTZAssetModelToUploadFileDataFunBy:indexPathsForSelectedItems]; HLog(@"11"); } #pragma mark 读取数据库数据 - (void)getDataInDatabaseFun { _allDataArr = [NSMutableArray new]; KWeakSelf [uploadFileDataModel bg_findAllAsync:upLoadFile_image_tableName complete:^(NSArray * _Nullable array) { NSMutableArray *failArr = [NSMutableArray new]; NSMutableArray *doneArr = [NSMutableArray new]; NSMutableArray *otherArr = [NSMutableArray new]; for (uploadFileDataModel * curModel in array) { //图片 和视频 还原 if(curModel.curUploadFileType == uploadFileTypeImage){ NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeImage]; curModel.imageData = [NSData dataWithContentsOfFile:pathStr]; } else if(curModel.curUploadFileType == uploadFileTypeVideo){ NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.videoFirstImageName type:uploadFileTypeImage]; curModel.imageData = [NSData dataWithContentsOfFile:pathStr]; NSString*videoPathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeVideo]; curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr]; } if(curModel.curUploadStateType == uploadStateFail){ [failArr addObject:curModel]; } else if(curModel.curUploadStateType == uploadStateDone){ [doneArr addObject:curModel]; } else{ //不是上传视频和进来的 所以上传状态(上传中和等待)改为暂停 if(self->_isNotUploadingType && ![uploadFileManager shareInstance].isUploadIngType){ curModel.curUploadStateType = uploadStateSuspend; } [otherArr addObject:curModel]; } } [self->_allDataArr addObject:otherArr]; [self->_allDataArr addObject:doneArr]; [self->_allDataArr addObject:failArr]; weakSelf.uploadFileRecordBodyV.allDataArr = self->_allDataArr; }]; } - (void)uploadFileRefreshFun:(NSNotification*)not { uploadFileDataModel *uploadFileDataMod = [not object]; HLog(@"%@",uploadFileDataMod); if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){ NSMutableArray *curArr = _allDataArr[0]; NSInteger index = 0; for (uploadFileDataModel*mod in curArr) { HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id); if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){ if(uploadFileDataMod.curUploadStateType == uploadStateDone){ [curArr removeObject:mod]; NSMutableArray *doneArr = _allDataArr[1]; [doneArr insertObject:uploadFileDataMod atIndex:0]; //全部上传了 if(curArr.count == 0){ } } else if(uploadFileDataMod.curUploadStateType == uploadStateFail){ [curArr removeObject:mod]; NSMutableArray *failArr = _allDataArr[2]; [failArr insertObject:uploadFileDataMod atIndex:0]; } else{ [curArr replaceObjectAtIndex:index withObject:uploadFileDataMod]; } break; } index++; } //精准刷新 if(uploadFileDataMod.curUploadStateType == uploadStateDone){ [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:nil]; } else if(uploadFileDataMod.curUploadStateType == uploadStateFail){ [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:_allDataArr[2]]; } else{ [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil]; } } //self.uploadFileRecordBodyV.allDataArr = _allDataArr; } - (void)uploadFileDeteleFun:(NSNotification*)not { uploadFileDataModel *uploadFileDataMod = [not object]; HLog(@"%@",uploadFileDataMod); if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){ NSMutableArray *curArr = _allDataArr[0]; NSInteger index = 0; for (uploadFileDataModel*mod in curArr) { HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id); if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){ [curArr removeObject:mod]; break; } index++; } //精准刷新 [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil]; } } #pragma mark 按钮点击 - (void)didClickButFun:(UIButton*)but { NSInteger tag = but.tag; if(tag == 1){ self.isEditType = NO; self.uploadFileRecordBodyV.isEditType = NO; } else{ self.uploadFileRecordBodyV.isSelectAllType = YES; } } -(void)setIsEditType:(BOOL)isEditType { _isEditType = isEditType; if(_isEditType){ _leftButton.hidden = NO; _rightButton.hidden = NO; self.backBtn.hidden = YES; _uploadFileRecordEditBottomV.hidden = NO; _uploadFileRecordheadV.userInteractionEnabled = NO; [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top).offset(0.0); make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0); }]; //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)]; // // CGRect frame = curTabview.frame; // frame.size.height = SCREEN_H - CGRectGetMaxY(_uploadFileRecordheadV.frame) - (60 + safeArea); // // CGSize curSize = _uploadFileRecordBodyV.bgScrollV.contentSize; // curSize.height = frame.size.height; // _uploadFileRecordBodyV.bgScrollV.contentSize = curSize; //curTabview.frame = frame; //}); } else{ _leftButton.hidden = YES; _rightButton.hidden = YES; self.backBtn.hidden = NO; _uploadFileRecordEditBottomV.hidden = YES; _uploadFileRecordheadV.userInteractionEnabled = YES; [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0); make.bottom.mas_equalTo(0); }]; // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)]; // // CGRect frame = curTabview.frame; // frame.size.height = SCREEN_W - CGRectGetHeight(_uploadFileRecordBodyV.frame); // curTabview.frame = frame; } } @end