downLoadPreViewCell.m 18 KB

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