uploadFileRecordTableView.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //
  2. // uploadFileRecordTableView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/22.
  6. //
  7. #import "uploadFileRecordTableView.h"
  8. #import "uploadFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileManager.h"
  11. #import "uploadFileRecordTableViewHeadView.h"
  12. @interface uploadFileRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  13. {
  14. }
  15. @property (nonatomic, strong) NSMutableArray *curDataArr;
  16. @end
  17. @implementation uploadFileRecordTableView
  18. - (id)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self initCommon];
  22. [self initTableHeaderInSectionFun];
  23. _selectModelArr = [NSMutableArray new];
  24. _curDataArr = [NSMutableArray new];
  25. _isfirstRefreshType = YES;
  26. }
  27. return self;
  28. }
  29. - (void)initCommon {
  30. self.delegate = self;
  31. self.dataSource = self;
  32. self.showsVerticalScrollIndicator = NO;
  33. self.showsHorizontalScrollIndicator = NO;
  34. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  35. [self setSeparatorColor:[UIColor clearColor]];
  36. [self setBackgroundColor:[UIColor clearColor]];
  37. [self setTableFooterView:[UIView new]];
  38. [self setBounces:YES];
  39. if (@available(iOS 15.0, *)) {
  40. self.sectionHeaderTopPadding = 0;
  41. }
  42. //空数据引入第三方开源处理
  43. self.emptyDataSetSource = self;
  44. self.emptyDataSetDelegate = self;
  45. }
  46. - (void)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
  47. if(!outSideDataArr || outSideDataArr.count != 3){
  48. return;
  49. }
  50. _outSideDataArr = outSideDataArr;
  51. _uploadingArr = outSideDataArr[0];
  52. _uploadDoneArr = outSideDataArr[1];
  53. _uploadfailArr = outSideDataArr[2];
  54. [self RefreshAllDataFun];
  55. }
  56. - (void)RefreshAllDataFun
  57. {
  58. NSMutableArray *totalArr = [NSMutableArray new];
  59. if(_uploadingArr.count>0){
  60. [totalArr addObject:_uploadingArr];
  61. }
  62. if(_uploadfailArr.count>0){
  63. [totalArr addObject:_uploadfailArr];
  64. }
  65. if(_uploadDoneArr.count>0){
  66. [totalArr addObject:_uploadDoneArr];
  67. }
  68. _curDataArr = totalArr;
  69. [self reloadDataFun];
  70. }
  71. #pragma mark - 列表委托
  72. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  73. return _curDataArr.count;
  74. }
  75. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  76. if(section < _curDataArr.count){
  77. NSArray *curArr = _curDataArr[section];
  78. return curArr.count;
  79. }
  80. return 0;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  83. NSInteger row = indexPath.row;
  84. NSInteger section = indexPath.section;
  85. static NSString *identifier = @"uploadFileRecordCell";
  86. uploadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  87. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  88. if (!cell){
  89. cell = [[uploadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  90. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  91. [cell setBackgroundColor:[UIColor clearColor]];
  92. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  93. }
  94. if(section < _curDataArr.count){
  95. NSMutableArray *curArr = _curDataArr[section];
  96. if(row < curArr.count){
  97. uploadFileDataModel *model = curArr[row];
  98. cell.curUploadFileDataModel = model;
  99. cell.isEditType = _isEditType;
  100. if(_isEditType){
  101. if([_selectModelArr containsObject:model]){
  102. cell.isSelectType = YES;
  103. }
  104. else{
  105. cell.isSelectType = NO;
  106. }
  107. }
  108. KWeakSelf
  109. cell.didLongPressClick = ^{
  110. [weakSelf didLongPressClickFun];
  111. };
  112. cell.didClckSelectBut = ^(BOOL isSelect) {
  113. [weakSelf selectModelOneByOne:model BySelect:isSelect];
  114. };
  115. cell.didTapPressClick = ^{
  116. if(model.curUploadStateType == uploadStateUploading){
  117. model.curUploadStateType = uploadStateSuspend;
  118. [weakSelf handleUploadingStateTapFunBy:YES with:model];
  119. }
  120. else if(model.curUploadStateType == uploadStateSuspend){
  121. model.curUploadStateType = uploadStateUploading;
  122. [weakSelf handleUploadingStateTapFunBy:NO with:model];
  123. }
  124. else if(model.curUploadStateType == uploadStateFail){
  125. [weakSelf handleUploadFailStateWith:model];
  126. }
  127. };
  128. }
  129. }
  130. return cell;
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  133. return 70;
  134. }
  135. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  136. {
  137. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  138. if(section == 2){
  139. curType = 2;
  140. }
  141. else if(section == 1){
  142. if(_uploadingArr.count == 0){
  143. curType = 2;
  144. }
  145. else if(_uploadfailArr.count == 0){
  146. curType = 2;
  147. }
  148. else{
  149. curType = 1;
  150. }
  151. }
  152. else{
  153. if(_uploadingArr.count > 0){
  154. curType = 0;
  155. }
  156. else if(_uploadfailArr.count > 0){
  157. curType = 1;
  158. }
  159. else{
  160. curType = 2;
  161. }
  162. }
  163. [self RefresHeadUIFun];
  164. if(curType == 2){
  165. return _doneHeadView;
  166. }
  167. else if(curType == 1){
  168. return _failHeadView;
  169. }
  170. else{
  171. return _uploadingHeadView;
  172. }
  173. }
  174. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  175. {
  176. return 40;
  177. }
  178. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  179. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  180. }
  181. #pragma mark 空数据
  182. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  183. NSString *imageName = @"uploadFile_noData";
  184. if(self.tag == 101){
  185. imageName = @"uploadFile_noData";
  186. }
  187. else if(self.tag == 102){
  188. imageName = @"uploadFile_noData";
  189. }
  190. return [UIImage imageNamed:imageName];
  191. }
  192. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  193. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  194. if(self.tag == 101){
  195. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  196. }
  197. else if(self.tag == 102){
  198. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  199. }
  200. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  201. NSForegroundColorAttributeName: HW999999Color};
  202. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  203. }
  204. //调整图片位置
  205. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  206. return -150;
  207. }
  208. -(void)reloadDataFun{
  209. mainBlock(^{
  210. [self RefresHeadUIFun];
  211. [self reloadData];
  212. });
  213. }
  214. #pragma mark 初始化段头
  215. - (void)initTableHeaderInSectionFun
  216. {
  217. KWeakSelf
  218. if(!_uploadingHeadView){
  219. _uploadingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  220. //headView.backgroundColor = [UIColor greenColor];
  221. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  222. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  223. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  224. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadingArr.count];
  225. _uploadingHeadView.titleLabel.text = titleStr;
  226. [_uploadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  227. [_uploadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  228. _uploadingHeadView.didClickButFun = ^{
  229. [weakSelf didClickRightButtonFun:0];
  230. };
  231. }
  232. if(!_failHeadView){
  233. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  234. //headView.backgroundColor = [UIColor greenColor];
  235. NSString *leftStr = NSLocalizedString(@"File_upload_Record_upload_fail",nil);
  236. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  237. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadfailArr.count];
  238. _failHeadView.titleLabel.text = titleStr;
  239. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  240. _failHeadView.didClickButFun = ^{
  241. [weakSelf didClickRightButtonFun:2];
  242. };
  243. }
  244. if(!_doneHeadView){
  245. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  246. //headView.backgroundColor = [UIColor greenColor];
  247. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  248. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  249. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadDoneArr.count];
  250. _doneHeadView.titleLabel.text = titleStr;
  251. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  252. _doneHeadView.didClickButFun = ^{
  253. [weakSelf didClickRightButtonFun:1];
  254. };
  255. }
  256. }
  257. #pragma mark 点击头部右边按钮
  258. - (void)didClickRightButtonFun:(NSInteger)section
  259. {
  260. if(_uploadingHeadView.rightButton.selected){
  261. for (uploadFileDataModel*model in _uploadingArr) {
  262. model.curUploadStateType = uploadStateSuspend;
  263. }
  264. }
  265. if(_didClickSectionHeadViewRightButton){
  266. _didClickSectionHeadViewRightButton(section);
  267. }
  268. [self reloadData];
  269. }
  270. #pragma mark 刷新头部数据
  271. -(void)RefresHeadUIFun
  272. {
  273. if(_uploadingHeadView){
  274. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  275. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  276. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  277. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadingArr.count];
  278. _uploadingHeadView.titleLabel.text = titleStr;
  279. [_uploadingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  280. [_uploadingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  281. if(_uploadingArr.count == 0){
  282. _uploadingHeadView.hidden = YES;
  283. }
  284. else{
  285. _uploadingHeadView.hidden = NO;
  286. if(_isfirstRefreshType){
  287. BOOL isAllUploadingType = NO;
  288. // if([nasMixUploadManager shareManager].isUploadIngType){
  289. // isAllUploadingType = YES;
  290. // }
  291. HLog(@"上传刷新头部按钮 开始遍历")
  292. @synchronized (self) {
  293. for (uploadFileDataModel*model in _uploadingArr) {
  294. if(model.curUploadStateType != uploadStateUploading){
  295. isAllUploadingType = YES;
  296. break;
  297. }
  298. }
  299. _uploadingHeadView.rightButton.selected = isAllUploadingType;
  300. _isfirstRefreshType = NO;
  301. }
  302. HLog(@"上传刷新头部按钮 结束遍历")
  303. }
  304. }
  305. }
  306. if(_failHeadView){
  307. NSString *leftStr = NSLocalizedString(@"File_upload_Record_upload_fail",nil);
  308. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  309. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadfailArr.count];
  310. _failHeadView.titleLabel.text = titleStr;
  311. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  312. if(_uploadfailArr.count == 0){
  313. _failHeadView.hidden = YES;
  314. }
  315. else{
  316. _failHeadView.hidden = NO;
  317. }
  318. }
  319. if(_doneHeadView){
  320. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  321. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  322. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_uploadDoneArr.count];
  323. _doneHeadView.titleLabel.text = titleStr;
  324. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  325. if(_uploadDoneArr.count == 0){
  326. _doneHeadView.hidden = YES;
  327. }
  328. else{
  329. _doneHeadView.hidden = NO;
  330. }
  331. }
  332. }
  333. #pragma mark 点击全选
  334. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  335. {
  336. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  337. _selectModelArr = [NSMutableArray new];
  338. if(isSelectAllType){
  339. [_selectModelArr addObjectsFromArray:_uploadingArr];
  340. [_selectModelArr addObjectsFromArray:_uploadfailArr];
  341. [_selectModelArr addObjectsFromArray:_uploadDoneArr];
  342. }
  343. [self reloadDataFun];
  344. }
  345. -(void)setIsEditType:(BOOL)isEditType
  346. {
  347. _isEditType = isEditType;
  348. if(_isEditType){
  349. //_bgScrollV.scrollEnabled = NO;
  350. }
  351. else{
  352. //_bgScrollV.scrollEnabled = YES;
  353. [_selectModelArr removeAllObjects];
  354. }
  355. [self reloadDataFun];
  356. }
  357. #pragma mark cell长按时间
  358. - (void)didLongPressClickFun{
  359. self.isEditType = YES;
  360. if(self->_didLongPressClick){
  361. self->_didLongPressClick();
  362. }
  363. }
  364. #pragma mark 单个点击选中 取消
  365. - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet
  366. {
  367. if(isSelcet){
  368. [_selectModelArr addObject:model];
  369. }
  370. else{
  371. [_selectModelArr removeObject:model];
  372. }
  373. }
  374. #pragma mark 单个点击选中后删除
  375. - (void)deleteModelOneByOneFun{
  376. if(!_selectModelArr || _selectModelArr.count==0){
  377. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  378. [SVProgressHUD dismiss];
  379. });
  380. return;
  381. }
  382. KWeakSelf
  383. [[nasUploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
  384. HLog(@"isSuccess:%d",isSuccess);
  385. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  386. [SVProgressHUD dismiss];
  387. });
  388. if(isSuccess){
  389. // NSMutableArray *curArr = self->_curDataArr;
  390. // [curArr removeObjectsInArray:self->_selectModelArr];
  391. // [weakSelf reloadDataFun];
  392. self->_selectModelArr = [NSMutableArray new];
  393. //重新拿数据
  394. [weakSelf refreshGetDatabaseFun];
  395. }
  396. }];
  397. }
  398. #pragma mark 删除后重新拿数据
  399. - (void)refreshGetDatabaseFun
  400. {
  401. if(_didNeedRefreshGetDatabaseFun){
  402. _didNeedRefreshGetDatabaseFun();
  403. }
  404. }
  405. #pragma mark 处理上传中的 状态点击事件
  406. - (void)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
  407. {
  408. if (isSuspendType) {
  409. //[[uploadFileManager shareInstance] suspendUploadFileFun:NO withModel:model];
  410. [[nasUploadFileManager shareInstance] suspendUploadFileFun:NO withModel:model];
  411. }
  412. else{
  413. NSMutableArray*arr = [NSMutableArray new];
  414. [arr addObject:model];
  415. //[[uploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
  416. [[nasUploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
  417. }
  418. [self reloadDataFun];
  419. }
  420. #pragma mark 处理上传中的 状态点击事件
  421. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  422. if(_uploadfailArr && _uploadfailArr.count > 0){
  423. [_uploadfailArr removeObject:model];
  424. }
  425. //添加到上传中的列表
  426. if(!_uploadingArr){
  427. _uploadingArr = [NSMutableArray new];
  428. }
  429. model.curUploadStateType = uploadStateUploading;
  430. [_uploadingArr addObject:model];
  431. [self RefreshAllDataFun];
  432. if(_didClickReUploadBlock){
  433. _didClickReUploadBlock(model);
  434. }
  435. NSMutableArray*arr = [NSMutableArray new];
  436. model.curUploadStateType = uploadStateUploading;
  437. [arr addObject:model];
  438. //[[uploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
  439. [[nasUploadFileManager shareInstance] reUploadFileFunBy:arr withAll:NO];
  440. }
  441. @end