123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- //
- // backupsFilerecordTableView.m
- // 隐私保护
- //
- // Created by xd h on 2024/1/4.
- //
- #import "backupsFilerecordTableView.h"
- #import "UIScrollView+EmptyDataSet.h"
- //#import "backupsFileManager.h"
- #import "nasBackupsManager.h"
- #import "backupsFileRecordCell.h"
- #import "AFNetworkReachabilityManager.h"
- @interface backupsFilerecordTableView()<UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- {
- UIView* curTableHeadView;
- UILabel *titleHeadLabel;
- }
- @end
- @implementation backupsFilerecordTableView
- - (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initCommon];
-
- }
- return self;
- }
- - (void)initCommon {
- self.delegate = self;
- self.dataSource = self;
- self.showsVerticalScrollIndicator = NO;
- self.showsHorizontalScrollIndicator = NO;
- [self setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
- [self setSeparatorColor:[UIColor clearColor]];
- [self setBackgroundColor:[UIColor clearColor]];
- [self setTableFooterView:[UIView new]];
- [self setBounces:YES];
- if (@available(iOS 15.0, *)) {
- self.sectionHeaderTopPadding = 0;
- }
-
- self.scrollEnabled = NO;
-
- //空数据引入第三方开源处理
- self.emptyDataSetSource = self;
- self.emptyDataSetDelegate = self;
- }
- - (void)setPhotosBackupsIngTaskModel:(photosBackupsTaskModel *)photosBackupsIngTaskModel
- {
- _photosBackupsIngTaskModel = photosBackupsIngTaskModel;
- NSArray *curArr = @[_photosBackupsIngTaskModel];
- _curDataArr = curArr;
- [self reloadDataFun];
- }
- - (void)setTableViewHeadTitleFun
- {
- if(_curDataArr.count == 0){
- titleHeadLabel.text = @"";
- return;
- }
-
- photosBackupsTaskModel *model = _curDataArr.firstObject;
-
- NSString *text = @"";
- if(model.curBackupsState == backupsStateUploading
- ||model.curBackupsState == backupsStateSuspend){
- text = NSLocalizedString(@"File_Transfer_List_head_title_ing",nil);
- NSInteger num = model.count - model.didBackupsCount - model.failCount;
- if(num < 0){
- num = 0;
- }
- text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,num];
- }
- else if(model.curBackupsState == backupsStateFail){
- text = NSLocalizedString(@"File_Transfer_List_head_title_fail",nil);
- text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount];
- }
- else{
- text = NSLocalizedString(@"File_Transfer_List_head_title_done",nil);
- text = [[NSString alloc] initWithFormat:@"%@(%ld)",text,model.didBackupsCount + model.PreDidBackupsCount];
- }
- titleHeadLabel.text = text;
- }
- - (void)setCurDataArr:(NSArray *)curDataArr
- {
- _curDataArr = curDataArr;
- [self reloadDataFun];
- }
- #pragma mark - 列表委托
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;//_curDataArr.count;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
-
- // if(_curDataArr.count > section){
- // NSArray *curArr = _curDataArr[section];
- // return curArr.count;
- // }
-
- return _curDataArr.count;
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- NSInteger row = indexPath.row;
- //NSInteger section = indexPath.section;
- static NSString *identifier = @"backupsFileRecordCell";
-
- backupsFileRecordCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- if (!cell){
- cell = [[backupsFileRecordCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
- [cell setBackgroundColor:[UIColor clearColor]];
- [cell setAccessoryType:(UITableViewCellAccessoryNone)];
- }
-
- if(row < _curDataArr.count){
- photosBackupsTaskModel *model = _curDataArr[row];
- cell.curPhotosBackupsTaskModel = model;
-
- KWeakSelf
- cell.didLongPressClick = ^{
- //[weakSelf didLongPressClickFun];
- };
- cell.didClckSelectBut = ^(BOOL isSelect) {
- //[weakSelf selectModelOneByOne:model BySelect:isSelect];
- };
- cell.didTapPressClick = ^{
- if(model.curBackupsState == backupsStateUploading){
- [weakSelf handleBackupsingStateTapFunBy:YES with:model];
- }
- else if(model.curBackupsState == backupsStateSuspend){
- [weakSelf handleBackupsingStateTapFunBy:NO with:model];
- }
-
- };
- }
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 70;
- }
- - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIView* headView = [UIView new];
- headView.backgroundColor = [UIColor whiteColor];
- titleHeadLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_W -15, 50)];
- titleHeadLabel.font = [UIFont systemFontOfSize:12.0];
- titleHeadLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
- [headView addSubview:titleHeadLabel];
-
- [self setTableViewHeadTitleFun];
-
- return headView;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 50;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- }
- #pragma mark 空数据
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
-
- NSString *imageName = @"uploadFile_noData";
-
- if(self.tag == 101){
- imageName = @"uploadFile_noData";
- }
- else if(self.tag == 102){
- imageName = @"uploadFile_noData";
- }
-
- return [UIImage imageNamed:imageName];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
- NSString *text = NSLocalizedString(@"File_upload_Record_no_data",nil);
-
- if(self.tag == 101){
- text = NSLocalizedString(@"File_download_Record_no_data",nil);
- }
- else if(self.tag == 102){
- text = NSLocalizedString(@"File_backups_Record_no_data",nil);
- }
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:16.0f],
- NSForegroundColorAttributeName: HW999999Color};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- //调整图片位置
- - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
- return -150;
- }
- -(void)reloadDataFun{
- mainBlock(^{
- [self setTableViewHeadTitleFun];
- [self reloadData];
- });
- }
- #pragma mark cell长按时间
- - (void)didLongPressClickFun{
- if(self->_didLongPressClick){
- self->_didLongPressClick();
- }
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleBackupsingStateTapFunBy:(BOOL)isSuspendType with:(photosBackupsTaskModel*)model
- {
- if (isSuspendType) {
- model.isBackupsSuspendType = backupsSuspendByUser;
- model.curBackupsState = backupsStateSuspend;
-
- //[[backupsFileManager shareInstance] suspendBackupsFileFun];
- [[nasBackupsManager shareInstance] suspendBackupsFileFun];
- }
- else{
- BOOL haveOpenBackups = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_photo_backups_state)];
- if(!haveOpenBackups){
- [[iToast makeText:NSLocalizedString(@"File_Record_backups_set_close_tip",nil)] show];
- [self reloadData];
- return;
- }
-
- //相册权限
- if (![[TZImageManager manager] authorizationStatusAuthorized]){
- [[iToast makeText:NSLocalizedString(@"File_Record_backups_photo_close_tip",nil)] show];
- [self reloadData];
- return;
- }
-
- BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
- if(!isCanUseCellular){//不允许流量备份
- //
- if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
- [[iToast makeText:NSLocalizedString(@"backups_cannot_use_WWAN_tip",nil)] show];
- [self reloadData];
- return;
- }
-
- }
-
- //[[backupsFileManager shareInstance] reBackupsFileFunBy:model];
- [[nasBackupsManager shareInstance] reBackupsFileFunBy:model];
- }
-
- }
- #pragma mark 处理上传中的 状态点击事件
- - (void)handleUploadFailStateWith:(uploadFileDataModel*)model{
-
- // [_curDataArr removeObject:model];
- // [self reloadDataFun];
- //
- // if(_didClickReUploadBlock){
- // _didClickReUploadBlock(model);
- // }
- //
- // NSMutableArray*arr = [NSMutableArray new];
- // model.curUploadStateType = uploadStateWait;
- // [arr addObject:model];
- // [[uploadFileManager shareInstance] reUploadFileFunBy:arr];
-
- }
- @end
|