uploadFileRecordTableView.m 13 KB

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