receiveSaveRecordTableView.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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 = @"common_no_data_pic";
  185. return [UIImage imageNamed:imageName];
  186. }
  187. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  188. NSString *text = NSLocalizedString(@"common_no_data_tip",nil);
  189. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  190. NSForegroundColorAttributeName: HW999999Color};
  191. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  192. }
  193. //调整图片位置
  194. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  195. return -150;
  196. }
  197. -(void)reloadDataFun{
  198. mainBlock(^{
  199. [self RefresHeadUIFun];
  200. [self reloadData];
  201. });
  202. }
  203. #pragma mark 初始化段头
  204. - (void)initTableHeaderInSectionFun
  205. {
  206. KWeakSelf
  207. if(!_boxSaveingHeadView){
  208. _boxSaveingHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  209. //headView.backgroundColor = [UIColor greenColor];
  210. NSString *leftStr = NSLocalizedString(@"box_receive_Record_receiveing",nil);
  211. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  212. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  213. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveingArr.count];
  214. _boxSaveingHeadView.titleLabel.text = titleStr;
  215. // [_boxSaveingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  216. // [_boxSaveingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  217. _boxSaveingHeadView.rightButton.hidden = YES;
  218. _boxSaveingHeadView.didClickButFun = ^{
  219. [weakSelf didClickRightButtonFun:0];
  220. };
  221. }
  222. if(!_failHeadView){
  223. _failHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  224. //headView.backgroundColor = [UIColor greenColor];
  225. NSString *leftStr = NSLocalizedString(@"box_receive_Record_fail",nil);
  226. //NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  227. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSavefailArr.count];
  228. _failHeadView.titleLabel.text = titleStr;
  229. //[_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  230. _failHeadView.rightButton.hidden = YES;
  231. _failHeadView.didClickButFun = ^{
  232. [weakSelf didClickRightButtonFun:2];
  233. };
  234. }
  235. if(!_doneHeadView){
  236. _doneHeadView = [[uploadFileRecordTableViewHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 40)];
  237. //headView.backgroundColor = [UIColor greenColor];
  238. NSString *leftStr = NSLocalizedString(@"box_receive_Record_suc",nil);
  239. //NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  240. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveDoneArr.count];
  241. _doneHeadView.titleLabel.text = titleStr;
  242. //[_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  243. _doneHeadView.rightButton.hidden = YES;
  244. _doneHeadView.didClickButFun = ^{
  245. [weakSelf didClickRightButtonFun:1];
  246. };
  247. }
  248. }
  249. #pragma mark 点击头部右边按钮
  250. - (void)didClickRightButtonFun:(NSInteger)section
  251. {
  252. if(_didClickSectionHeadViewRightButton){
  253. _didClickSectionHeadViewRightButton(section);
  254. }
  255. }
  256. #pragma mark 刷新头部数据
  257. -(void)RefresHeadUIFun
  258. {
  259. if(_boxSaveingHeadView){
  260. NSString *leftStr = NSLocalizedString(@"File_upload_Record_downloading",nil);
  261. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  262. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  263. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveingArr.count];
  264. _boxSaveingHeadView.titleLabel.text = titleStr;
  265. [_boxSaveingHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  266. [_boxSaveingHeadView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  267. if(_boxSavefailArr.count == 0){
  268. _boxSaveingHeadView.hidden = YES;
  269. }
  270. else{
  271. _boxSaveingHeadView.hidden = NO;
  272. }
  273. }
  274. if(_failHeadView){
  275. NSString *leftStr = NSLocalizedString(@"File_upload_Record_download_fail",nil);
  276. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  277. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSavefailArr.count];
  278. _failHeadView.titleLabel.text = titleStr;
  279. [_failHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  280. if(_boxSavefailArr.count == 0){
  281. _failHeadView.hidden = YES;
  282. }
  283. else{
  284. _failHeadView.hidden = NO;
  285. }
  286. }
  287. if(_doneHeadView){
  288. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_download",nil);
  289. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  290. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_boxSaveDoneArr.count];
  291. _doneHeadView.titleLabel.text = titleStr;
  292. [_doneHeadView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  293. if(_boxSaveDoneArr.count == 0){
  294. _doneHeadView.hidden = YES;
  295. }
  296. else{
  297. _doneHeadView.hidden = NO;
  298. }
  299. }
  300. }
  301. #pragma mark 点击全选
  302. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  303. {
  304. //_selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  305. _selectModelArr = [NSMutableArray new];
  306. [_selectModelArr addObjectsFromArray:_boxSaveingArr];
  307. [_selectModelArr addObjectsFromArray:_boxSavefailArr];
  308. [_selectModelArr addObjectsFromArray:_boxSaveDoneArr];
  309. [self reloadDataFun];
  310. }
  311. -(void)setIsEditType:(BOOL)isEditType
  312. {
  313. _isEditType = isEditType;
  314. if(_isEditType){
  315. //_bgScrollV.scrollEnabled = NO;
  316. }
  317. else{
  318. //_bgScrollV.scrollEnabled = YES;
  319. [_selectModelArr removeAllObjects];
  320. }
  321. [self reloadDataFun];
  322. }
  323. #pragma mark cell长按时间
  324. - (void)didLongPressClickFun{
  325. self.isEditType = YES;
  326. if(self->_didLongPressClick){
  327. self->_didLongPressClick();
  328. }
  329. }
  330. #pragma mark 单个点击选中 取消
  331. - (void)selectModelOneByOne:(couldPhoneFileModel*)model BySelect:(BOOL)isSelcet
  332. {
  333. if(isSelcet){
  334. [_selectModelArr addObject:model];
  335. }
  336. else{
  337. [_selectModelArr removeObject:model];
  338. }
  339. }
  340. #pragma mark 单个点击选中后删除
  341. - (void)deleteModelOneByOneFun{
  342. if(!_selectModelArr || _selectModelArr.count==0){
  343. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  344. [SVProgressHUD dismiss];
  345. });
  346. return;
  347. }
  348. //[[downloadManager shareInstance] deleteDownloadFileRecordBy:_selectModelArr withDelCache:YES];
  349. [_selectModelArr removeAllObjects];
  350. //重新拿数据
  351. [self refreshGetDatabaseFun];
  352. }
  353. #pragma mark 删除后重新拿数据
  354. - (void)refreshGetDatabaseFun
  355. {
  356. if(_didNeedRefreshGetDatabaseFun){
  357. _didNeedRefreshGetDatabaseFun();
  358. }
  359. }
  360. #pragma mark 处理上传中的 状态点击事件
  361. - (void)handleDownloadingStateTapFunBy:(BOOL)isSuspendType with:(couldPhoneFileModel*)model
  362. {
  363. // if (isSuspendType) {
  364. // [[downloadManager shareInstance] suspendDownloadFileFun:NO withModel:model];
  365. // }
  366. // else{
  367. // NSMutableArray*arr = [NSMutableArray new];
  368. // [arr addObject:model];
  369. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  370. // }
  371. //
  372. // [self reloadDataFun];
  373. }
  374. #pragma mark 处理上传中的 状态点击事件
  375. - (void)handleUploadFailStateWith:(couldPhoneFileModel*)model{
  376. // [_downloadfailArr removeObject:model];
  377. // [_downloadingArr addObject:model];
  378. //
  379. // [self RefreshAllDataFun];
  380. //
  381. // if(_didClickReUploadBlock){
  382. // _didClickReUploadBlock(model);
  383. // }
  384. //
  385. // NSMutableArray*arr = [NSMutableArray new];
  386. // model.curDownloadStateType = downloadStateWait;
  387. // [arr addObject:model];
  388. // [[downloadManager shareInstance] reDownloadFileFunBy:arr withAll:NO];
  389. }
  390. @end