lastFileTableViewCell~.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // lastFileTableViewCell.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/7/9.
  6. //
  7. #import "lastFileTableViewCell.h"
  8. #import <SDWebImage/SDWebImage.h>
  9. @implementation lastFileTableViewCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. }
  14. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  15. {
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if (self)
  18. {
  19. [self drawView];
  20. }
  21. return self;
  22. }
  23. - (void)drawView
  24. {
  25. _cellBgView = [[UIView alloc] init];
  26. [self.contentView addSubview:_cellBgView];
  27. _cellBgView.backgroundColor = [UIColor whiteColor];
  28. [_cellBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.left.mas_equalTo(16.f);
  30. make.top.mas_equalTo(0);
  31. make.bottom.mas_equalTo(0);
  32. make.width.mas_equalTo(SCREEN_W - 2*16.f);
  33. }];
  34. /**时间*/
  35. _timeLabel = [[UILabel alloc] init];
  36. [_cellBgView addSubview:_timeLabel];
  37. _timeLabel.font = [UIFont systemFontOfSize:12.f];
  38. //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
  39. [_timeLabel setTextColor:[UIColor hwColor:@"#828D9A"]];
  40. [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.right.mas_equalTo(0.f);
  42. make.left.mas_equalTo(15);
  43. //make.centerY.equalTo(cellBgView.mas_centerY);
  44. make.top.mas_equalTo(0);
  45. make.height.mas_equalTo(20);
  46. }];
  47. /*图片*/
  48. _mImageView = [[UIImageView alloc] init];
  49. [_mImageView setBackgroundColor:[UIColor clearColor]];
  50. _mImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  51. [_cellBgView addSubview:_mImageView];
  52. [_mImageView setContentMode:(UIViewContentModeScaleAspectFit)];
  53. [_mImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.left.mas_equalTo(15);
  55. make.width.mas_equalTo(42);
  56. make.height.mas_equalTo(42);
  57. make.centerY.equalTo(self.mas_centerY);
  58. }];
  59. _checkButton = [[UIButton alloc] init];
  60. [_checkButton setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  61. [_checkButton setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  62. [_cellBgView addSubview:_checkButton];
  63. [_checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.right.mas_equalTo(-15.f);
  65. make.centerY.equalTo(self.mas_centerY);
  66. make.width.mas_equalTo(36.f);
  67. make.height.mas_equalTo(36.f);
  68. }];
  69. [_checkButton addTarget:self action:@selector(maskSwitchPressed:) forControlEvents:(UIControlEventTouchUpInside)];
  70. /**标题*/
  71. _titleLabel = [[UILabel alloc] init];
  72. [_cellBgView addSubview:_titleLabel];
  73. _titleLabel.font = [UIFont boldSystemFontOfSize:14.f];
  74. _titleLabel.numberOfLines = 2;
  75. _titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  76. [_titleLabel setTextColor:HW0A132BColor];
  77. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.equalTo(_mImageView.mas_right).offset(5.f);
  79. make.right.equalTo(_checkButton.mas_left).offset(-5.f);
  80. //make.centerY.equalTo(cellBgView.mas_centerY);
  81. make.top.equalTo(_mImageView.mas_top);
  82. }];
  83. /**副标题*/
  84. _contentLabel = [[UILabel alloc] init];
  85. [_cellBgView addSubview:_contentLabel];
  86. _contentLabel.font = [UIFont systemFontOfSize:12.f];
  87. _contentLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  88. //[titleLabel2 setTextAlignment:(NSTextAlignmentRight)];
  89. [_contentLabel setTextColor:HW666666Color];
  90. [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.mas_equalTo(_titleLabel.mas_right);
  92. make.left.mas_equalTo(_titleLabel.mas_left);
  93. //make.centerY.equalTo(cellBgView.mas_centerY);
  94. make.top.equalTo(_titleLabel.mas_bottom).offset(5.0);
  95. }];
  96. }
  97. - (void)maskSwitchPressed:(UIButton *)maskSwitch{
  98. maskSwitch.selected = !maskSwitch.selected;
  99. if(_didClickSwitch){
  100. _didClickSwitch(maskSwitch.selected);
  101. }
  102. }
  103. - (void)setCurLastFileModel:(lastFileModel *)curLastFileModel
  104. {
  105. _curLastFileModel = curLastFileModel;
  106. _checkButton.selected = _curLastFileModel.isSelectType;
  107. NSString *filePath = _curLastFileModel.path;
  108. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  109. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  110. UIImage *placeholderImage = nil;
  111. if([_curLastFileModel.type isEqualToString:@"video"])
  112. {
  113. placeholderImage = [UIImage imageNamed:@"uploadFile_Video"];
  114. }
  115. else if([_curLastFileModel.type containsString:@"jpg"])
  116. {
  117. placeholderImage = [UIImage imageNamed:@"uploadFile_image"];
  118. //iOS格式的图片 代理拿不到缩略图
  119. if([filePath rangeOfString:@".HEIC"].location != NSNotFound
  120. ||[filePath rangeOfString:@".heic"].location != NSNotFound){
  121. fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  122. }
  123. }
  124. else if([_curLastFileModel.type isEqualToString:@"audio"])
  125. {
  126. _mImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  127. }
  128. else if([_curLastFileModel.type isEqualToString:@"dir"])
  129. {
  130. _checkButton.hidden = YES;
  131. _mImageView.image = [UIImage imageNamed:@"uploadFile_dir"];
  132. }
  133. //else if([curNASFileAndFolderDataModel.type isEqualToString:@"doc"])
  134. // {
  135. // //uploadFile_TXT uploadFile_pdf uploadFile_xlsx uploadFile_doc
  136. // NSArray *nameArr= [curNASFileAndFolderDataModel.name componentsSeparatedByString:@"."];
  137. // if (nameArr.count >= 2) {
  138. // NSString *lastName = nameArr.lastObject;
  139. //
  140. // lastName = [lastName lowercaseString];
  141. //
  142. // if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  143. // mImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  144. // }
  145. // else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  146. // mImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  147. // }
  148. // else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  149. // mImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  150. // }
  151. // else if ([lastName rangeOfString:@"doc"].location != NSNotFound) {
  152. // mImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  153. // }
  154. // else{
  155. // mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  156. // }
  157. // }
  158. //
  159. // }
  160. else{
  161. _mImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  162. }
  163. if([_curLastFileModel.type isEqualToString:@"video"]
  164. ||([_curLastFileModel.type containsString:@"jpg"])){
  165. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  166. [_mImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  167. if(image){
  168. //HLog(@"11图片1:%@",imageURL.absoluteString);
  169. }
  170. else{
  171. //HLog(@"11图片0:%@",imageURL.absoluteString);
  172. }
  173. }];
  174. }
  175. _titleLabel.text = _curLastFileModel.name;
  176. //时间戳转换为日期
  177. NSString *dateStr = [iTools getTimeStringFromTimeInterval:_curLastFileModel.lastPreTime];
  178. //NSString *dateStr = _curLastFileModel.time;
  179. _timeLabel.text = dateStr;
  180. NSString * totalSizeStr = nil;
  181. NSInteger totalSize_k = _curLastFileModel.size / 1024;
  182. if(totalSize_k == 0){
  183. totalSize_k = 1;
  184. }
  185. if(totalSize_k < 1024){
  186. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  187. }
  188. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  189. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  190. }
  191. else{
  192. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  193. }
  194. NSString *path = _curLastFileModel.path;
  195. path = [iTools changePathToShowPathBy:path];
  196. NSString *totalStr = [[NSString alloc] initWithFormat:@"%@ %@",totalSizeStr,path];
  197. _contentLabel.text = totalStr;
  198. }
  199. - (void)hideCheckButtonBy:(BOOL)isHide{
  200. _checkButton.hidden = isHide;
  201. if(isHide){
  202. [_titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  203. make.left.equalTo(_mImageView.mas_right).offset(5.f);
  204. make.right.mas_equalTo(-5.f);
  205. //make.centerY.equalTo(cellBgView.mas_centerY);
  206. make.top.equalTo(_mImageView.mas_top);
  207. }];
  208. /**副标题*/
  209. [_contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  210. make.right.mas_equalTo(_titleLabel.mas_right);
  211. make.left.mas_equalTo(_titleLabel.mas_left);
  212. //make.centerY.equalTo(cellBgView.mas_centerY);
  213. make.top.equalTo(_titleLabel.mas_bottom).offset(5.0);
  214. }];
  215. }
  216. else{
  217. [_cellBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  218. make.left.mas_equalTo(0.f);
  219. make.top.mas_equalTo(0);
  220. make.bottom.mas_equalTo(0);
  221. make.width.mas_equalTo(SCREEN_W);
  222. }];
  223. }
  224. }
  225. @end