uploadFileRecordTableView.m 13 KB

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