backupsFilerecordTableView.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. //
  2. // backupsFilerecordTableView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/4.
  6. //
  7. #import "backupsFilerecordTableView.h"
  8. #import "UIScrollView+EmptyDataSet.h"
  9. #import "backupsFileManager.h"
  10. #import "backupsFileRecordCell.h"
  11. @interface backupsFilerecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
  12. {
  13. UIView* curTableHeadView;
  14. UILabel *titleHeadLabel;
  15. }
  16. @end
  17. @implementation backupsFilerecordTableView
  18. - (id)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self initCommon];
  22. }
  23. return self;
  24. }
  25. - (void)initCommon {
  26. self.delegate = self;
  27. self.dataSource = self;
  28. self.showsVerticalScrollIndicator = NO;
  29. self.showsHorizontalScrollIndicator = NO;
  30. [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  31. [self setSeparatorColor:[UIColor clearColor]];
  32. [self setBackgroundColor:[UIColor clearColor]];
  33. [self setTableFooterView:[UIView new]];
  34. [self setBounces:YES];
  35. if (@available(iOS 15.0, *)) {
  36. self.sectionHeaderTopPadding = 0;
  37. }
  38. self.scrollEnabled = NO;
  39. //空数据引入第三方开源处理
  40. self.emptyDataSetSource = self;
  41. self.emptyDataSetDelegate = self;
  42. }
  43. - (void)setPhotosBackupsIngTaskModel:(photosBackupsTaskModel *)photosBackupsIngTaskModel
  44. {
  45. _photosBackupsIngTaskModel = photosBackupsIngTaskModel;
  46. NSArray *curArr = @[_photosBackupsIngTaskModel];
  47. _curDataArr = curArr;
  48. [self reloadDataFun];
  49. }
  50. - (void)setTableViewHeadTitleFun
  51. {
  52. if(_curDataArr.count == 0){
  53. titleHeadLabel.text = @"";
  54. return;
  55. }
  56. photosBackupsTaskModel *model = _curDataArr.firstObject;
  57. NSString *text = @"";
  58. if(model.curBackupsState == backupsStateUploading
  59. ||model.curBackupsState == backupsStateSuspend){
  60. text = NSLocalizedString(@"File_Transfer_List_head_title_ing",nil);
  61. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.count - model.didBackupsCount - model.failCount];
  62. }
  63. else if(model.curBackupsState == backupsStateFail){
  64. text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil);
  65. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount];
  66. }
  67. else{
  68. text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil);
  69. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount];
  70. }
  71. titleHeadLabel.text = text;
  72. }
  73. - (void)setCurDataArr:(NSArray *)curDataArr
  74. {
  75. _curDataArr = curDataArr;
  76. [self reloadDataFun];
  77. }
  78. #pragma mark - 列表委托
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  80. return 1;//_curDataArr.count;
  81. }
  82. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  83. // if(_curDataArr.count > section){
  84. // NSArray *curArr = _curDataArr[section];
  85. // return curArr.count;
  86. // }
  87. return _curDataArr.count;
  88. }
  89. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  90. NSInteger row = indexPath.row;
  91. //NSInteger section = indexPath.section;
  92. static NSString *identifier = @"backupsFileRecordCell";
  93. backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  94. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  95. if (!cell){
  96. cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  97. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  98. [cell setBackgroundColor:[UIColor clearColor]];
  99. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  100. }
  101. if(row < _curDataArr.count){
  102. photosBackupsTaskModel *model = _curDataArr[row];
  103. cell.curPhotosBackupsTaskModel = model;
  104. KWeakSelf
  105. cell.didLongPressClick = ^{
  106. //[weakSelf didLongPressClickFun];
  107. };
  108. cell.didClckSelectBut = ^(BOOL isSelect) {
  109. //[weakSelf selectModelOneByOne:model BySelect:isSelect];
  110. };
  111. cell.didTapPressClick = ^{
  112. if(model.curBackupsState == backupsStateUploading){
  113. [weakSelf handleBackupsingStateTapFunBy:YES with:model];
  114. }
  115. else if(model.curBackupsState == backupsStateSuspend){
  116. [weakSelf handleBackupsingStateTapFunBy:NO with:model];
  117. }
  118. };
  119. }
  120. return cell;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  123. return 70;
  124. }
  125. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  126. {
  127. UIView* headView = [UIView new];
  128. headView.backgroundColor = [UIColor whiteColor];
  129. titleHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)];
  130. titleHeadLabel.font = [UIFont systemFontOfSize:12.0];
  131. titleHeadLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  132. [headView addSubview:titleHeadLabel];
  133. [self setTableViewHeadTitleFun];
  134. return headView;
  135. }
  136. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  137. {
  138. return 50;
  139. }
  140. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  141. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  142. }
  143. #pragma mark 空数据
  144. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  145. NSString *imageName = @"uploadFile_noData";
  146. if(self.tag == 101){
  147. imageName = @"uploadFile_noData";
  148. }
  149. else if(self.tag == 102){
  150. imageName = @"uploadFile_noData";
  151. }
  152. return [UIImage imageNamed:imageName];
  153. }
  154. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  155. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  156. if(self.tag == 101){
  157. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  158. }
  159. else if(self.tag == 102){
  160. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  161. }
  162. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  163. NSForegroundColorAttributeName: HW999999Color};
  164. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  165. }
  166. //调整图片位置
  167. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  168. return -150;
  169. }
  170. -(void)reloadDataFun{
  171. mainBlock(^{
  172. [self setTableViewHeadTitleFun];
  173. [self reloadData];
  174. });
  175. }
  176. #pragma mark cell长按时间
  177. - (void)didLongPressClickFun{
  178. if(self->_didLongPressClick){
  179. self->_didLongPressClick();
  180. }
  181. }
  182. #pragma mark 处理上传中的 状态点击事件
  183. - (void)handleBackupsingStateTapFunBy:(BOOL)isSuspendType with:(photosBackupsTaskModel*)model
  184. {
  185. if (isSuspendType) {
  186. model.isBackupsSuspendType = backupsSuspendByUser;
  187. model.curBackupsState = backupsStateSuspend;
  188. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  189. }
  190. else{
  191. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:Const_photo_backups_state];
  192. if(!haveOpenBackups){
  193. [[iToast makeText:NSLocalizedString(@"File_Record_backups_set_close_tip",nil)] show];
  194. [self reloadData];
  195. return;
  196. }
  197. //相册权限
  198. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  199. [[iToast makeText:NSLocalizedString(@"File_Record_backups_photo_close_tip",nil)] show];
  200. [self reloadData];
  201. return;
  202. }
  203. [[backupsFileManager shareInstance] reBackupsFileFunBy:model];
  204. }
  205. }
  206. #pragma mark 处理上传中的 状态点击事件
  207. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  208. // [_curDataArr removeObject:model];
  209. // [self reloadDataFun];
  210. //
  211. // if(_didClickReUploadBlock){
  212. // _didClickReUploadBlock(model);
  213. // }
  214. //
  215. // NSMutableArray*arr = [NSMutableArray new];
  216. // model.curUploadStateType = uploadStateWait;
  217. // [arr addObject:model];
  218. // [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  219. }
  220. @end