receiveSaveRecordTableView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. //
  2. // receiveSaveRecordTableView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/23.
  6. //
  7. #import "receiveSaveRecordTableView.h"
  8. #import "boxReceiveFileRecordCell.h"
  9. #import "UIScrollView+EmptyDataSet.h"
  10. #import "uploadFileRecordTableViewHeadView.h"
  11. @interface receiveSaveRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. }
  14. @property (nonatomic, strong) NSMutableArray *curDataArr;
  15. @end
  16. @implementation receiveSaveRecordTableView
  17. - (id)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initCommon];
  21. [self initTableHeaderInSectionFun];
  22. _selectModelArr = [NSMutableArray new];
  23. _curDataArr = [NSMutableArray new];
  24. }
  25. return self;
  26. }
  27. - (void)initCommon {
  28. self.delegate = self;
  29. self.dataSource = self;
  30. self.showsVerticalScrollIndicator = NO;
  31. self.showsHorizontalScrollIndicator = NO;
  32. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  33. [self setSeparatorColor:[UIColor clearColor]];
  34. [self setBackgroundColor:[UIColor clearColor]];
  35. [self setTableFooterView:[UIView new]];
  36. [self setBounces:YES];
  37. if (@available(iOS 15.0, *)) {
  38. self.sectionHeaderTopPadding = 0;
  39. }
  40. //空数据引入第三方开源处理
  41. self.emptyDataSetSource = self;
  42. self.emptyDataSetDelegate = self;
  43. }
  44. - (void)setOutSideDataArr:(NSMutableArray *)outSideDataArr{
  45. if(!outSideDataArr || outSideDataArr.count != 3){
  46. return;
  47. }
  48. _outSideDataArr = outSideDataArr;
  49. _boxSaveingArr = outSideDataArr[0];
  50. _boxSaveDoneArr = outSideDataArr[1];
  51. _boxSavefailArr = outSideDataArr[2];
  52. //test code
  53. _boxSaveDoneArr = outSideDataArr[0];
  54. _boxSavefailArr = outSideDataArr[0];
  55. [self RefreshAllDataFun];
  56. }
  57. - (void)RefreshAllDataFun
  58. {
  59. NSMutableArray *totalArr = [NSMutableArray new];
  60. if(_boxSaveingArr.count>0){
  61. [totalArr addObject:_boxSaveingArr];
  62. }
  63. if(_boxSavefailArr.count>0){
  64. [totalArr addObject:_boxSavefailArr];
  65. }
  66. if(_boxSaveDoneArr.count>0){
  67. [totalArr addObject:_boxSaveDoneArr];
  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 = @"boxReceiveFileRecordCell";
  87. boxReceiveFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  88. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  89. if (!cell){
  90. cell = [[boxReceiveFileRecordCell 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. ShareFileDataModel *model = curArr[row];
  99. cell.curShareFileDataModel = 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.curDownloadStateType == downloadStateUploading){
  118. // model.curDownloadStateType = downloadStateSuspend;
  119. // [weakSelf handleDownloadingStateTapFunBy:YES with:model];
  120. // }
  121. // else if(model.curDownloadStateType == downloadStateSuspend){
  122. // model.curDownloadStateType = downloadStateUploading;
  123. // [weakSelf handleDownloadingStateTapFunBy:NO with:model];
  124. // }
  125. // else if(model.curDownloadStateType == downloadStateFail){
  126. // [weakSelf handleUploadFailStateWith:model];
  127. // }
  128. };
  129. }
  130. }
  131. return cell;
  132. }
  133. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  134. return 70;
  135. }
  136. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  137. {
  138. NSInteger curType = 0;// 0 上传中 1 失败 2 完成
  139. if(section == 2){
  140. curType = 2;
  141. }
  142. else if(section == 1){
  143. if(_boxSaveingArr.count == 0){
  144. curType = 2;
  145. }
  146. else if(_boxSavefailArr.count == 0){
  147. curType = 2;
  148. }
  149. else{
  150. curType = 1;
  151. }
  152. }
  153. else{
  154. if(_boxSaveingArr.count > 0){
  155. curType = 0;
  156. }
  157. else if(_boxSavefailArr.count > 0){
  158. curType = 1;
  159. }
  160. else{
  161. curType = 2;
  162. }
  163. }
  164. [self RefresHeadUIFun];
  165. if(curType == 2){
  166. return _doneHeadView;
  167. }
  168. else if(curType == 1){
  169. return _failHeadView;
  170. }
  171. else{
  172. return _boxSaveingHeadView;
  173. }
  174. }
  175. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  176. {
  177. return 40;
  178. }
  179. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  180. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  181. }
  182. #pragma mark 空数据
  183. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  184. NSString *imageName = @"uploadFile_noData";
  185. if(self.tag == 101){
  186. imageName = @"uploadFile_noData";
  187. }
  188. else if(self.tag == 102){
  189. imageName = @"uploadFile_noData";
  190. }
  191. return [UIImage imageNamed:imageName];
  192. }
  193. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  194. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  195. if(self.tag == 101){
  196. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  197. }
  198. else if(self.tag == 102){
  199. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  200. }
  201. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  202. NSForegroundColorAttributeName: HW999999Color};
  203. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  204. }
  205. //调整图片位置
  206. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  207. return -150;
  208. }
  209. -(void)reloadDataFun{
  210. mainBlock(^{
  211. [self RefresHeadUIFun];
  212. [self reloadData];
  213. });
  214. }
  215. #pragma mark 初始化段头
  216. - (void)initTableHeaderInSectionFun
  217. {
  218. KWeakSelf
  219. if(!_boxSaveingHeadView){
  220. _boxSaveingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  221. //headView.backgroundColor = [UIColor greenColor];
  222. NSString *leftStr = NSLocalizedString(@"box_receive_Record_receiveing",nil);
  223. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  224. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  225. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveingArr.count];
  226. _boxSaveingHeadView.titleLabel.text = titleStr;
  227. // [_boxSaveingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  228. // [_boxSaveingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  229. _boxSaveingHeadView.rightButton.hidden = YES;
  230. _boxSaveingHeadView.didClickButFun = ^{
  231. [weakSelf didClickRightButtonFun:0];
  232. };
  233. }
  234. if(!_failHeadView){
  235. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  236. //headView.backgroundColor = [UIColor greenColor];
  237. NSString *leftStr = NSLocalizedString(@"box_receive_Record_fail",nil);
  238. //NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  239. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSavefailArr.count];
  240. _failHeadView.titleLabel.text = titleStr;
  241. //[_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  242. _failHeadView.rightButton.hidden = YES;
  243. _failHeadView.didClickButFun = ^{
  244. [weakSelf didClickRightButtonFun:2];
  245. };
  246. }
  247. if(!_doneHeadView){
  248. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  249. //headView.backgroundColor = [UIColor greenColor];
  250. NSString *leftStr = NSLocalizedString(@"box_receive_Record_suc",nil);
  251. //NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  252. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveDoneArr.count];
  253. _doneHeadView.titleLabel.text = titleStr;
  254. //[_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  255. _doneHeadView.rightButton.hidden = YES;
  256. _doneHeadView.didClickButFun = ^{
  257. [weakSelf didClickRightButtonFun:1];
  258. };
  259. }
  260. }
  261. #pragma mark 点击头部右边按钮
  262. - (void)didClickRightButtonFun:(NSInteger)section
  263. {
  264. if(_didClickSectionHeadViewRightButton){
  265. _didClickSectionHeadViewRightButton(section);
  266. }
  267. }
  268. #pragma mark 刷新头部数据
  269. -(void)RefresHeadUIFun
  270. {
  271. if(_boxSaveingHeadView){
  272. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  273. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  274. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  275. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveingArr.count];
  276. _boxSaveingHeadView.titleLabel.text = titleStr;
  277. [_boxSaveingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  278. [_boxSaveingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  279. if(_boxSavefailArr.count == 0){
  280. _boxSaveingHeadView.hidden = YES;
  281. }
  282. else{
  283. _boxSaveingHeadView.hidden = NO;
  284. }
  285. }
  286. if(_failHeadView){
  287. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  288. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  289. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSavefailArr.count];
  290. _failHeadView.titleLabel.text = titleStr;
  291. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  292. if(_boxSavefailArr.count == 0){
  293. _failHeadView.hidden = YES;
  294. }
  295. else{
  296. _failHeadView.hidden = NO;
  297. }
  298. }
  299. if(_doneHeadView){
  300. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  301. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  302. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveDoneArr.count];
  303. _doneHeadView.titleLabel.text = titleStr;
  304. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  305. if(_boxSaveDoneArr.count == 0){
  306. _doneHeadView.hidden = YES;
  307. }
  308. else{
  309. _doneHeadView.hidden = NO;
  310. }
  311. }
  312. }
  313. #pragma mark 点击全选
  314. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  315. {
  316. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  317. _selectModelArr = [NSMutableArray new];
  318. [_selectModelArr addObjectsFromArray:_boxSaveingArr];
  319. [_selectModelArr addObjectsFromArray:_boxSavefailArr];
  320. [_selectModelArr addObjectsFromArray:_boxSaveDoneArr];
  321. [self reloadDataFun];
  322. }
  323. -(void)setIsEditType:(BOOL)isEditType
  324. {
  325. _isEditType = isEditType;
  326. if(_isEditType){
  327. //_bgScrollV.scrollEnabled = NO;
  328. }
  329. else{
  330. //_bgScrollV.scrollEnabled = YES;
  331. [_selectModelArr removeAllObjects];
  332. }
  333. [self reloadDataFun];
  334. }
  335. #pragma mark cell长按时间
  336. - (void)didLongPressClickFun{
  337. self.isEditType = YES;
  338. if(self->_didLongPressClick){
  339. self->_didLongPressClick();
  340. }
  341. }
  342. #pragma mark 单个点击选中 取消
  343. - (void)selectModelOneByOne:(couldPhoneFileModel*)model BySelect:(BOOL)isSelcet
  344. {
  345. if(isSelcet){
  346. [_selectModelArr addObject:model];
  347. }
  348. else{
  349. [_selectModelArr removeObject:model];
  350. }
  351. }
  352. #pragma mark 单个点击选中后删除
  353. - (void)deleteModelOneByOneFun{
  354. if(!_selectModelArr || _selectModelArr.count==0){
  355. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  356. [SVProgressHUD dismiss];
  357. });
  358. return;
  359. }
  360. //[[downloadManager shareInstance] deleteDownloadFileRecordBy:_selectModelArr withDelCache:YES];
  361. [_selectModelArr removeAllObjects];
  362. //重新拿数据
  363. [self refreshGetDatabaseFun];
  364. }
  365. #pragma mark 删除后重新拿数据
  366. - (void)refreshGetDatabaseFun
  367. {
  368. if(_didNeedRefreshGetDatabaseFun){
  369. _didNeedRefreshGetDatabaseFun();
  370. }
  371. }
  372. #pragma mark 处理上传中的 状态点击事件
  373. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
  374. {
  375. // if (isSuspendType) {
  376. // [[downloadManager shareInstance] suspendDownloadFileFun:NO withModel:model];
  377. // }
  378. // else{
  379. // NSMutableArray*arr = [NSMutableArray new];
  380. // [arr addObject:model];
  381. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  382. // }
  383. //
  384. // [self reloadDataFun];
  385. }
  386. #pragma mark 处理上传中的 状态点击事件
  387. - (void)handleUploadFailStateWith:(couldPhoneFileModel*)model{
  388. // [_downloadfailArr removeObject:model];
  389. // [_downloadingArr addObject:model];
  390. //
  391. // [self RefreshAllDataFun];
  392. //
  393. // if(_didClickReUploadBlock){
  394. // _didClickReUploadBlock(model);
  395. // }
  396. //
  397. // NSMutableArray*arr = [NSMutableArray new];
  398. // model.curDownloadStateType = downloadStateWait;
  399. // [arr addObject:model];
  400. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  401. }
  402. @end