backupsFilerecordTableView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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 "uploadFileManager.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)setOutSideDataArr:(NSArray *)outSideDataArr
  50. {
  51. _outSideDataArr = outSideDataArr;
  52. [backupsingArr removeAllObjects];
  53. [backupsfailArr removeAllObjects];
  54. [backupsDoneArr removeAllObjects];
  55. if(outSideDataArr && outSideDataArr.count >0){
  56. for (photosBackupsTaskModel*model in outSideDataArr) {
  57. if(model.curBackupsState == backupsStateUploading
  58. ||model.curBackupsState == backupsStateSuspend){
  59. [backupsingArr addObject:model];
  60. }
  61. else if(model.curBackupsState == backupsStateFail){
  62. [backupsfailArr addObject:model];
  63. }
  64. else{
  65. [backupsDoneArr addObject:model];
  66. }
  67. }
  68. }
  69. if(backupsingArr.count > 0){
  70. [_curDataArr addObject:backupsingArr];
  71. }
  72. if(backupsfailArr.count > 0){
  73. [_curDataArr addObject:backupsfailArr];
  74. }
  75. if(backupsDoneArr.count > 0){
  76. [_curDataArr addObject:backupsDoneArr];
  77. }
  78. [self reloadDataFun];
  79. }
  80. #pragma mark - 列表委托
  81. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  82. return _curDataArr.count;
  83. }
  84. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  85. if(_curDataArr.count > section){
  86. NSArray *curArr = _curDataArr[section];
  87. return curArr.count;
  88. }
  89. return 0;
  90. }
  91. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  92. NSInteger row = indexPath.row;
  93. NSInteger section = indexPath.section;
  94. static NSString *identifier = @"backupsFileRecordCell";
  95. backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  96. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  97. if (!cell){
  98. cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  99. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  100. [cell setBackgroundColor:[UIColor clearColor]];
  101. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  102. }
  103. if(section <_curDataArr.count){
  104. NSMutableArray *curArr = _curDataArr[section];
  105. if(row < curArr.count){
  106. uploadFileDataModel *model = curArr[row];
  107. cell.curPhotosBackupsTaskModel = model;
  108. cell.isEditType = _isEditType;
  109. if(_isEditType){
  110. if([_selectModelArr containsObject:model]){
  111. cell.isSelectType = YES;
  112. }
  113. else{
  114. cell.isSelectType = NO;
  115. }
  116. }
  117. KWeakSelf
  118. cell.didLongPressClick = ^{
  119. [weakSelf didLongPressClickFun];
  120. };
  121. cell.didClckSelectBut = ^(BOOL isSelect) {
  122. [weakSelf selectModelOneByOne:model BySelect:isSelect];
  123. };
  124. cell.didTapPressClick = ^{
  125. if(model.curUploadStateType == uploadStateUploading){
  126. [weakSelf handleUploadingStateTapFunBy:YES with:model];
  127. }
  128. else if(model.curUploadStateType == uploadStateSuspend){
  129. [weakSelf handleUploadingStateTapFunBy:NO with:model];
  130. }
  131. else if(model.curUploadStateType == uploadStateFail){
  132. [weakSelf handleUploadFailStateWith:model];
  133. }
  134. };
  135. }
  136. }
  137. return cell;
  138. }
  139. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  140. return 70;
  141. }
  142. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  143. {
  144. UIView* headView = [UIView new];
  145. headView.backgroundColor = [UIColor whiteColor];
  146. UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)];
  147. titleLabel.font = [UIFont systemFontOfSize:12.0];
  148. titleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  149. [headView addSubview:titleLabel];
  150. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  151. if(section == 2){
  152. curType = 2;
  153. }
  154. else if(section == 1){
  155. if(backupsingArr.count == 0){
  156. curType = 2;
  157. }
  158. else if(backupsfailArr.count == 0){
  159. curType = 2;
  160. }
  161. else{
  162. curType = 1;
  163. }
  164. }
  165. else{
  166. if(backupsingArr.count > 0){
  167. curType = 0;
  168. }
  169. else if(backupsfailArr.count > 0){
  170. curType = 1;
  171. }
  172. else{
  173. curType = 2;
  174. }
  175. }
  176. NSString *text = @"";
  177. if(curType == 0){
  178. text = NSLocalizedString(@"File_Transfer_List_head_title_ing",nil);
  179. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsingArr.count];
  180. }
  181. else if(curType == 1){
  182. text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil);
  183. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsfailArr.count];
  184. }
  185. else{
  186. text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil);
  187. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,backupsDoneArr.count];
  188. }
  189. titleLabel.text = text;
  190. return headView;
  191. }
  192. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  193. {
  194. return 50;
  195. }
  196. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  197. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  198. }
  199. #pragma mark 空数据
  200. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  201. NSString *imageName = @"uploadFile_noData";
  202. if(self.tag == 101){
  203. imageName = @"uploadFile_noData";
  204. }
  205. else if(self.tag == 102){
  206. imageName = @"uploadFile_noData";
  207. }
  208. return [UIImage imageNamed:imageName];
  209. }
  210. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  211. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  212. if(self.tag == 101){
  213. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  214. }
  215. else if(self.tag == 102){
  216. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  217. }
  218. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  219. NSForegroundColorAttributeName: HW999999Color};
  220. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  221. }
  222. //调整图片位置
  223. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  224. return -150;
  225. }
  226. -(void)reloadDataFun{
  227. mainBlock(^{
  228. [self RefresHeadUIFun];
  229. [self reloadData];
  230. });
  231. }
  232. #pragma mark 熟悉头部数据
  233. -(void)RefresHeadUIFun
  234. {
  235. uploadFileRecordTableViewHeadView *headView = (uploadFileRecordTableViewHeadView *)self.tableHeaderView;
  236. if(!headView || ![headView isKindOfClass:[uploadFileRecordTableViewHeadView class]]){
  237. return;
  238. }
  239. if(!_curDataArr ||_curDataArr.count ==0){
  240. headView.hidden = YES;
  241. return;
  242. }
  243. headView.hidden = NO;
  244. NSInteger tag = self.tag;
  245. if(tag == 100){
  246. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  247. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  248. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  249. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  250. headView.titleLabel.text = titleStr;
  251. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  252. [headView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  253. }
  254. else if(tag == 101){
  255. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  256. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  257. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  258. headView.titleLabel.text = titleStr;
  259. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  260. }
  261. else if(tag == 102){
  262. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  263. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  264. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  265. headView.titleLabel.text = titleStr;
  266. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  267. }
  268. }
  269. #pragma mark 点击全选
  270. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  271. {
  272. _selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  273. [self reloadDataFun];
  274. }
  275. -(void)setIsEditType:(BOOL)isEditType
  276. {
  277. _isEditType = isEditType;
  278. if(_isEditType){
  279. //_bgScrollV.scrollEnabled = NO;
  280. }
  281. else{
  282. //_bgScrollV.scrollEnabled = YES;
  283. [_selectModelArr removeAllObjects];
  284. }
  285. [self reloadDataFun];
  286. }
  287. #pragma mark cell长按时间
  288. - (void)didLongPressClickFun{
  289. self.isEditType = YES;
  290. if(self->_didLongPressClick){
  291. self->_didLongPressClick();
  292. }
  293. }
  294. #pragma mark 单个点击选中 取消
  295. - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet
  296. {
  297. if(isSelcet){
  298. [_selectModelArr addObject:model];
  299. }
  300. else{
  301. [_selectModelArr removeObject:model];
  302. }
  303. }
  304. #pragma mark 单个点击选中后删除
  305. - (void)deleteModelOneByOneFun{
  306. if(!_selectModelArr || _selectModelArr.count==0){
  307. return;
  308. }
  309. KWeakSelf
  310. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
  311. HLog(@"isSuccess:%d",isSuccess);
  312. if(isSuccess){
  313. NSMutableArray *curArr = self->_curDataArr;
  314. [curArr removeObjectsInArray:self->_selectModelArr];
  315. [weakSelf reloadDataFun];
  316. self->_selectModelArr = [NSMutableArray new];
  317. }
  318. }];
  319. }
  320. #pragma mark 处理上传中的 状态点击事件
  321. - (void)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
  322. {
  323. if (isSuspendType) {
  324. [[uploadFileManager shareInstance] suspendUploadFileFun:NO];
  325. }
  326. else{
  327. NSMutableArray*arr = [NSMutableArray new];
  328. [arr addObject:model];
  329. [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  330. }
  331. }
  332. #pragma mark 处理上传中的 状态点击事件
  333. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  334. [_curDataArr removeObject:model];
  335. [self reloadDataFun];
  336. if(_didClickReUploadBlock){
  337. _didClickReUploadBlock(model);
  338. }
  339. NSMutableArray*arr = [NSMutableArray new];
  340. model.curUploadStateType = uploadStateWait;
  341. [arr addObject:model];
  342. [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  343. }
  344. @end