uploadFileRecordTableView.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. @interface uploadFileRecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. @end
  13. @implementation uploadFileRecordTableView
  14. - (id)initWithFrame:(CGRect)frame {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. [self initCommon];
  18. _selectModelArr = [NSMutableArray new];
  19. _curDataArr = [NSMutableArray new];
  20. }
  21. return self;
  22. }
  23. - (void)initCommon {
  24. self.delegate = self;
  25. self.dataSource = self;
  26. self.showsVerticalScrollIndicator = NO;
  27. self.showsHorizontalScrollIndicator = NO;
  28. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  29. [self setSeparatorColor:[UIColor clearColor]];
  30. [self setBackgroundColor:[UIColor clearColor]];
  31. [self setTableFooterView:[UIView new]];
  32. [self setBounces:YES];
  33. if (@available(iOS 15.0, *)) {
  34. self.sectionHeaderTopPadding = 0;
  35. }
  36. //空数据引入第三方开源处理
  37. self.emptyDataSetSource = self;
  38. self.emptyDataSetDelegate = self;
  39. }
  40. #pragma mark - 列表委托
  41. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  42. return 1;
  43. }
  44. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  45. if(_curDataArr){
  46. return _curDataArr.count;
  47. }
  48. return 0;
  49. }
  50. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  51. NSInteger row = indexPath.row;
  52. static NSString *identifier = @"uploadFileRecordCell";
  53. uploadFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  54. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  55. if (!cell){
  56. cell = [[uploadFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  57. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  58. [cell setBackgroundColor:[UIColor clearColor]];
  59. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  60. }
  61. NSMutableArray *curArr = _curDataArr;
  62. if(row < curArr.count){
  63. uploadFileDataModel *model = curArr[row];
  64. cell.curUploadFileDataModel = model;
  65. cell.isEditType = _isEditType;
  66. if(_isEditType){
  67. if([_selectModelArr containsObject:model]){
  68. cell.isSelectType = YES;
  69. }
  70. else{
  71. cell.isSelectType = NO;
  72. }
  73. }
  74. KWeakSelf
  75. cell.didLongPressClick = ^{
  76. [weakSelf didLongPressClickFun];
  77. };
  78. cell.didClckSelectBut = ^(BOOL isSelect) {
  79. [weakSelf selectModelOneByOne:model BySelect:isSelect];
  80. };
  81. cell.didTapPressClick = ^{
  82. if(model.curUploadStateType == uploadStateUploading){
  83. [weakSelf handleUploadingStateTapFunBy:YES with:model];
  84. }
  85. else if(model.curUploadStateType == uploadStateSuspend){
  86. [weakSelf handleUploadingStateTapFunBy:NO with:model];
  87. }
  88. else if(model.curUploadStateType == uploadStateFail){
  89. [weakSelf handleUploadFailStateWith:model];
  90. }
  91. };
  92. }
  93. return cell;
  94. }
  95. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  96. return 70;
  97. }
  98. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  99. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  100. }
  101. #pragma mark 空数据
  102. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  103. NSString *imageName = @"uploadFile_noData";
  104. if(self.tag == 101){
  105. imageName = @"uploadFile_noData";
  106. }
  107. else if(self.tag == 102){
  108. imageName = @"uploadFile_noData";
  109. }
  110. return [UIImage imageNamed:imageName];
  111. }
  112. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  113. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  114. if(self.tag == 101){
  115. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  116. }
  117. else if(self.tag == 102){
  118. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  119. }
  120. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  121. NSForegroundColorAttributeName: HW999999Color};
  122. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  123. }
  124. //调整图片位置
  125. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  126. return -150;
  127. }
  128. -(void)reloadDataFun{
  129. mainBlock(^{
  130. [self RefresHeadUIFun];
  131. [self reloadData];
  132. });
  133. }
  134. #pragma mark 熟悉头部数据
  135. -(void)RefresHeadUIFun
  136. {
  137. uploadFileRecordTableViewHeadView *headView = (uploadFileRecordTableViewHeadView *)self.tableHeaderView;
  138. if(!headView || ![headView isKindOfClass:[uploadFileRecordTableViewHeadView class]]){
  139. return;
  140. }
  141. if(!_curDataArr ||_curDataArr.count ==0){
  142. headView.hidden = YES;
  143. return;
  144. }
  145. headView.hidden = NO;
  146. NSInteger tag = self.tag;
  147. if(tag == 100){
  148. NSString *leftStr = NSLocalizedString(@"File_upload_Record_uploading",nil);
  149. NSString *rightStr = NSLocalizedString(@"File_upload_Record_all_suspend",nil);
  150. NSString *rightSelectStr = NSLocalizedString(@"File_upload_Record_all_open",nil);
  151. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  152. headView.titleLabel.text = titleStr;
  153. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  154. [headView.rightButton setTitle:rightSelectStr forState:UIControlStateSelected];
  155. }
  156. else if(tag == 101){
  157. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  158. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  159. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  160. headView.titleLabel.text = titleStr;
  161. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  162. }
  163. else if(tag == 102){
  164. NSString *leftStr = NSLocalizedString(@"File_upload_Record_did_upload",nil);
  165. NSString *rightStr = NSLocalizedString(@"File_upload_Record_clear_Record",nil);
  166. NSString *titleStr = [[NSString alloc] initWithFormat:@"%@ (%ld)",leftStr,_curDataArr.count];
  167. headView.titleLabel.text = titleStr;
  168. [headView.rightButton setTitle:rightStr forState:UIControlStateNormal];
  169. }
  170. }
  171. #pragma mark 点击全选
  172. - (void)setIsSelectAllType:(BOOL)isSelectAllType
  173. {
  174. _selectModelArr = [NSMutableArray arrayWithArray:_curDataArr];
  175. [self reloadDataFun];
  176. }
  177. -(void)setIsEditType:(BOOL)isEditType
  178. {
  179. _isEditType = isEditType;
  180. if(_isEditType){
  181. //_bgScrollV.scrollEnabled = NO;
  182. }
  183. else{
  184. //_bgScrollV.scrollEnabled = YES;
  185. [_selectModelArr removeAllObjects];
  186. }
  187. [self reloadDataFun];
  188. }
  189. #pragma mark cell长按时间
  190. - (void)didLongPressClickFun{
  191. self.isEditType = YES;
  192. if(self->_didLongPressClick){
  193. self->_didLongPressClick();
  194. }
  195. }
  196. #pragma mark 单个点击选中 取消
  197. - (void)selectModelOneByOne:(uploadFileDataModel*)model BySelect:(BOOL)isSelcet
  198. {
  199. if(isSelcet){
  200. [_selectModelArr addObject:model];
  201. }
  202. else{
  203. [_selectModelArr removeObject:model];
  204. }
  205. }
  206. #pragma mark 单个点击选中后删除
  207. - (void)deleteModelOneByOneFun{
  208. if(!_selectModelArr || _selectModelArr.count==0){
  209. return;
  210. }
  211. KWeakSelf
  212. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:_selectModelArr withDelCache:YES complete:^(BOOL isSuccess) {
  213. HLog(@"isSuccess:%d",isSuccess);
  214. if(isSuccess){
  215. NSMutableArray *curArr = self->_curDataArr;
  216. [curArr removeObjectsInArray:self->_selectModelArr];
  217. [weakSelf reloadDataFun];
  218. self->_selectModelArr = [NSMutableArray new];
  219. }
  220. }];
  221. }
  222. #pragma mark 处理上传中的 状态点击事件
  223. - (void)handleUploadingStateTapFunBy:(BOOL)isSuspendType with:(uploadFileDataModel*)model
  224. {
  225. if (isSuspendType) {
  226. [[uploadFileManager shareInstance] suspendUploadFileFun:NO];
  227. }
  228. else{
  229. NSMutableArray*arr = [NSMutableArray new];
  230. [arr addObject:model];
  231. [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  232. }
  233. }
  234. #pragma mark 处理上传中的 状态点击事件
  235. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  236. [_curDataArr removeObject:model];
  237. [self reloadDataFun];
  238. if(_didClickReUploadBlock){
  239. _didClickReUploadBlock(model);
  240. }
  241. NSMutableArray*arr = [NSMutableArray new];
  242. model.curUploadStateType = uploadStateWait;
  243. [arr addObject:model];
  244. [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  245. }
  246. @end