backupsFilerecordTableView.m 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.count - model.didBackupsCount - model.failCount];
  63. }
  64. else if(model.curBackupsState == backupsStateFail){
  65. text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil);
  66. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount];
  67. }
  68. else{
  69. text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil);
  70. text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount];
  71. }
  72. titleHeadLabel.text = text;
  73. }
  74. - (void)setCurDataArr:(NSArray *)curDataArr
  75. {
  76. _curDataArr = curDataArr;
  77. [self reloadDataFun];
  78. }
  79. #pragma mark - 列表委托
  80. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  81. return 1;//_curDataArr.count;
  82. }
  83. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  84. // if(_curDataArr.count > section){
  85. // NSArray *curArr = _curDataArr[section];
  86. // return curArr.count;
  87. // }
  88. return _curDataArr.count;
  89. }
  90. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  91. NSInteger row = indexPath.row;
  92. //NSInteger section = indexPath.section;
  93. static NSString *identifier = @"backupsFileRecordCell";
  94. backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  95. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  96. if (!cell){
  97. cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  98. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  99. [cell setBackgroundColor:[UIColor clearColor]];
  100. [cell setAccessoryType:(UITableViewCellAccessoryNone)];
  101. }
  102. if(row < _curDataArr.count){
  103. photosBackupsTaskModel *model = _curDataArr[row];
  104. cell.curPhotosBackupsTaskModel = model;
  105. KWeakSelf
  106. cell.didLongPressClick = ^{
  107. //[weakSelf didLongPressClickFun];
  108. };
  109. cell.didClckSelectBut = ^(BOOL isSelect) {
  110. //[weakSelf selectModelOneByOne:model BySelect:isSelect];
  111. };
  112. cell.didTapPressClick = ^{
  113. if(model.curBackupsState == backupsStateUploading){
  114. [weakSelf handleBackupsingStateTapFunBy:YES with:model];
  115. }
  116. else if(model.curBackupsState == backupsStateSuspend){
  117. [weakSelf handleBackupsingStateTapFunBy:NO with:model];
  118. }
  119. };
  120. }
  121. return cell;
  122. }
  123. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  124. return 70;
  125. }
  126. - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  127. {
  128. UIView* headView = [UIView new];
  129. headView.backgroundColor = [UIColor whiteColor];
  130. titleHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)];
  131. titleHeadLabel.font = [UIFont systemFontOfSize:12.0];
  132. titleHeadLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  133. [headView addSubview:titleHeadLabel];
  134. [self setTableViewHeadTitleFun];
  135. return headView;
  136. }
  137. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  138. {
  139. return 50;
  140. }
  141. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  142. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  143. }
  144. #pragma mark 空数据
  145. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
  146. NSString *imageName = @"uploadFile_noData";
  147. if(self.tag == 101){
  148. imageName = @"uploadFile_noData";
  149. }
  150. else if(self.tag == 102){
  151. imageName = @"uploadFile_noData";
  152. }
  153. return [UIImage imageNamed:imageName];
  154. }
  155. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  156. NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
  157. if(self.tag == 101){
  158. text = NSLocalizedString(@"File_download_Record_no_data",nil);
  159. }
  160. else if(self.tag == 102){
  161. text = NSLocalizedString(@"File_backups_Record_no_data",nil);
  162. }
  163. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
  164. NSForegroundColorAttributeName: HW999999Color};
  165. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  166. }
  167. //调整图片位置
  168. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
  169. return -150;
  170. }
  171. -(void)reloadDataFun{
  172. mainBlock(^{
  173. [self setTableViewHeadTitleFun];
  174. [self reloadData];
  175. });
  176. }
  177. #pragma mark cell长按时间
  178. - (void)didLongPressClickFun{
  179. if(self->_didLongPressClick){
  180. self->_didLongPressClick();
  181. }
  182. }
  183. #pragma mark 处理上传中的 状态点击事件
  184. - (void)handleBackupsingStateTapFunBy:(BOOL)isSuspendType with:(photosBackupsTaskModel*)model
  185. {
  186. if (isSuspendType) {
  187. model.isBackupsSuspendType = backupsSuspendByUser;
  188. model.curBackupsState = backupsStateSuspend;
  189. [[backupsFileManager shareInstance] suspendBackupsFileFun];
  190. }
  191. else{
  192. BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
  193. if(!haveOpenBackups){
  194. [[iToast makeText:NSLocalizedString(@"File_Record_backups_set_close_tip",nil)] show];
  195. [self reloadData];
  196. return;
  197. }
  198. //相册权限
  199. if (![[TZImageManager manager] authorizationStatusAuthorized]){
  200. [[iToast makeText:NSLocalizedString(@"File_Record_backups_photo_close_tip",nil)] show];
  201. [self reloadData];
  202. return;
  203. }
  204. BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_backups_canUse_Cellular)];
  205. if(!isCanUseCellular){//不允许流量备份
  206. //
  207. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
  208. [[iToast makeText:NSLocalizedString(@"backups_cannot_use_WWAN_tip",nil)] show];
  209. [self reloadData];
  210. return;
  211. }
  212. }
  213. [[backupsFileManager shareInstance] reBackupsFileFunBy:model];
  214. }
  215. }
  216. #pragma mark 处理上传中的 状态点击事件
  217. - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
  218. // [_curDataArr removeObject:model];
  219. // [self reloadDataFun];
  220. //
  221. // if(_didClickReUploadBlock){
  222. // _didClickReUploadBlock(model);
  223. // }
  224. //
  225. // NSMutableArray*arr = [NSMutableArray new];
  226. // model.curUploadStateType = uploadStateWait;
  227. // [arr addObject:model];
  228. // [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
  229. }
  230. @end