backupsFilerecordTableView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. //
  2. // backupsFilerecordTableView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/4.
  6. //
  7. #import "backupsFilerecordTableView.h"
  8. #import "UIScrollView+EmptyDataSet.h"
  9. #import "backupsFileManager.h"
  10. #import "backupsFileRecordCell.h"
  11. @interface backupsFilerecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. NSMutableArray *backupsingArr;
  14. NSMutableArray *backupsfailArr;
  15. NSMutableArray *backupsDoneArr;
  16. }
  17. @property (nonatomic, strong) NSMutableArray *curDataArr;
  18. @end
  19. @implementation backupsFilerecordTableView
  20. - (id)initWithFrame:(CGRect)frame {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self initCommon];
  24. _selectModelArr = [NSMutableArray new];
  25. _curDataArr = [NSMutableArray new];
  26. backupsingArr = [NSMutableArray new];
  27. backupsfailArr = [NSMutableArray new];
  28. backupsDoneArr = [NSMutableArray new];
  29. }
  30. return self;
  31. }
  32. - (void)initCommon {
  33. self.delegate = self;
  34. self.dataSource = self;
  35. self.showsVerticalScrollIndicator = NO;
  36. self.showsHorizontalScrollIndicator = NO;
  37. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  38. [self setSeparatorColor:[UIColor clearColor]];
  39. [self setBackgroundColor:[UIColor clearColor]];
  40. [self setTableFooterView:[UIView new]];
  41. [self setBounces:YES];
  42. if (@available(iOS 15.0, *)) {
  43. self.sectionHeaderTopPadding = 0;
  44. }
  45. //空数据引入第三方开源处理
  46. self.emptyDataSetSource = self;
  47. self.emptyDataSetDelegate = self;
  48. }
  49. - (void)setPhotosBackupsIngTaskModel:(photosBackupsTaskModel *)photosBackupsIngTaskModel
  50. {
  51. _photosBackupsIngTaskModel = photosBackupsIngTaskModel;
  52. // if(_photosBackupsIngTaskModel.curBackupsState == backupsStateDone){
  53. // NSInteger i;
  54. // }
  55. if(backupsingArr.count >=1){
  56. if(_photosBackupsIngTaskModel.curBackupsState == backupsStateUploading
  57. || _photosBackupsIngTaskModel.curBackupsState == backupsStateSuspend){
  58. [backupsingArr replaceObjectAtIndex:0 withObject:_photosBackupsIngTaskModel];
  59. }
  60. else if (_photosBackupsIngTaskModel.curBackupsState == backupsStateFail){
  61. [backupsingArr removeObjectAtIndex:0];
  62. [backupsfailArr insertObject:_photosBackupsIngTaskModel atIndex:0];
  63. }
  64. else if (_photosBackupsIngTaskModel.curBackupsState == backupsStateDone){
  65. [backupsingArr removeObjectAtIndex:0];
  66. [backupsDoneArr insertObject:_photosBackupsIngTaskModel atIndex:0];
  67. }
  68. }
  69. else if(_photosBackupsIngTaskModel.curBackupsState == backupsStateUploading)
  70. {//先进界面 再备份
  71. [backupsingArr addObject:_photosBackupsIngTaskModel];
  72. }
  73. NSMutableArray*newDataArr = [NSMutableArray new];
  74. if(backupsingArr.count > 0){
  75. [newDataArr addObject:backupsingArr];
  76. }
  77. if(backupsfailArr.count > 0){
  78. [newDataArr addObject:backupsfailArr];
  79. }
  80. if(backupsDoneArr.count > 0){
  81. [newDataArr addObject:backupsDoneArr];
  82. }
  83. _curDataArr = newDataArr;
  84. [self reloadDataFun];
  85. }
  86. -(void)setOutSideDataArr:(NSArray *)outSideDataArr
  87. {
  88. _outSideDataArr = outSideDataArr;
  89. [backupsingArr removeAllObjects];
  90. [backupsfailArr removeAllObjects];
  91. [backupsDoneArr removeAllObjects];
  92. if(outSideDataArr && outSideDataArr.count >0){
  93. for (photosBackupsTaskModel*model in outSideDataArr) {
  94. if(model.curBackupsState == backupsStateUploading
  95. ||model.curBackupsState == backupsStateSuspend){
  96. [backupsingArr addObject:model];
  97. }
  98. else if(model.curBackupsState == backupsStateFail){
  99. [backupsfailArr addObject:model];
  100. }
  101. else{
  102. [backupsDoneArr addObject:model];
  103. }
  104. }
  105. }
  106. if(backupsingArr.count > 0){
  107. [_curDataArr addObject:backupsingArr];
  108. }
  109. if(backupsfailArr.count > 0){
  110. [_curDataArr addObject:backupsfailArr];
  111. }
  112. if(backupsDoneArr.count > 0){
  113. [_curDataArr addObject:backupsDoneArr];
  114. }
  115. [self reloadDataFun];
  116. }
  117. #pragma mark - 列表委托
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  119. return _curDataArr.count;
  120. }
  121. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  122. if(_curDataArr.count > section){
  123. NSArray *curArr = _curDataArr[section];
  124. return curArr.count;
  125. }
  126. return 0;
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  129. NSInteger row = indexPath.row;
  130. NSInteger section = indexPath.section;
  131. static NSString *identifier = @"backupsFileRecordCell";
  132. backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  133. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  134. if (!cell){
  135. cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  136. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  137. [cell setBackgroundColor:[UIColor clearColor]];
  138. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  139. }
  140. if(section <_curDataArr.count){
  141. NSMutableArray *curArr = _curDataArr[section];
  142. if(row < curArr.count){
  143. photosBackupsTaskModel *model = curArr[row];
  144. cell.curPhotosBackupsTaskModel = model;
  145. //cell.isEditType = _isEditType;
  146. if(_isEditType){
  147. if([_selectModelArr containsObject:model]){
  148. cell.isSelectType = YES;
  149. }
  150. else{
  151. cell.isSelectType = NO;
  152. }
  153. }
  154. KWeakSelf
  155. cell.didLongPressClick = ^{
  156. //[weakSelf didLongPressClickFun];
  157. };
  158. cell.didClckSelectBut = ^(BOOL isSelect) {
  159. //[weakSelf selectModelOneByOne:model BySelect:isSelect];
  160. };
  161. cell.didTapPressClick = ^{
  162. if(model.curBackupsState == backupsStateUploading){
  163. [weakSelf handleBackupsingStateTapFunBy:YES with:model];
  164. }
  165. else if(model.curBackupsState == backupsStateSuspend){
  166. [weakSelf handleBackupsingStateTapFunBy:NO with:model];
  167. }
  168. };
  169. }
  170. }
  171. return cell;
  172. }
  173. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  174. return 70;
  175. }
  176. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  177. {
  178. UIView* headView = [UIView new];
  179. headView.backgroundColor = [UIColor whiteColor];
  180. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)];
  181. titleLabel.font = [UIFont systemFontOfSize:12.0];
  182. titleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  183. [headView addSubview:titleLabel];
  184. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  185. if(section == 2){
  186. curType = 2;
  187. }
  188. else if(section == 1){
  189. if(backupsingArr.count == 0){
  190. curType = 2;
  191. }
  192. else if(backupsfailArr.count == 0){
  193. curType = 2;
  194. }
  195. else{
  196. curType = 1;
  197. }
  198. }
  199. else{
  200. if(backupsingArr.count > 0){
  201. curType = 0;
  202. }
  203. else if(backupsfailArr.count > 0){
  204. curType = 1;
  205. }
  206. else{
  207. curType = 2;
  208. }
  209. }
  210. NSString *text = @"";
  211. if(curType == 0){
  212. text = NSLocalizedString(@"File_Transfer_List_head_title_ing",nil);
  213. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsingArr.count];
  214. }
  215. else if(curType == 1){
  216. text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil);
  217. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsfailArr.count];
  218. }
  219. else{
  220. text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil);
  221. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsDoneArr.count];
  222. }
  223. titleLabel.text = text;
  224. return headView;
  225. }
  226. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  227. {
  228. return 50;
  229. }
  230. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  231. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  232. }
  233. #pragma mark 空数据
  234. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  235. NSString *imageName = @"uploadFile_noData";
  236. if(self.tag == 101){
  237. imageName = @"uploadFile_noData";
  238. }
  239. else if(self.tag == 102){
  240. imageName = @"uploadFile_noData";
  241. }
  242. return [UIImage imageNamed:imageName];
  243. }
  244. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  245. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  246. if(self.tag == 101){
  247. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  248. }
  249. else if(self.tag == 102){
  250. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  251. }
  252. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  253. NSForegroundColorAttributeName: HW999999Color};
  254. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  255. }
  256. //调整图片位置
  257. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  258. return -150;
  259. }
  260. -(void)reloadDataFun{
  261. mainBlock(^{
  262. [self RefresHeadUIFun];
  263. [self reloadData];
  264. });
  265. }
  266. #pragma mark 熟悉头部数据
  267. -(void)RefresHeadUIFun
  268. {
  269. uploadFileRecordTableViewHeadView *headView = (uploadFileRecordTableViewHeadView *)self.tableHeaderView;
  270. if(!headView || ![headView isKindOfClass:[uploadFileRecordTableViewHeadView class]]){
  271. return;
  272. }
  273. if(!_curDataArr ||_curDataArr.count ==0){
  274. headView.hidden = YES;
  275. return;
  276. }
  277. headView.hidden = NO;
  278. NSInteger tag = self.tag;
  279. if(tag == 100){
  280. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  281. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  282. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  283. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  284. headView.titleLabel.text = titleStr;
  285. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  286. [headView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  287. }
  288. else if(tag == 101){
  289. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  290. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  291. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  292. headView.titleLabel.text = titleStr;
  293. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  294. }
  295. else if(tag == 102){
  296. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  297. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  298. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  299. headView.titleLabel.text = titleStr;
  300. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  301. }
  302. }
  303. #pragma mark 点击全选
  304. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  305. {
  306. _selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  307. [self reloadDataFun];
  308. }
  309. -(void)setIsEditType:(BOOL)isEditType
  310. {
  311. _isEditType = isEditType;
  312. if(_isEditType){
  313. //_bgScrollV.scrollEnabled = NO;
  314. }
  315. else{
  316. //_bgScrollV.scrollEnabled = YES;
  317. [_selectModelArr removeAllObjects];
  318. }
  319. [self reloadDataFun];
  320. }
  321. #pragma mark cell长按时间
  322. - (void)didLongPressClickFun{
  323. self.isEditType = YES;
  324. if(self->_didLongPressClick){
  325. self->_didLongPressClick();
  326. }
  327. }
  328. #pragma mark 单个点击选中 取消
  329. - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet
  330. {
  331. if(isSelcet){
  332. [_selectModelArr addObject:model];
  333. }
  334. else{
  335. [_selectModelArr removeObject:model];
  336. }
  337. }
  338. #pragma mark 单个点击选中后删除
  339. - (void)deleteModelOneByOneFun{
  340. // if(!_selectModelArr || _selectModelArr.count==0){
  341. //
  342. // return;
  343. // }
  344. //
  345. // KWeakSelf
  346. // [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
  347. // HLog(@"isSuccess:%d",isSuccess);
  348. //
  349. // if(isSuccess){
  350. // NSMutableArray *curArr = self->_curDataArr;
  351. // [curArr removeObjectsInArray:self->_selectModelArr];
  352. // [weakSelf reloadDataFun];
  353. // self->_selectModelArr = [NSMutableArray new];
  354. // }
  355. // }];
  356. }
  357. #pragma mark 处理上传中的 状态点击事件
  358. - (void)handleBackupsingStateTapFunBy:(BOOL)isSuspendType with:(photosBackupsTaskModel*)model
  359. {
  360. if (isSuspendType) {
  361. model.isSuspendType = YES;
  362. model.curBackupsState = backupsStateSuspend;
  363. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  364. }
  365. else{
  366. [[backupsFileManager shareInstance] reBackupsFileFunBy:model];
  367. }
  368. }
  369. #pragma mark 处理上传中的 状态点击事件
  370. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  371. // [_curDataArr removeObject:model];
  372. // [self reloadDataFun];
  373. //
  374. // if(_didClickReUploadBlock){
  375. // _didClickReUploadBlock(model);
  376. // }
  377. //
  378. // NSMutableArray*arr = [NSMutableArray new];
  379. // model.curUploadStateType = uploadStateWait;
  380. // [arr addObject:model];
  381. // [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  382. }
  383. @end