uploadFileRecordTableView.m 16 KB

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