// // downLoadPreViewCell.m // 隐私保护 // // Created by xd h on 2024/1/8. // #import "downLoadPreViewCell.h" #import "downloadThumbnailManager.h" #import @implementation downLoadPreViewCell @synthesize cellBgView; @synthesize mImageView; @synthesize titleLabel; @synthesize titleLabel2; @synthesize rightImage; @synthesize lineView; @synthesize checkButton; - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self drawView]; } return self; } - (void)drawView { cellBgView = [[UIView alloc] init]; [self.contentView addSubview:cellBgView]; cellBgView.backgroundColor = [UIColor whiteColor]; [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15.f); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(SCREEN_W - 2*15.f); }]; /*图片*/ mImageView = [[UIImageView alloc] init]; [mImageView setBackgroundColor:[UIColor clearColor]]; mImageView.image = [UIImage imageNamed:@"uploadFile_image"]; [cellBgView addSubview:mImageView]; [mImageView setContentMode:(UIViewContentModeScaleAspectFit)]; [mImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.mas_equalTo(36); make.height.mas_equalTo(36); make.centerY.equalTo(cellBgView.mas_centerY); }]; /*右侧箭头*/ rightImage = [[UIImageView alloc] init]; [rightImage setBackgroundColor:[UIColor clearColor]]; [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]]; [cellBgView addSubview:rightImage]; [rightImage mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(28); make.right.mas_equalTo(-15.f); make.height.mas_equalTo(28); make.centerY.equalTo(cellBgView.mas_centerY); }]; checkButton = [[UIButton alloc] init]; [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal]; [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected]; [cellBgView addSubview:checkButton]; [checkButton mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-18.f); make.centerY.equalTo(cellBgView.mas_centerY); make.width.mas_equalTo(36.f); make.height.mas_equalTo(36.f); }]; [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)]; /**标题*/ titleLabel = [[UILabel alloc] init]; [cellBgView addSubview:titleLabel]; titleLabel.font = [UIFont boldSystemFontOfSize:14.f]; titleLabel.numberOfLines = 3; [titleLabel setTextColor:HW0A132BColor]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(mImageView.mas_right).offset(5.f); make.right.equalTo(checkButton.mas_left).offset(-5.f); make.centerY.equalTo(cellBgView.mas_centerY); //make.top.mas_equalTo(15.f); }]; /**副标题*/ titleLabel2 = [[UILabel alloc] init]; [cellBgView addSubview:titleLabel2]; titleLabel2.font = [UIFont systemFontOfSize:12.f]; //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)]; [titleLabel2 setTextColor:HW666666Color]; [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-53.f); make.left.mas_equalTo(titleLabel.mas_left); //make.centerY.equalTo(cellBgView.mas_centerY); make.bottom.mas_equalTo(-15); }]; lineView = [[UIView alloc] init]; [lineView setBackgroundColor:HW979797Color10]; [cellBgView addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15.f); make.left.mas_equalTo(15.f); make.bottom.mas_equalTo(0); make.height.mas_equalTo(1.f); }]; //titleLabel2.text = @"2023/10/22"; } - (void)maskSwitchPressed:(UIButton *)maskSwitch{ maskSwitch.selected = !maskSwitch.selected; if(_didClickSwitch){ _didClickSwitch(maskSwitch.selected); } } - (void)setCurFileModel:(couldPhoneFileModel *)curFileModel { _curFileModel = curFileModel; //[[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]]; mImageView.image = [UIImage imageNamed:@"uploadFile_image"]; if([curFileModel.fileType isEqualToString:@"video"]) { mImageView.image = [UIImage imageNamed:@"uploadFile_Video"]; } checkButton.selected = curFileModel.isSelectType; NSString *fileName = [_curFileModel getFileNameFun]; NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail]; UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr]; if(curImage){ mImageView.image = curImage; } //时间戳转换为日期 NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curFileModel.time]; NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr]; NSString * totalSizeStr = nil; NSInteger totalSize_k = curFileModel.length / 1024; if(totalSize_k < 1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k]; } else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0]; } else{ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0]; } NSString * leftStr = curFileModel.name; NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr]; NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr]; NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr]; NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length); [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange]; [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange]; // 设置行间距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:5]; //设置行间距 [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])]; titleLabel.attributedText = noteStr; } - (void)setCurNASFileAudioDataModel:(NASFileAudioDataModel *)curNASFileAudioDataModel { _curNASFileAudioDataModel = curNASFileAudioDataModel; mImageView.image = [UIImage imageNamed:@"uploadFile_image"]; if([_curNASFileAudioDataModel.type isEqualToString:@"video"]) { mImageView.image = [UIImage imageNamed:@"uploadFile_Video"]; } else if([_curNASFileAudioDataModel.type isEqualToString:@"audio"]) { mImageView.image = [UIImage imageNamed:@"uploadFile_audio"]; } checkButton.selected = _curNASFileAudioDataModel.isSelectType; //时间戳转换为日期 NSString *dateStr = _curNASFileAudioDataModel.time; NSString * totalSizeStr = nil; NSInteger totalSize_k = _curNASFileAudioDataModel.size / 1024; if(totalSize_k == 0){ totalSize_k = 1; } if(totalSize_k < 1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k]; } else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0]; } else{ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0]; } NSString * leftStr = _curNASFileAudioDataModel.name; NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr]; NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr]; if([_curNASFileAudioDataModel.type isEqualToString:@"dir"]){ rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr]; } NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr]; NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length); [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange]; [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange]; // 设置行间距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:5]; //设置行间距 [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])]; titleLabel.attributedText = noteStr; } - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel { _curNASFileAndFolderDataModel = curNASFileAndFolderDataModel; checkButton.hidden = NO; checkButton.selected = curNASFileAndFolderDataModel.isSelectType; NSString *filePath = _curNASFileAndFolderDataModel.path; NSString *urlStr = ksharedAppDelegate.NASFileByBoxService; NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath]; UIImage *placeholderImage = nil; if([curNASFileAndFolderDataModel.type isEqualToString:@"video"]) { placeholderImage = [UIImage imageNamed:@"uploadFile_Video"]; } else if([curNASFileAndFolderDataModel.type containsString:@"jpg"]) { placeholderImage = [UIImage imageNamed:@"uploadFile_image"]; //iOS格式的图片 代理拿不到缩略图 if([filePath rangeOfString:@".HEIC"].location != NSNotFound ||[filePath rangeOfString:@".heic"].location != NSNotFound){ fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath]; } } else if([curNASFileAndFolderDataModel.type isEqualToString:@"audio"]) { mImageView.image = [UIImage imageNamed:@"uploadFile_audio"]; } else if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"]) { checkButton.hidden = YES; mImageView.image = [UIImage imageNamed:@"uploadFile_dir"]; } else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"]) { //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."]; if (nameArr.count >= 2) { NSString *lastName = nameArr.lastObject; lastName = [lastName lowercaseString]; if ([lastName rangeOfString:@"txt"].location != NSNotFound) { mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"]; } else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) { mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"]; } else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) { mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"]; } else if ([lastName rangeOfString:@"doc"].location != NSNotFound) { mImageView.image = [UIImage imageNamed:@"uploadFile_doc"]; } else{ mImageView.image = [UIImage imageNamed:@"uploadFile_other"]; } } } else{ mImageView.image = [UIImage imageNamed:@"uploadFile_other"]; } if([curNASFileAndFolderDataModel.type isEqualToString:@"video"] ||([curNASFileAndFolderDataModel.type containsString:@"jpg"])){ fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { // if(image){ // //HLog(@"11图片1:%@",imageURL.absoluteString); // } // else{ // //HLog(@"11图片0:%@",imageURL.absoluteString); // // } }]; } //时间戳转换为日期 // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curNASFileAndFolderDataModel.time]; // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr]; NSString *dateStr = curNASFileAndFolderDataModel.time; NSString * totalSizeStr = nil; NSInteger totalSize_k = curNASFileAndFolderDataModel.size / 1024; if(totalSize_k == 0){ totalSize_k = 1; } if(totalSize_k < 1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k]; } else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0]; } else{ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0]; } NSString * leftStr = curNASFileAndFolderDataModel.name; NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr]; if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"]){ rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr]; } NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr]; NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr]; NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length); [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange]; [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange]; // 设置行间距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:5]; //设置行间距 [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])]; titleLabel.attributedText = noteStr; } - (void)setCurGetInstalledAppMod:(getInstalledAppModel *)curGetInstalledAppMod { _curGetInstalledAppMod = curGetInstalledAppMod; checkButton.hidden = NO; checkButton.selected = curGetInstalledAppMod.isSelectType; NSString *filePath = curGetInstalledAppMod.path; UIImage *image = nil; if(curGetInstalledAppMod.icon){ // 将 Base64 字符串转换为 NSData NSData *imageData = [[NSData alloc] initWithBase64EncodedString:curGetInstalledAppMod.icon options:NSDataBase64DecodingIgnoreUnknownCharacters]; // 将 NSData 转换为 UIImage image = [UIImage imageWithData:imageData]; } if(image){ mImageView.image = image; } else{ mImageView.image = [UIImage imageNamed:@"uploadFile_app"]; } //时间戳转换为日期 NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curGetInstalledAppMod.time]; NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr]; NSString * totalSizeStr = nil; NSInteger totalSize_k = curGetInstalledAppMod.length / 1024; if(totalSize_k == 0){ totalSize_k = 1; } if(totalSize_k < 1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k]; } else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0]; } else{ totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0]; } NSString * leftStr = curGetInstalledAppMod.name; NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr]; NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr]; NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr]; NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length); [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange]; [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange]; // 设置行间距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; [paragraphStyle setLineSpacing:5]; //设置行间距 [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])]; titleLabel.attributedText = noteStr; } @end