downLoadPreViewCell.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. //
  2. // downLoadPreViewCell.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/8.
  6. //
  7. #import "downLoadPreViewCell.h"
  8. #import "downloadThumbnailManager.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. @implementation downLoadPreViewCell
  11. @synthesize cellBgView;
  12. @synthesize mImageView;
  13. @synthesize titleLabel;
  14. @synthesize titleLabel2;
  15. @synthesize rightImage;
  16. @synthesize lineView;
  17. @synthesize checkButton;
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. // Initialization code
  21. }
  22. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  23. {
  24. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  25. if (self)
  26. {
  27. [self drawView];
  28. }
  29. return self;
  30. }
  31. - (void)drawView
  32. {
  33. cellBgView = [[UIView alloc] init];
  34. [self.contentView addSubview:cellBgView];
  35. cellBgView.backgroundColor = [UIColor whiteColor];
  36. [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(15.f);
  38. make.top.mas_equalTo(0);
  39. make.bottom.mas_equalTo(0);
  40. make.width.mas_equalTo(SCREEN_W - 2*15.f);
  41. }];
  42. /*图片*/
  43. mImageView = [[UIImageView alloc] init];
  44. [mImageView setBackgroundColor:[UIColor clearColor]];
  45. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  46. [cellBgView addSubview:mImageView];
  47. [mImageView setContentMode:(UIViewContentModeScaleAspectFit)];
  48. [mImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(15);
  50. make.width.mas_equalTo(36);
  51. make.height.mas_equalTo(36);
  52. make.centerY.equalTo(cellBgView.mas_centerY);
  53. }];
  54. /*右侧箭头*/
  55. rightImage = [[UIImageView alloc] init];
  56. [rightImage setBackgroundColor:[UIColor clearColor]];
  57. [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]];
  58. [cellBgView addSubview:rightImage];
  59. [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.width.mas_equalTo(28);
  61. make.right.mas_equalTo(-15.f);
  62. make.height.mas_equalTo(28);
  63. make.centerY.equalTo(cellBgView.mas_centerY);
  64. }];
  65. checkButton = [[UIButton alloc] init];
  66. [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  67. [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  68. [cellBgView addSubview:checkButton];
  69. [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.right.mas_equalTo(-18.f);
  71. make.centerY.equalTo(cellBgView.mas_centerY);
  72. make.width.mas_equalTo(36.f);
  73. make.height.mas_equalTo(36.f);
  74. }];
  75. [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  76. /**标题*/
  77. titleLabel = [[UILabel alloc] init];
  78. [cellBgView addSubview:titleLabel];
  79. titleLabel.font = [UIFont boldSystemFontOfSize:14.f];
  80. titleLabel.numberOfLines = 3;
  81. [titleLabel setTextColor:HW0A132BColor];
  82. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(mImageView.mas_right).offset(5.f);
  84. make.right.equalTo(checkButton.mas_left).offset(-5.f);
  85. make.centerY.equalTo(cellBgView.mas_centerY);
  86. //make.top.mas_equalTo(15.f);
  87. }];
  88. /**副标题*/
  89. titleLabel2 = [[UILabel alloc] init];
  90. [cellBgView addSubview:titleLabel2];
  91. titleLabel2.font = [UIFont systemFontOfSize:12.f];
  92. //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
  93. [titleLabel2 setTextColor:HW666666Color];
  94. [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.right.mas_equalTo(-53.f);
  96. make.left.mas_equalTo(titleLabel.mas_left);
  97. //make.centerY.equalTo(cellBgView.mas_centerY);
  98. make.bottom.mas_equalTo(-15);
  99. }];
  100. lineView = [[UIView alloc] init];
  101. [lineView setBackgroundColor:HW979797Color10];
  102. [cellBgView addSubview:lineView];
  103. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.right.mas_equalTo(-15.f);
  105. make.left.mas_equalTo(15.f);
  106. make.bottom.mas_equalTo(0);
  107. make.height.mas_equalTo(1.f);
  108. }];
  109. //titleLabel2.text = @"2023/10/22";
  110. }
  111. - (void)maskSwitchPressed:(UIButton *)maskSwitch{
  112. maskSwitch.selected = !maskSwitch.selected;
  113. if(_didClickSwitch){
  114. _didClickSwitch(maskSwitch.selected);
  115. }
  116. }
  117. - (void)setCurFileModel:(couldPhoneFileModel *)curFileModel
  118. {
  119. _curFileModel = curFileModel;
  120. //[[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]];
  121. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  122. if([curFileModel.fileType isEqualToString:@"video"])
  123. {
  124. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  125. }
  126. checkButton.selected = curFileModel.isSelectType;
  127. NSString *fileName = [_curFileModel getFileNameFun];
  128. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  129. UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr];
  130. if(curImage){
  131. mImageView.image = curImage;
  132. }
  133. //时间戳转换为日期
  134. NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curFileModel.time];
  135. NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  136. NSString * totalSizeStr = nil;
  137. NSInteger totalSize_k = curFileModel.length / 1024;
  138. if(totalSize_k < 1024){
  139. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  140. }
  141. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  142. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  143. }
  144. else{
  145. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  146. }
  147. NSString * leftStr = curFileModel.name;
  148. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr];
  149. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  150. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  151. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  152. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  153. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  154. // 设置行间距
  155. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  156. [paragraphStyle setLineSpacing:5]; //设置行间距
  157. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  158. titleLabel.attributedText = noteStr;
  159. }
  160. - (void)setCurNASFileAudioDataModel:(NASFileAudioDataModel *)curNASFileAudioDataModel
  161. {
  162. _curNASFileAudioDataModel = curNASFileAudioDataModel;
  163. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  164. if([_curNASFileAudioDataModel.type isEqualToString:@"video"])
  165. {
  166. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  167. }
  168. else if([_curNASFileAudioDataModel.type isEqualToString:@"audio"])
  169. {
  170. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  171. }
  172. checkButton.selected = _curNASFileAudioDataModel.isSelectType;
  173. //时间戳转换为日期
  174. NSString *dateStr = _curNASFileAudioDataModel.time;
  175. NSString * totalSizeStr = nil;
  176. NSInteger totalSize_k = _curNASFileAudioDataModel.size / 1024;
  177. if(totalSize_k == 0){
  178. totalSize_k = 1;
  179. }
  180. if(totalSize_k < 1024){
  181. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  182. }
  183. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  184. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  185. }
  186. else{
  187. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  188. }
  189. NSString * leftStr = _curNASFileAudioDataModel.name;
  190. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  191. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  192. if([_curNASFileAudioDataModel.type isEqualToString:@"dir"]){
  193. rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
  194. }
  195. //处理音频 无网络 读取缓存的情况
  196. if (_curNASFileAudioDataModel.isOffLineType && !_curNASFileAudioDataModel.isDidCacheType) {
  197. titleLabel.textColor = [UIColor hwColor:@"#666666" alpha:1.0];
  198. }
  199. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  200. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  201. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  202. // 设置行间距
  203. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  204. [paragraphStyle setLineSpacing:5]; //设置行间距
  205. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  206. titleLabel.attributedText = noteStr;
  207. }
  208. - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel
  209. {
  210. _curNASFileAndFolderDataModel = curNASFileAndFolderDataModel;
  211. checkButton.hidden = NO;
  212. checkButton.selected = curNASFileAndFolderDataModel.isSelectType;
  213. NSString *filePath = _curNASFileAndFolderDataModel.path;
  214. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  215. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  216. UIImage *placeholderImage = nil;
  217. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"])
  218. {
  219. placeholderImage = [UIImage imageNamed:@"uploadFile_Video"];
  220. }
  221. else if([curNASFileAndFolderDataModel.type containsString:@"jpg"])
  222. {
  223. placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  224. //iOS格式的图片 代理拿不到缩略图
  225. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  226. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  227. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  228. }
  229. }
  230. else if([curNASFileAndFolderDataModel.type isEqualToString:@"audio"])
  231. {
  232. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  233. }
  234. else if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"])
  235. {
  236. checkButton.hidden = YES;
  237. mImageView.image = [UIImage imageNamed:@"uploadFile_dir"];
  238. }
  239. else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"])
  240. {
  241. //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc
  242. NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."];
  243. if (nameArr.count >= 2) {
  244. NSString *lastName = nameArr.lastObject;
  245. lastName = [lastName lowercaseString];
  246. if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  247. mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  248. }
  249. else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  250. mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  251. }
  252. else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  253. mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  254. }
  255. else if ([lastName rangeOfString:@"doc"].location != NSNotFound) {
  256. mImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  257. }
  258. else{
  259. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  260. }
  261. }
  262. }
  263. else{
  264. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  265. }
  266. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"]
  267. ||([curNASFileAndFolderDataModel.type containsString:@"jpg"])){
  268. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  269. [mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  270. // if(image){
  271. // //HLog(@"11图片1:%@",imageURL.absoluteString);
  272. // }
  273. // else{
  274. // //HLog(@"11图片0:%@",imageURL.absoluteString);
  275. //
  276. // }
  277. }];
  278. }
  279. //时间戳转换为日期
  280. // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curNASFileAndFolderDataModel.time];
  281. // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  282. NSString *dateStr = curNASFileAndFolderDataModel.time;
  283. NSString * totalSizeStr = nil;
  284. NSInteger totalSize_k = curNASFileAndFolderDataModel.size / 1024;
  285. if(totalSize_k == 0){
  286. totalSize_k = 1;
  287. }
  288. if(totalSize_k < 1024){
  289. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  290. }
  291. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  292. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  293. }
  294. else{
  295. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  296. }
  297. NSString * leftStr = curNASFileAndFolderDataModel.name;
  298. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  299. if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"]){
  300. rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
  301. }
  302. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  303. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  304. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  305. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  306. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  307. // 设置行间距
  308. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  309. [paragraphStyle setLineSpacing:5]; //设置行间距
  310. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  311. titleLabel.attributedText = noteStr;
  312. }
  313. - (void)setCurGetInstalledAppMod:(getInstalledAppModel *)curGetInstalledAppMod
  314. {
  315. _curGetInstalledAppMod = curGetInstalledAppMod;
  316. checkButton.hidden = NO;
  317. checkButton.selected = curGetInstalledAppMod.isSelectType;
  318. NSString *filePath = curGetInstalledAppMod.path;
  319. UIImage *image = nil;
  320. if(curGetInstalledAppMod.icon){
  321. // 将 Base64 字符串转换为 NSData
  322. NSData *imageData = [[NSData alloc] initWithBase64EncodedString:curGetInstalledAppMod.icon options:NSDataBase64DecodingIgnoreUnknownCharacters];
  323. // 将 NSData 转换为 UIImage
  324. image = [UIImage imageWithData:imageData];
  325. }
  326. if(image){
  327. mImageView.image = image;
  328. }
  329. else{
  330. mImageView.image = [UIImage imageNamed:@"uploadFile_app"];
  331. }
  332. //时间戳转换为日期
  333. // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curGetInstalledAppMod.time];
  334. // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  335. NSString *dateStr = @"";
  336. if (curGetInstalledAppMod.time.length > 10) {
  337. dateStr = [curGetInstalledAppMod.time substringToIndex:10];
  338. }
  339. NSString * totalSizeStr = nil;
  340. NSInteger totalSize_all = curGetInstalledAppMod.size;
  341. if (totalSize_all == 0) {
  342. totalSize_all = curGetInstalledAppMod.length;
  343. }
  344. NSInteger totalSize_k = totalSize_all / 1024;
  345. if(totalSize_k == 0){
  346. totalSize_k = 1;
  347. }
  348. if(totalSize_k < 1024){
  349. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  350. }
  351. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  352. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  353. }
  354. else{
  355. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  356. }
  357. NSString * leftStr = curGetInstalledAppMod.name;
  358. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  359. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  360. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  361. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  362. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  363. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  364. // 设置行间距
  365. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  366. [paragraphStyle setLineSpacing:5]; //设置行间距
  367. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  368. titleLabel.attributedText = noteStr;
  369. }
  370. @end