backupsFilerecordTableView.m 8.8 KB

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