downLoadPreViewCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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:@"%.1fMB",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:@"%.1fMB",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%@ %@",dateStr,totalSizeStr];
  192. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  193. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  194. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  195. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  196. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  197. // 设置行间距
  198. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  199. [paragraphStyle setLineSpacing:5]; //设置行间距
  200. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  201. titleLabel.attributedText = noteStr;
  202. }
  203. - (void)setCurNASFileAndFolderDataModel:(NASFileAndFolderDataModel *)curNASFileAndFolderDataModel
  204. {
  205. _curNASFileAndFolderDataModel = curNASFileAndFolderDataModel;
  206. checkButton.hidden = NO;
  207. checkButton.selected = curNASFileAndFolderDataModel.isSelectType;
  208. NSString *filePath = _curNASFileAndFolderDataModel.path;
  209. NSString *urlStr = ksharedAppDelegate.NASFileService;
  210. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  211. UIImage *placeholderImage = nil;
  212. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"])
  213. {
  214. placeholderImage = [UIImage imageNamed:@"uploadFile_Video"];
  215. }
  216. else if([curNASFileAndFolderDataModel.type isEqualToString:@"jpg"])
  217. {
  218. placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  219. //iOS格式的图片 代理拿不到缩略图
  220. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  221. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  222. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  223. }
  224. }
  225. else if([curNASFileAndFolderDataModel.type isEqualToString:@"audio"])
  226. {
  227. mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  228. }
  229. else if([curNASFileAndFolderDataModel.type isEqualToString:@"dir"])
  230. {
  231. checkButton.hidden = YES;
  232. mImageView.image = [UIImage imageNamed:@"uploadFile_dir"];
  233. }
  234. else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"])
  235. {
  236. //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc
  237. NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."];
  238. if (nameArr.count >= 2) {
  239. NSString *lastName = nameArr.lastObject;
  240. lastName = [lastName lowercaseString];
  241. if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  242. mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  243. }
  244. else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  245. mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  246. }
  247. else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  248. mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  249. }
  250. else if ([lastName rangeOfString:@"doc"].location != NSNotFound) {
  251. mImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  252. }
  253. else{
  254. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  255. }
  256. }
  257. }
  258. else{
  259. mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  260. }
  261. if([curNASFileAndFolderDataModel.type isEqualToString:@"video"]
  262. ||([curNASFileAndFolderDataModel.type isEqualToString:@"jpg"])){
  263. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  264. [mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  265. // if(image){
  266. // //HLog(@"11图片1:%@",imageURL.absoluteString);
  267. // }
  268. // else{
  269. // //HLog(@"11图片0:%@",imageURL.absoluteString);
  270. //
  271. // }
  272. }];
  273. }
  274. //时间戳转换为日期
  275. // NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curNASFileAndFolderDataModel.time];
  276. // NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  277. NSString *dateStr = curNASFileAndFolderDataModel.time;
  278. NSString * totalSizeStr = nil;
  279. NSInteger totalSize_k = curNASFileAndFolderDataModel.size / 1024;
  280. if(totalSize_k == 0){
  281. totalSize_k = 1;
  282. }
  283. if(totalSize_k < 1024){
  284. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  285. }
  286. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  287. totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  288. }
  289. else{
  290. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  291. }
  292. NSString * leftStr = curNASFileAndFolderDataModel.name;
  293. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr];
  294. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  295. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  296. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  297. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  298. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  299. // 设置行间距
  300. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  301. [paragraphStyle setLineSpacing:5]; //设置行间距
  302. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  303. titleLabel.attributedText = noteStr;
  304. }
  305. @end