123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- //
- // downLoadPreViewCell.m
- // 隐私保护
- //
- // Created by xd h on 2024/1/8.
- //
- #import "downLoadPreViewCell.h"
- #import "downloadThumbnailManager.h"
- #import <SDWebImage/SDWebImage.h>
- @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
|