downLoadPreViewCell.m 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  196. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  197. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  198. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  199. // 设置行间距
  200. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  201. [paragraphStyle setLineSpacing:5]; //设置行间距
  202. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  203. titleLabel.attributedText = noteStr;
  204. }
  205. - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel
  206. {
  207. _curNASFileAndFolderDataModel = curNASFileAndFolderDataModel;
  208. checkButton.hidden = NO;
  209. checkButton.selected = curNASFileAndFolderDataModel.isSelectType;
  210. NSString *filePath = _curNASFileAndFolderDataModel.path;
  211. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  212. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  213. UIImage *placeholderImage = nil;
  214. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"])
  215. {
  216. placeholderImage = [UIImage imageNamed:@"uploadFile_Video"];
  217. }
  218. else if([curNASFileAndFolderDataModel.type containsString:@"jpg"])
  219. {
  220. placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  221. //iOS格式的图片 代理拿不到缩略图
  222. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  223. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  224. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  225. }
  226. }
  227. else if([curNASFileAndFolderDataModel.type isEqualToString:@"audio"])
  228. {
  229. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  230. }
  231. else if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"])
  232. {
  233. checkButton.hidden = YES;
  234. mImageView.image = [UIImage imageNamed:@"uploadFile_dir"];
  235. }
  236. else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"])
  237. {
  238. //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc
  239. NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."];
  240. if (nameArr.count >= 2) {
  241. NSString *lastName = nameArr.lastObject;
  242. lastName = [lastName lowercaseString];
  243. if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  244. mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  245. }
  246. else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  247. mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  248. }
  249. else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  250. mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  251. }
  252. else if ([lastName rangeOfString:@"doc"].location != NSNotFound) {
  253. mImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  254. }
  255. else{
  256. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  257. }
  258. }
  259. }
  260. else{
  261. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  262. }
  263. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"]
  264. ||([curNASFileAndFolderDataModel.type containsString:@"jpg"])){
  265. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  266. [mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  267. // if(image){
  268. // //HLog(@"11图片1:%@",imageURL.absoluteString);
  269. // }
  270. // else{
  271. // //HLog(@"11图片0:%@",imageURL.absoluteString);
  272. //
  273. // }
  274. }];
  275. }
  276. //时间戳转换为日期
  277. // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curNASFileAndFolderDataModel.time];
  278. // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  279. NSString *dateStr = curNASFileAndFolderDataModel.time;
  280. NSString * totalSizeStr = nil;
  281. NSInteger totalSize_k = curNASFileAndFolderDataModel.size / 1024;
  282. if(totalSize_k == 0){
  283. totalSize_k = 1;
  284. }
  285. if(totalSize_k < 1024){
  286. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  287. }
  288. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  289. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  290. }
  291. else{
  292. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  293. }
  294. NSString * leftStr = curNASFileAndFolderDataModel.name;
  295. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  296. if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"]){
  297. rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
  298. }
  299. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  300. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  301. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  302. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  303. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  304. // 设置行间距
  305. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  306. [paragraphStyle setLineSpacing:5]; //设置行间距
  307. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  308. titleLabel.attributedText = noteStr;
  309. }
  310. - (void)setCurGetInstalledAppMod:(getInstalledAppModel *)curGetInstalledAppMod
  311. {
  312. _curGetInstalledAppMod = curGetInstalledAppMod;
  313. checkButton.hidden = NO;
  314. checkButton.selected = curGetInstalledAppMod.isSelectType;
  315. NSString *filePath = curGetInstalledAppMod.path;
  316. UIImage *image = nil;
  317. if(curGetInstalledAppMod.icon){
  318. // 将 Base64 字符串转换为 NSData
  319. NSData *imageData = [[NSData alloc] initWithBase64EncodedString:curGetInstalledAppMod.icon options:NSDataBase64DecodingIgnoreUnknownCharacters];
  320. // 将 NSData 转换为 UIImage
  321. image = [UIImage imageWithData:imageData];
  322. }
  323. if(image){
  324. mImageView.image = image;
  325. }
  326. else{
  327. mImageView.image = [UIImage imageNamed:@"uploadFile_app"];
  328. }
  329. //时间戳转换为日期
  330. NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curGetInstalledAppMod.time];
  331. NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  332. NSString * totalSizeStr = nil;
  333. NSInteger totalSize_k = curGetInstalledAppMod.length / 1024;
  334. if(totalSize_k == 0){
  335. totalSize_k = 1;
  336. }
  337. if(totalSize_k < 1024){
  338. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  339. }
  340. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  341. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  342. }
  343. else{
  344. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  345. }
  346. NSString * leftStr = curGetInstalledAppMod.name;
  347. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  348. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  349. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  350. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  351. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  352. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  353. // 设置行间距
  354. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  355. [paragraphStyle setLineSpacing:5]; //设置行间距
  356. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  357. titleLabel.attributedText = noteStr;
  358. }
  359. @end