backupsFilerecordTableView.m 9.0 KB

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