downLoadPreViewCell.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. @implementation downLoadPreViewCell
  10. @synthesize cellBgView;
  11. @synthesize mImageView;
  12. @synthesize titleLabel;
  13. @synthesize titleLabel2;
  14. @synthesize rightImage;
  15. @synthesize lineView;
  16. @synthesize checkButton;
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. }
  21. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  22. {
  23. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  24. if (self)
  25. {
  26. [self drawView];
  27. }
  28. return self;
  29. }
  30. - (void)drawView
  31. {
  32. cellBgView = [[UIView alloc] init];
  33. [self.contentView addSubview:cellBgView];
  34. cellBgView.backgroundColor = [UIColor whiteColor];
  35. [cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.mas_equalTo(15.f);
  37. make.top.mas_equalTo(0);
  38. make.bottom.mas_equalTo(0);
  39. make.width.mas_equalTo(SCREEN_W - 2*15.f);
  40. }];
  41. /*图片*/
  42. mImageView = [[UIImageView alloc] init];
  43. [mImageView setBackgroundColor:[UIColor clearColor]];
  44. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  45. [cellBgView addSubview:mImageView];
  46. [mImageView setContentMode:(UIViewContentModeScaleAspectFit)];
  47. [mImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.mas_equalTo(15);
  49. make.width.mas_equalTo(36);
  50. make.height.mas_equalTo(36);
  51. make.centerY.equalTo(cellBgView.mas_centerY);
  52. }];
  53. /*右侧箭头*/
  54. rightImage = [[UIImageView alloc] init];
  55. [rightImage setBackgroundColor:[UIColor clearColor]];
  56. [rightImage setImage:[UIImage imageNamed:@"cell_right_access"]];
  57. [cellBgView addSubview:rightImage];
  58. [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.width.mas_equalTo(28);
  60. make.right.mas_equalTo(-15.f);
  61. make.height.mas_equalTo(28);
  62. make.centerY.equalTo(cellBgView.mas_centerY);
  63. }];
  64. checkButton = [[UIButton alloc] init];
  65. [checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  66. [checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  67. [cellBgView addSubview:checkButton];
  68. [checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.right.mas_equalTo(-18.f);
  70. make.centerY.equalTo(cellBgView.mas_centerY);
  71. make.width.mas_equalTo(36.f);
  72. make.height.mas_equalTo(36.f);
  73. }];
  74. [checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  75. /**标题*/
  76. titleLabel = [[UILabel alloc] init];
  77. [cellBgView addSubview:titleLabel];
  78. titleLabel.font = [UIFont boldSystemFontOfSize:14.f];
  79. titleLabel.numberOfLines = 3;
  80. [titleLabel setTextColor:HW0A132BColor];
  81. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(mImageView.mas_right).offset(5.f);
  83. make.right.equalTo(checkButton.mas_left).offset(-5.f);
  84. make.centerY.equalTo(cellBgView.mas_centerY);
  85. //make.top.mas_equalTo(15.f);
  86. }];
  87. /**副标题*/
  88. titleLabel2 = [[UILabel alloc] init];
  89. [cellBgView addSubview:titleLabel2];
  90. titleLabel2.font = [UIFont systemFontOfSize:12.f];
  91. //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
  92. [titleLabel2 setTextColor:HW666666Color];
  93. [titleLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.right.mas_equalTo(-53.f);
  95. make.left.mas_equalTo(titleLabel.mas_left);
  96. //make.centerY.equalTo(cellBgView.mas_centerY);
  97. make.bottom.mas_equalTo(-15);
  98. }];
  99. lineView = [[UIView alloc] init];
  100. [lineView setBackgroundColor:HW979797Color10];
  101. [cellBgView addSubview:lineView];
  102. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.right.mas_equalTo(-15.f);
  104. make.left.mas_equalTo(15.f);
  105. make.bottom.mas_equalTo(0);
  106. make.height.mas_equalTo(1.f);
  107. }];
  108. //titleLabel2.text = @"2023/10/22";
  109. }
  110. - (void)maskSwitchPressed:(UIButton *)maskSwitch{
  111. if(_didClickSwitch){
  112. _didClickSwitch(maskSwitch.selected);
  113. }
  114. }
  115. - (void)setCurFileModel:(couldPhoneFileModel *)curFileModel
  116. {
  117. _curFileModel = curFileModel;
  118. //[[downloadThumbnailManager shareInstance] handlToDownloadOneThumbnailWith:_curFileModel];
  119. [[downloadThumbnailManager shareInstance] handlToDownloadThumbnailInDownTableViewWith:@[_curFileModel]];
  120. mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  121. if([curFileModel.fileType isEqualToString:@"video"])
  122. {
  123. mImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  124. }
  125. checkButton.selected = curFileModel.isSelectType;
  126. NSString *fileName = [_curFileModel getFileNameFun];
  127. NSString*pathStr = [cachesFileManager getFilePathWithName:fileName type:DownLoadThumbnail];
  128. UIImage *curImage = [UIImage imageWithContentsOfFile:pathStr];
  129. if(curImage){
  130. mImageView.image = curImage;
  131. }
  132. //时间戳转换为日期
  133. NSString *timeStr = [[NSString alloc] initWithFormat:@"%ld",curFileModel.time];
  134. NSString *dateStr = [iTools getDateStringWithTimeStr:timeStr];
  135. NSString * totalSizeStr = nil;
  136. NSInteger totalSize_k = curFileModel.length / 1024;
  137. if(totalSize_k < 1024){
  138. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  139. }
  140. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  141. totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  142. }
  143. else{
  144. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  145. }
  146. NSString * leftStr = curFileModel.name;
  147. NSString * rightStr = [[NSString alloc] initWithFormat:@"\n%@ %@",dateStr,totalSizeStr];
  148. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@%@",leftStr,rightStr];
  149. NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:totalStr];
  150. NSRange redRange = NSMakeRange([totalStr rangeOfString:rightStr].location, [totalStr rangeOfString:rightStr].length);
  151. [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor hwColor:@"#666666" alpha:1.0] range:redRange];
  152. [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
  153. // 设置行间距
  154. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  155. [paragraphStyle setLineSpacing:5]; //设置行间距
  156. [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [totalStr length])];
  157. titleLabel.attributedText = noteStr;
  158. }
  159. @end