downLoadPreViewCell.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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] handlToDownloadOneThumbnailWith:_curFileModel];
  121. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]];
  122. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  123. if([curFileModel.fileType isEqualToString:@"video"])
  124. {
  125. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  126. }
  127. checkButton.selected = curFileModel.isSelectType;
  128. NSString *fileName = [_curFileModel getFileNameFun];
  129. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  130. UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr];
  131. if(curImage){
  132. mImageView.image = curImage;
  133. }
  134. //时间戳转换为日期
  135. NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curFileModel.time];
  136. NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  137. NSString * totalSizeStr = nil;
  138. NSInteger totalSize_k = curFileModel.length / 1024;
  139. if(totalSize_k < 1024){
  140. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  141. }
  142. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  143. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  144. }
  145. else{
  146. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  147. }
  148. NSString * leftStr = curFileModel.name;
  149. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr];
  150. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  151. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  152. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  153. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  154. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  155. // 设置行间距
  156. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  157. [paragraphStyle setLineSpacing:5]; //设置行间距
  158. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  159. titleLabel.attributedText = noteStr;
  160. }
  161. - (void)setCurNASFileAudioDataModel:(NASFileAudioDataModel *)curNASFileAudioDataModel
  162. {
  163. _curNASFileAudioDataModel = curNASFileAudioDataModel;
  164. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  165. if([_curNASFileAudioDataModel.type isEqualToString:@"video"])
  166. {
  167. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  168. }
  169. else if([_curNASFileAudioDataModel.type isEqualToString:@"audio"])
  170. {
  171. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  172. }
  173. checkButton.selected = _curNASFileAudioDataModel.isSelectType;
  174. //时间戳转换为日期
  175. NSString *dateStr = _curNASFileAudioDataModel.time;
  176. NSString * totalSizeStr = nil;
  177. NSInteger totalSize_k = _curNASFileAudioDataModel.size / 1024;
  178. if(totalSize_k == 0){
  179. totalSize_k = 1;
  180. }
  181. if(totalSize_k < 1024){
  182. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  183. }
  184. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  185. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  186. }
  187. else{
  188. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  189. }
  190. NSString * leftStr = _curNASFileAudioDataModel.name;
  191. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  192. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  193. if([_curNASFileAudioDataModel.type isEqualToString:@"dir"]){
  194. rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
  195. }
  196. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  197. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  198. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  199. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  200. // 设置行间距
  201. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  202. [paragraphStyle setLineSpacing:5]; //设置行间距
  203. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  204. titleLabel.attributedText = noteStr;
  205. }
  206. - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel
  207. {
  208. _curNASFileAndFolderDataModel = curNASFileAndFolderDataModel;
  209. checkButton.hidden = NO;
  210. checkButton.selected = curNASFileAndFolderDataModel.isSelectType;
  211. NSString *filePath = _curNASFileAndFolderDataModel.path;
  212. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  213. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  214. UIImage *placeholderImage = nil;
  215. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"])
  216. {
  217. placeholderImage = [UIImage imageNamed:@"uploadFile_Video"];
  218. }
  219. else if([curNASFileAndFolderDataModel.type containsString:@"jpg"])
  220. {
  221. placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  222. //iOS格式的图片 代理拿不到缩略图
  223. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  224. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  225. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  226. }
  227. }
  228. else if([curNASFileAndFolderDataModel.type isEqualToString:@"audio"])
  229. {
  230. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  231. }
  232. else if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"])
  233. {
  234. checkButton.hidden = YES;
  235. mImageView.image = [UIImage imageNamed:@"uploadFile_dir"];
  236. }
  237. else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"])
  238. {
  239. //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc
  240. NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."];
  241. if (nameArr.count >= 2) {
  242. NSString *lastName = nameArr.lastObject;
  243. lastName = [lastName lowercaseString];
  244. if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  245. mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  246. }
  247. else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  248. mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  249. }
  250. else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  251. mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  252. }
  253. else if ([lastName rangeOfString:@"doc"].location != NSNotFound) {
  254. mImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  255. }
  256. else{
  257. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  258. }
  259. }
  260. }
  261. else{
  262. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  263. }
  264. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"]
  265. ||([curNASFileAndFolderDataModel.type containsString:@"jpg"])){
  266. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  267. [mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  268. // if(image){
  269. // //HLog(@"11图片1:%@",imageURL.absoluteString);
  270. // }
  271. // else{
  272. // //HLog(@"11图片0:%@",imageURL.absoluteString);
  273. //
  274. // }
  275. }];
  276. }
  277. //时间戳转换为日期
  278. // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curNASFileAndFolderDataModel.time];
  279. // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  280. NSString *dateStr = curNASFileAndFolderDataModel.time;
  281. NSString * totalSizeStr = nil;
  282. NSInteger totalSize_k = curNASFileAndFolderDataModel.size / 1024;
  283. if(totalSize_k == 0){
  284. totalSize_k = 1;
  285. }
  286. if(totalSize_k < 1024){
  287. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  288. }
  289. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  290. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  291. }
  292. else{
  293. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  294. }
  295. NSString * leftStr = curNASFileAndFolderDataModel.name;
  296. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",totalSizeStr,dateStr];
  297. if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"]){
  298. rightStr = [[NSString alloc] initWithFormat:@"\n%@",dateStr];
  299. }
  300. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  301. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  302. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  303. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  304. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  305. // 设置行间距
  306. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  307. [paragraphStyle setLineSpacing:5]; //设置行间距
  308. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  309. titleLabel.attributedText = noteStr;
  310. }
  311. @end