uploadFileRecordBodyView.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. //
  2. // uploadFileRecordBodyView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/15.
  6. //
  7. #import "uploadFileRecordBodyView.h"
  8. #import "uploadFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileDataModel.h"
  11. #import "ComontAlretViewController.h"
  12. #import "uploadFileManager.h"
  13. @interface uploadFileRecordBodyView ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  14. @property (nonatomic,strong) NSMutableArray *selectModelArr;
  15. @end
  16. @implementation uploadFileRecordBodyView
  17. - (id)initWithFrame:(CGRect)frame{
  18. self = [super initWithFrame:frame];
  19. _selectIndex = 1;
  20. [self drawAnyView];
  21. _selectModelArr = [NSMutableArray new];
  22. return self;
  23. }
  24. - (void)drawAnyView{
  25. [self setBackgroundColor:[UIColor whiteColor]];
  26. NSInteger maxNum = 3;
  27. _bgScrollV = [[UIScrollView alloc] init];
  28. _bgScrollV.showsHorizontalScrollIndicator = NO;
  29. _bgScrollV.pagingEnabled = YES;
  30. _bgScrollV.delegate = self;
  31. [self addSubview:_bgScrollV];
  32. [_bgScrollV mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.mas_equalTo(0);
  34. make.right.mas_equalTo(0);
  35. make.top.mas_equalTo(0);
  36. make.bottom.mas_equalTo(0);
  37. }];
  38. KWeakSelf
  39. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  40. mainBlock(^{
  41. [weakSelf initBaseTableViewFun:maxNum];
  42. });
  43. });
  44. }
  45. #pragma mark UITableView
  46. - (void)initBaseTableViewFun:(NSInteger)maxNum
  47. {
  48. CGRect frame = self->_bgScrollV.frame;
  49. self->_bgScrollV.contentSize = CGSizeMake(maxNum* SCREEN_W, frame.size.height);
  50. for (NSInteger i= 0; i<maxNum; i++) {
  51. UITableView *curTableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  52. curTableview.delegate = self;
  53. curTableview.dataSource = self;
  54. curTableview.showsVerticalScrollIndicator = NO;
  55. curTableview.showsHorizontalScrollIndicator = NO;
  56. // _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
  57. [curTableview setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  58. [curTableview setSeparatorColor:[UIColor clearColor]];
  59. [curTableview setBackgroundColor:[UIColor clearColor]];
  60. [curTableview setTableFooterView:[UIView new]];
  61. [curTableview setBounces:YES];
  62. if (@available(iOS 15.0, *)) {
  63. curTableview.sectionHeaderTopPadding = 0;
  64. }
  65. [self->_bgScrollV addSubview:curTableview];
  66. curTableview.tag = 10 +i;
  67. //空数据引入第三方开源处理
  68. curTableview.emptyDataSetSource = self;
  69. curTableview.emptyDataSetDelegate = self;
  70. [curTableview mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.mas_equalTo(SCREEN_W * i);
  72. make.width.mas_equalTo(SCREEN_W);
  73. make.top.mas_equalTo(0);
  74. make.height.mas_equalTo(frame.size.height);
  75. //make.bottom.mas_equalTo(0);
  76. }];
  77. uploadFileRecordTableViewHeadView *headView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  78. curTableview.tableHeaderView = headView;
  79. KWeakSelf
  80. headView.didClickButFun = ^{
  81. if(headView == self->_leftHeadView)
  82. {
  83. [weakSelf didClickAllSuspendInLoadingFun];
  84. }
  85. else if(headView == self->_midHeadView)
  86. {
  87. [weakSelf didClickClearRecordInDoneFun];
  88. }
  89. else if(headView == self->_rightHeadView)
  90. {
  91. [weakSelf didClickClearRecordInFailFun];
  92. }
  93. };
  94. if(i==0){
  95. self->_leftHeadView = headView;
  96. }
  97. else if(i==1){
  98. self->_midHeadView = headView;
  99. }
  100. else if(i==2){
  101. self->_rightHeadView = headView;
  102. }
  103. }
  104. }
  105. #pragma mark - 列表委托
  106. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  107. return 1;
  108. }
  109. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  110. NSInteger tag = tableView.tag - 10;
  111. if(_allDataArr && tag <_allDataArr.count){
  112. NSMutableArray *curArr = _allDataArr[tag];
  113. return curArr.count;
  114. }
  115. return 0;
  116. }
  117. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  118. NSInteger row = indexPath.row;
  119. static NSString *identifier = @"uploadFileRecordCell";
  120. uploadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  121. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  122. if (!cell){
  123. cell = [[uploadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  124. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  125. [cell setBackgroundColor:[UIColor clearColor]];
  126. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  127. }
  128. NSInteger tag = tableView.tag - 10;
  129. if(_allDataArr && tag <_allDataArr.count){
  130. NSMutableArray *curArr = _allDataArr[tag];
  131. if(row < curArr.count){
  132. uploadFileDataModel *model = curArr[row];
  133. cell.curUploadFileDataModel = model;
  134. // cell.isEditType = _isEditType;
  135. //
  136. // if(_isEditType){
  137. // if([_selectModelArr containsObject:model]){
  138. // cell.isSelectType = YES;
  139. // }
  140. // else{
  141. // cell.isSelectType = NO;
  142. // }
  143. // }
  144. KWeakSelf
  145. // cell.didLongPressClick = ^{
  146. // weakSelf.isEditType = YES;
  147. // if(self->_didLongPressClick){
  148. // self->_didLongPressClick();
  149. // }
  150. // };
  151. // cell.didClckSelectBut = ^(BOOL isSelect) {
  152. // [weakSelf selectModelOneByOne:model BySelect:isSelect];
  153. // };
  154. //
  155. // cell.didTapPressClick = ^{
  156. // if(model.curUploadStateType == uploadStateUploading){
  157. // [weakSelf handleUploadingStateTapFunBy:YES with:model];
  158. // }
  159. // else if(model.curUploadStateType == uploadStateSuspend){
  160. // [weakSelf handleUploadingStateTapFunBy:NO with:model];
  161. // }
  162. // };
  163. }
  164. }
  165. return cell;
  166. }
  167. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  168. return 70;
  169. }
  170. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  171. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  172. }
  173. //- (void)scrollViewDidScroll:(UIScrollView *)scrollView
  174. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  175. {
  176. if(_bgScrollV != scrollView) return;
  177. CGFloat x = scrollView.contentOffset.x;
  178. NSInteger index = (x+1)/SCREEN_W;
  179. index += 1;//因为头部是从1开始的
  180. //HLog(@"index:%ld",index);
  181. if(_didScrollFun){
  182. _didScrollFun(index);
  183. }
  184. }
  185. #pragma mark 空数据
  186. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  187. return [UIImage imageNamed:@"uploadFile_noData"];
  188. }
  189. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  190. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  191. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  192. NSForegroundColorAttributeName: HW999999Color};
  193. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  194. }
  195. //调整图片位置
  196. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  197. return -150;
  198. }
  199. - (void)setSelectIndex:(NSInteger)selectIndex
  200. {
  201. _selectIndex = selectIndex;
  202. CGPoint poit = _bgScrollV.contentOffset;
  203. poit.x = SCREEN_W * (selectIndex -1);
  204. [UIView animateWithDuration:0.2 animations:^{
  205. self->_bgScrollV.contentOffset = poit;
  206. }];
  207. }
  208. - (void)setAllDataArr:(NSMutableArray *)allDataArr
  209. {
  210. _allDataArr = allDataArr;
  211. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  212. if(self->_allDataArr.count >=3){
  213. [self RefresHeadUIFunBy:self->_allDataArr[0] withMidArr:self->_allDataArr[1] withRightArr:self->_allDataArr[2]];
  214. }
  215. });
  216. mainBlock(^{
  217. //刷新数据
  218. [self reloadAllDataFun];
  219. });
  220. }
  221. #pragma mark 熟悉全部数据
  222. - (void)reloadAllDataFun
  223. {
  224. if(_allDataArr.count == 3){
  225. [self RefreshDataWithUploadingArr:_allDataArr[0] withDoneArr:_allDataArr[1] withfailArr:_allDataArr[2]];
  226. }
  227. }
  228. - (void)RefreshDataWithUploadingArr:(NSMutableArray* _Nullable)uploadingArr withDoneArr:(NSMutableArray* _Nullable)doneArr withfailArr:(NSMutableArray* _Nullable)failArr
  229. {
  230. if(uploadingArr){
  231. UITableView *curTabview = [self->_bgScrollV viewWithTag:10];
  232. if([curTabview isKindOfClass:[UITableView class]]){
  233. [_allDataArr replaceObjectAtIndex:0 withObject:uploadingArr];
  234. [curTabview reloadData];
  235. BOOL isAllSuspendType = YES;
  236. for (uploadFileDataModel*model in uploadingArr) {
  237. if(model.curUploadStateType != uploadStateSuspend){
  238. isAllSuspendType = NO;
  239. break;
  240. }
  241. }
  242. mainBlock(^{
  243. //刷新
  244. if(isAllSuspendType){
  245. self->_leftHeadView.rightButton.selected = YES;
  246. }
  247. });
  248. }
  249. }
  250. if(doneArr){
  251. UITableView *curTabview = [self->_bgScrollV viewWithTag:11];
  252. if([curTabview isKindOfClass:[UITableView class]]){
  253. [_allDataArr replaceObjectAtIndex:1 withObject:doneArr];
  254. [curTabview reloadData];
  255. }
  256. }
  257. if(failArr){
  258. UITableView *curTabview = [self->_bgScrollV viewWithTag:12];
  259. if([curTabview isKindOfClass:[UITableView class]]){
  260. [_allDataArr replaceObjectAtIndex:2 withObject:failArr];
  261. [curTabview reloadData];
  262. }
  263. }
  264. [self RefresHeadUIFunBy:uploadingArr withMidArr:doneArr withRightArr:failArr];
  265. }
  266. #pragma mark 熟悉头部数据
  267. -(void)RefresHeadUIFunBy:(NSMutableArray*)letfArr withMidArr:(NSMutableArray*)midArr withRightArr:(NSMutableArray*)rightArr
  268. {
  269. if(letfArr){
  270. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  271. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  272. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  273. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,letfArr.count];
  274. _leftHeadView.titleLabel.text = titleStr;
  275. [_leftHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  276. [_leftHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  277. if(letfArr.count == 0){
  278. _leftHeadView.hidden = YES;
  279. }
  280. else{
  281. _leftHeadView.hidden = NO;
  282. }
  283. }
  284. if(midArr){
  285. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  286. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  287. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,midArr.count];
  288. _midHeadView.titleLabel.text = titleStr;
  289. [_midHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  290. if(midArr.count == 0){
  291. _midHeadView.hidden = YES;
  292. }
  293. else{
  294. _midHeadView.hidden = NO;
  295. }
  296. }
  297. if(rightArr){
  298. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  299. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  300. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,midArr.count];
  301. _rightHeadView.titleLabel.text = titleStr;
  302. [_rightHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  303. if(rightArr.count == 0){
  304. _rightHeadView.hidden = YES;
  305. }
  306. else{
  307. _rightHeadView.hidden = NO;
  308. }
  309. }
  310. }
  311. #pragma mark 点击上传中的全部暂停
  312. - (void)didClickAllSuspendInLoadingFun
  313. {
  314. _leftHeadView.rightButton.selected = !_leftHeadView.rightButton.selected;
  315. if(_leftHeadView.rightButton.selected){
  316. [[uploadFileManager shareInstance] suspendUploadFileFun:YES];
  317. }
  318. else{
  319. NSMutableArray *leftArr = _allDataArr[0];
  320. [[uploadFileManager shareInstance] reUploadFileFunBy:leftArr];
  321. }
  322. }
  323. #pragma mark 点击上传成功的清空记录
  324. - (void)didClickClearRecordInDoneFun
  325. {
  326. /*弹窗提示二次确认*/
  327. KWeakSelf
  328. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  329. msg:NSLocalizedString(@"File_upload_Record_clear_Tip_msg",nil)
  330. imageStr:nil
  331. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  332. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  333. didClickOk:^{
  334. [weakSelf ClearAllRecordInDoneFun];
  335. } didClickCancel:^{
  336. }];
  337. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  338. [self.window.rootViewController presentViewController:nextVC animated:YES completion:^{
  339. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  340. }];
  341. }
  342. - (void)ClearAllRecordInDoneFun
  343. {
  344. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_allDataArr[1] withDelCache:YES complete:^(BOOL isSuccess) {
  345. HLog(@"isSuccess:%d",isSuccess);
  346. if(isSuccess){
  347. [self->_allDataArr replaceObjectAtIndex:1 withObject:[NSMutableArray new]];
  348. [self reloadAllDataFun];
  349. }
  350. }];
  351. }
  352. #pragma mark 点击上传失败的清空记录
  353. - (void)didClickClearRecordInFailFun
  354. {
  355. /*弹窗提示二次确认*/
  356. KWeakSelf
  357. ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"File_upload_Record_clear_Tip_title",nil)
  358. msg:NSLocalizedString(@"File_upload_Record_clear_Tip_msg",nil)
  359. imageStr:nil
  360. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  361. okTitle:NSLocalizedString(@"other_comment_ok",nil) isOkBtnHighlight:YES
  362. didClickOk:^{
  363. [weakSelf ClearAllRecordInFailFun];
  364. } didClickCancel:^{
  365. }];
  366. nextVC.modalPresentationStyle = UIModalPresentationCustom;
  367. [self.window.rootViewController presentViewController:nextVC animated:YES completion:^{
  368. nextVC.view.superview.backgroundColor = [UIColor clearColor];
  369. }];
  370. }
  371. - (void)ClearAllRecordInFailFun
  372. {
  373. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_allDataArr[2] withDelCache:YES complete:^(BOOL isSuccess) {
  374. HLog(@"isSuccess:%d",isSuccess);
  375. if(isSuccess){
  376. [self->_allDataArr replaceObjectAtIndex:2 withObject:[NSMutableArray new]];
  377. [self reloadAllDataFun];
  378. }
  379. }];
  380. }
  381. -(void)setIsEditType:(BOOL)isEditType
  382. {
  383. _isEditType = isEditType;
  384. if(_isEditType){
  385. _bgScrollV.scrollEnabled = NO;
  386. }
  387. else{
  388. _bgScrollV.scrollEnabled = YES;
  389. [_selectModelArr removeAllObjects];
  390. }
  391. [self reloadAllDataFun];
  392. }
  393. #pragma mark 点击全选
  394. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  395. {
  396. if(isSelectAllType && _allDataArr && _allDataArr.count > (_selectIndex-1)){
  397. _selectModelArr = [NSMutableArray arrayWithArray:_allDataArr[_selectIndex-1]];
  398. [self reloadAllDataFun];
  399. }
  400. }
  401. #pragma mark 单个点击选中 取消
  402. - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet
  403. {
  404. if(isSelcet){
  405. [_selectModelArr addObject:model];
  406. }
  407. else{
  408. [_selectModelArr removeObject:model];
  409. }
  410. }
  411. #pragma mark 单个点击选中后删除
  412. - (void)deleteModelOneByOneFun{
  413. if(!_selectModelArr || _selectModelArr.count==0){
  414. return;
  415. }
  416. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
  417. HLog(@"isSuccess:%d",isSuccess);
  418. if(isSuccess){
  419. NSMutableArray *curArr = self->_allDataArr[self->_selectIndex -1];
  420. [curArr removeObjectsInArray:self->_selectModelArr];
  421. [self reloadAllDataFun];
  422. self->_selectModelArr = [NSMutableArray new];
  423. }
  424. }];
  425. }
  426. #pragma mark 处理上传中的 状态点击事件
  427. - (void)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
  428. {
  429. if (isSuspendType) {
  430. [[uploadFileManager shareInstance] suspendUploadFileFun:NO];
  431. }
  432. else{
  433. NSMutableArray*arr = [NSMutableArray new];
  434. [arr addObject:model];
  435. [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  436. }
  437. }
  438. @end