uploadFileRecordViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. //
  2. // uoloadFileRecordViewController.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/13.
  6. //
  7. #import "uploadFileRecordViewController.h"
  8. #import "uploadFileManager.h"
  9. #import "uploadFileDataModel.h"
  10. #import "uploadFileRecordheadView.h"
  11. #import "uploadFileRecordBodyView.h"
  12. #import "uploadFileRecordEditBottomView.h"
  13. @interface uploadFileRecordViewController ()
  14. //选中的项
  15. @property (nonatomic, strong) NSMutableArray *indexPathsForSelectedItems;
  16. @property (nonatomic, strong) uploadFileRecordheadView *uploadFileRecordheadV;
  17. @property (nonatomic, strong) uploadFileRecordBodyView *uploadFileRecordBodyV;
  18. @property (nonatomic, strong) NSMutableArray *allDataArr;
  19. @property (nonatomic, strong) UIButton *leftButton;
  20. @property (nonatomic, strong) UIButton *rightButton;
  21. @property (nonatomic, strong) uploadFileRecordEditBottomView *uploadFileRecordEditBottomV;
  22. @property (nonatomic,assign) BOOL isEditType;
  23. @end
  24. @implementation uploadFileRecordViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. // Do any additional setup after loading the view.
  28. //[self.view setBackgroundColor:HWF5F7FAColor];
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileRefreshFun:) name:uploadFileRefreshNotification object:nil];
  30. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileDeteleFun:) name:uploadFileDeteleNotification object:nil];
  31. [self.view setBackgroundColor:[UIColor whiteColor]];
  32. self.titleLabel.text = NSLocalizedString(@"my_set_no_File_upload_record",nil) ;
  33. [self.toolBar setHidden:YES];
  34. [self.navigationBar setHidden:YES];
  35. [self.navBarBGView setHidden:NO];
  36. self.navBarBGView.backgroundColor = [UIColor whiteColor];
  37. [self initbaseUIFun];
  38. [self getDataInDatabaseFun];
  39. }
  40. #pragma mark UI
  41. - (void)initbaseUIFun
  42. {
  43. _uploadFileRecordheadV = [[uploadFileRecordheadView alloc] init];
  44. [self.view addSubview:_uploadFileRecordheadV];
  45. [_uploadFileRecordheadV mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(15);
  47. make.right.mas_equalTo(-15);
  48. make.top.mas_equalTo(self.navBarBGView.mas_bottom).offset(15.0);
  49. make.height.mas_equalTo(50);
  50. }];
  51. KWeakSelf
  52. #pragma mark 头部点击事件
  53. _uploadFileRecordheadV.didClickButFun = ^(NSInteger index) {
  54. [weakSelf didClickHeadFun: index];
  55. };
  56. _uploadFileRecordBodyV = [[uploadFileRecordBodyView alloc] init];
  57. _uploadFileRecordBodyV.curVC = self;
  58. [self.view addSubview:_uploadFileRecordBodyV];
  59. [_uploadFileRecordBodyV mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(0);
  61. make.right.mas_equalTo(0);
  62. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  63. make.bottom.mas_equalTo(0);
  64. }];
  65. _uploadFileRecordBodyV.didScrollFun = ^(NSInteger index) {
  66. [weakSelf didScorllBodyFun:index];
  67. };
  68. _uploadFileRecordBodyV.didLongPressClick = ^{
  69. weakSelf.isEditType = YES;
  70. };
  71. _leftButton = [[UIButton alloc] init];
  72. [_leftButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  73. _leftButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  74. _leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  75. [_leftButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  76. _leftButton.tag = 1;
  77. [_leftButton setTitle:NSLocalizedString(@"other_cancel",nil) forState:UIControlStateNormal];
  78. _leftButton.hidden = YES;
  79. [self.navBarBGView addSubview:_leftButton];
  80. [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.width.mas_equalTo(80);
  82. make.left.mas_equalTo(15);
  83. make.height.mas_equalTo(self.backBtn.mas_height);
  84. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  85. }];
  86. _rightButton = [[UIButton alloc] init];
  87. [_rightButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateNormal];
  88. _rightButton.titleLabel.font = [UIFont systemFontOfSize:18.0];
  89. _rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  90. [_rightButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  91. _rightButton.tag = 2;
  92. [_rightButton setTitle:NSLocalizedString(@"File_upload_Record_select_all",nil) forState:UIControlStateNormal];
  93. _rightButton.hidden = YES;
  94. [self.navBarBGView addSubview:_rightButton];
  95. [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.width.mas_equalTo(80);
  97. make.right.mas_equalTo(-15);
  98. make.height.mas_equalTo(self.backBtn.mas_height);
  99. make.centerY.mas_equalTo(self.backBtn.mas_centerY);
  100. }];
  101. _uploadFileRecordEditBottomV = [[uploadFileRecordEditBottomView alloc] init];
  102. _uploadFileRecordEditBottomV.hidden = YES;
  103. [self.view addSubview:_uploadFileRecordEditBottomV];
  104. [_uploadFileRecordEditBottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.mas_equalTo(0);
  106. make.right.mas_equalTo(0);
  107. make.height.mas_equalTo(60 + safeArea);
  108. make.bottom.mas_equalTo(0);
  109. }];
  110. _uploadFileRecordEditBottomV.didClickButFun = ^{
  111. [weakSelf.uploadFileRecordBodyV deleteModelOneByOneFun];
  112. };
  113. }
  114. #pragma mark 头部点击 背景滚动
  115. - (void)didClickHeadFun:(NSInteger)index
  116. {
  117. _uploadFileRecordBodyV.selectIndex = index;
  118. }
  119. - (void)didScorllBodyFun:(NSInteger)index
  120. {
  121. _uploadFileRecordheadV.selectIndex = index;
  122. }
  123. -(void)gotoUploadFile:(NSMutableArray*)indexPathsForSelectedItems
  124. {
  125. _indexPathsForSelectedItems = [[uploadFileManager shareInstance] handlTZAssetModelToUploadFileDataFunBy:indexPathsForSelectedItems];
  126. HLog(@"11");
  127. }
  128. #pragma mark 读取数据库数据
  129. - (void)getDataInDatabaseFun
  130. {
  131. _allDataArr = [NSMutableArray new];
  132. KWeakSelf
  133. [uploadFileDataModel bg_findAllAsync:upLoadFile_image_tableName complete:^(NSArray * _Nullable array) {
  134. NSMutableArray *failArr = [NSMutableArray new];
  135. NSMutableArray *doneArr = [NSMutableArray new];
  136. NSMutableArray *otherArr = [NSMutableArray new];
  137. for (uploadFileDataModel * curModel in array) {
  138. //图片 和视频 还原
  139. if(curModel.curUploadFileType == uploadFileTypeImage){
  140. NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeImage];
  141. curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
  142. }
  143. else if(curModel.curUploadFileType == uploadFileTypeVideo){
  144. NSString*pathStr = [cachesFileManager getFilePathWithName:curModel.videoFirstImageName type:uploadFileTypeImage];
  145. curModel.imageData = [NSData dataWithContentsOfFile:pathStr];
  146. NSString*videoPathStr = [cachesFileManager getFilePathWithName:curModel.filename type:uploadFileTypeVideo];
  147. curModel.videoData = [NSData dataWithContentsOfFile:videoPathStr];
  148. }
  149. if(curModel.curUploadStateType == uploadStateFail){
  150. [failArr addObject:curModel];
  151. }
  152. else if(curModel.curUploadStateType == uploadStateDone){
  153. [doneArr addObject:curModel];
  154. }
  155. else{
  156. //不是上传视频和进来的 所以上传状态(上传中和等待)改为暂停
  157. if(self->_isNotUploadingType && ![uploadFileManager shareInstance].isUploadIngType){
  158. curModel.curUploadStateType = uploadStateSuspend;
  159. }
  160. [otherArr addObject:curModel];
  161. }
  162. }
  163. [self->_allDataArr addObject:otherArr];
  164. [self->_allDataArr addObject:doneArr];
  165. [self->_allDataArr addObject:failArr];
  166. weakSelf.uploadFileRecordBodyV.allDataArr = self->_allDataArr;
  167. }];
  168. }
  169. - (void)uploadFileRefreshFun:(NSNotification*)not
  170. {
  171. uploadFileDataModel *uploadFileDataMod = [not object];
  172. HLog(@"%@",uploadFileDataMod);
  173. if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
  174. NSMutableArray *curArr = _allDataArr[0];
  175. NSInteger index = 0;
  176. for (uploadFileDataModel*mod in curArr) {
  177. HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
  178. if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
  179. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  180. [curArr removeObject:mod];
  181. NSMutableArray *doneArr = _allDataArr[1];
  182. [doneArr insertObject:uploadFileDataMod atIndex:0];
  183. //全部上传了
  184. if(curArr.count == 0){
  185. }
  186. }
  187. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  188. [curArr removeObject:mod];
  189. NSMutableArray *failArr = _allDataArr[2];
  190. [failArr insertObject:uploadFileDataMod atIndex:0];
  191. }
  192. else{
  193. [curArr replaceObjectAtIndex:index withObject:uploadFileDataMod];
  194. }
  195. break;
  196. }
  197. index++;
  198. }
  199. //精准刷新
  200. if(uploadFileDataMod.curUploadStateType == uploadStateDone){
  201. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:nil];
  202. }
  203. else if(uploadFileDataMod.curUploadStateType == uploadStateFail){
  204. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:_allDataArr[2]];
  205. }
  206. else{
  207. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
  208. }
  209. }
  210. //self.uploadFileRecordBodyV.allDataArr = _allDataArr;
  211. }
  212. - (void)uploadFileDeteleFun:(NSNotification*)not
  213. {
  214. uploadFileDataModel *uploadFileDataMod = [not object];
  215. HLog(@"%@",uploadFileDataMod);
  216. if(_allDataArr.count == 3 && [uploadFileDataMod isKindOfClass:[uploadFileDataModel class]] ){
  217. NSMutableArray *curArr = _allDataArr[0];
  218. NSInteger index = 0;
  219. for (uploadFileDataModel*mod in curArr) {
  220. HLog(@"bg_id:%@ ?=? %@",mod.bg_id,uploadFileDataMod.bg_id);
  221. if(mod.bg_id.integerValue == uploadFileDataMod.bg_id.integerValue){
  222. [curArr removeObject:mod];
  223. break;
  224. }
  225. index++;
  226. }
  227. //精准刷新
  228. [self.uploadFileRecordBodyV RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:nil withfailArr:nil];
  229. }
  230. }
  231. #pragma mark 按钮点击
  232. - (void)didClickButFun:(UIButton*)but
  233. {
  234. NSInteger tag = but.tag;
  235. if(tag == 1){
  236. self.isEditType = NO;
  237. self.uploadFileRecordBodyV.isEditType = NO;
  238. }
  239. else{
  240. self.uploadFileRecordBodyV.isSelectAllType = YES;
  241. }
  242. }
  243. -(void)setIsEditType:(BOOL)isEditType
  244. {
  245. _isEditType = isEditType;
  246. if(_isEditType){
  247. _leftButton.hidden = NO;
  248. _rightButton.hidden = NO;
  249. self.backBtn.hidden = YES;
  250. _uploadFileRecordEditBottomV.hidden = NO;
  251. _uploadFileRecordheadV.userInteractionEnabled = NO;
  252. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  253. make.left.mas_equalTo(0);
  254. make.right.mas_equalTo(0);
  255. make.bottom.mas_equalTo(_uploadFileRecordEditBottomV.mas_top).offset(0.0);
  256. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  257. }];
  258. //dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  259. // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)];
  260. //
  261. // CGRect frame = curTabview.frame;
  262. // frame.size.height = SCREEN_H - CGRectGetMaxY(_uploadFileRecordheadV.frame) - (60 + safeArea);
  263. //
  264. // CGSize curSize = _uploadFileRecordBodyV.bgScrollV.contentSize;
  265. // curSize.height = frame.size.height;
  266. // _uploadFileRecordBodyV.bgScrollV.contentSize = curSize;
  267. //curTabview.frame = frame;
  268. //});
  269. }
  270. else{
  271. _leftButton.hidden = YES;
  272. _rightButton.hidden = YES;
  273. self.backBtn.hidden = NO;
  274. _uploadFileRecordEditBottomV.hidden = YES;
  275. _uploadFileRecordheadV.userInteractionEnabled = YES;
  276. [_uploadFileRecordBodyV mas_remakeConstraints:^(MASConstraintMaker *make) {
  277. make.left.mas_equalTo(0);
  278. make.right.mas_equalTo(0);
  279. make.top.mas_equalTo(_uploadFileRecordheadV.mas_bottom).offset(0.0);
  280. make.bottom.mas_equalTo(0);
  281. }];
  282. // UITableView *curTabview = [_uploadFileRecordBodyV.bgScrollV viewWithTag:(10+_uploadFileRecordBodyV.selectIndex -1)];
  283. //
  284. // CGRect frame = curTabview.frame;
  285. // frame.size.height = SCREEN_W - CGRectGetHeight(_uploadFileRecordBodyV.frame);
  286. // curTabview.frame = frame;
  287. }
  288. }
  289. @end