boxReceiveFileRecordCell.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // boxReceiveFileRecordCell.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/24.
  6. //
  7. #import "boxReceiveFileRecordCell.h"
  8. #import "cachesFileManager.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "downloadThumbnailManager.h"
  11. @interface boxReceiveFileRecordCell ()
  12. @property(nonatomic,strong) UIImageView *fileImageView;
  13. @property(nonatomic,strong) UIButton *upLoadStateButton;
  14. @property (nonatomic, strong) UIButton *selectButton;
  15. @property(nonatomic,strong) UILabel *fileNamelabel;
  16. @property(nonatomic,strong) UILabel *fileStatelabel;
  17. @end
  18. @implementation boxReceiveFileRecordCell
  19. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  20. {
  21. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  22. if (self)
  23. {
  24. [self drawView];
  25. }
  26. return self;
  27. }
  28. - (void)drawView
  29. {
  30. _fileImageView = [[UIImageView alloc] init];
  31. //_fileImageView.backgroundColor = [UIColor greenColor];
  32. [_fileImageView setContentMode:(UIViewContentModeScaleAspectFit)];
  33. [self.contentView addSubview:_fileImageView];
  34. [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(15);
  36. make.width.mas_equalTo(36);
  37. make.height.mas_equalTo(36);
  38. make.bottom.mas_equalTo(-18);
  39. }];
  40. _upLoadStateButton = [[UIButton alloc] init];
  41. //_upLoadStateButton.backgroundColor = [UIColor redColor];
  42. [self.contentView addSubview:_upLoadStateButton];
  43. [_upLoadStateButton addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
  44. [_upLoadStateButton mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.right.mas_equalTo(-5);
  46. make.width.mas_equalTo(50);
  47. make.height.mas_equalTo(50);
  48. make.bottom.mas_equalTo(-18);
  49. }];
  50. if (self.selectButton == nil) {
  51. UIButton *but = [[UIButton alloc] init];
  52. [but setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  53. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  54. [self.contentView addSubview:but];
  55. [but addTarget:self action:@selector(didClickSelectButFun:) forControlEvents:UIControlEventTouchUpInside];
  56. but.hidden = YES;
  57. //but.backgroundColor = [UIColor greenColor];
  58. //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
  59. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.width.mas_equalTo(30);
  61. make.height.mas_equalTo(30);
  62. make.centerX.mas_equalTo(_upLoadStateButton.mas_centerX);
  63. make.centerY.mas_equalTo(_upLoadStateButton.mas_centerY);
  64. }];
  65. self.selectButton = but;
  66. }
  67. _fileNamelabel = [[UILabel alloc] init];
  68. _fileNamelabel.font = [UIFont systemFontOfSize:14.0];
  69. _fileNamelabel.textColor = [UIColor blackColor];
  70. _fileNamelabel.numberOfLines = 0;
  71. _fileNamelabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  72. //_fileNamelabel.backgroundColor = [UIColor greenColor];
  73. [self.contentView addSubview:_fileNamelabel];
  74. [_fileNamelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  76. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  77. make.height.mas_equalTo(35);
  78. make.bottom.equalTo(_fileImageView.mas_centerY).offset(0);
  79. }];
  80. _fileStatelabel = [[UILabel alloc] init];
  81. _fileStatelabel.font = [UIFont systemFontOfSize:12.0];
  82. _fileStatelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  83. _fileStatelabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
  84. //_fileProgresslabel.backgroundColor = [UIColor greenColor];
  85. [self.contentView addSubview:_fileStatelabel];
  86. [_fileStatelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  88. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  89. make.height.mas_equalTo(15);
  90. make.top.mas_equalTo(_fileNamelabel.mas_bottom).offset(0);
  91. }];
  92. //长按手势
  93. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  94. //用几个手指触屏,默认1
  95. longPressGesture.numberOfTouchesRequired = 1;
  96. //设置最短长按时间,单位为秒(默认0.5)
  97. longPressGesture.minimumPressDuration = 1;
  98. //设置手势识别期间所允许的手势可移动范围
  99. longPressGesture.allowableMovement = 10;
  100. [self.contentView addGestureRecognizer:longPressGesture];
  101. }
  102. - (void)setIsEditType:(BOOL)isEditType
  103. {
  104. _isEditType = isEditType;
  105. if(isEditType){
  106. self.selectButton.hidden = NO;
  107. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  108. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  109. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  110. _upLoadStateButton.hidden = YES;
  111. //}
  112. }
  113. else{
  114. self.selectButton.hidden = YES;
  115. // if(_curCouldPhoneFileModel.curDownloadStateType == downloadStateWait
  116. // ||_curCouldPhoneFileModel.curDownloadStateType == downloadStateUploading
  117. // ||_curCouldPhoneFileModel.curDownloadStateType == downloadStateSuspend){
  118. // _upLoadStateButton.hidden = NO;
  119. // }
  120. }
  121. }
  122. - (void)setIsSelectType:(BOOL)isSelectType
  123. {
  124. _isSelectType = isSelectType;
  125. if(isSelectType){
  126. self.selectButton.selected = YES;
  127. }
  128. else{
  129. self.selectButton.selected = NO;
  130. }
  131. }
  132. //@所有人 文件格式需要支持以下内容预览/播放
  133. //1. 图片格式:JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
  134. //2. 音频格式:MP3、WAV、FLAC、AAC、OGG。
  135. //3. 视频格式:MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
  136. - (void)setCurShareFileDataModel:(ShareFileDataModel *)curShareFileDataModel
  137. {
  138. _upLoadStateButton.hidden = NO;
  139. _curShareFileDataModel = curShareFileDataModel;
  140. NSArray *nameArr= [curShareFileDataModel.fileName componentsSeparatedByString:@"."];
  141. //HLog(@"fileName: %@",curShareFileDataModel.fileName);
  142. if (nameArr.count >= 2) {
  143. NSString *lastName = nameArr.lastObject;
  144. lastName = [lastName lowercaseString];
  145. //HLog(@"lastName: %@",lastName);
  146. if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
  147. _fileImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
  148. }
  149. else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
  150. _fileImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
  151. }
  152. else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
  153. _fileImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
  154. }
  155. else if ([lastName rangeOfString:@"doc"].location != NSNotFound
  156. ||[lastName rangeOfString:@"docx"].location != NSNotFound) {
  157. _fileImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
  158. }
  159. else if ([iTools isAudioFilewithName:lastName]) {
  160. _fileImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
  161. }
  162. else if ([iTools isPhotoFilewithName:lastName]) {//JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
  163. //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
  164. NSString *fileUrl = curShareFileDataModel.headUrl;
  165. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  166. UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_image"];
  167. [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  168. if(image){
  169. //HLog(@"11图片1:%@",imageURL.absoluteString);
  170. }
  171. else{
  172. //HLog(@"11图片0:%@",imageURL.absoluteString);
  173. }
  174. }];
  175. }
  176. else if ([iTools isVideoFilewithName:lastName]) {//JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
  177. //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
  178. NSString *fileUrl = curShareFileDataModel.headUrl;
  179. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  180. UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
  181. [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  182. if(image){
  183. //HLog(@"11图片1:%@",imageURL.absoluteString);
  184. }
  185. else{
  186. //HLog(@"11图片0:%@",imageURL.absoluteString);
  187. }
  188. }];
  189. }
  190. else{
  191. _fileImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  192. }
  193. }
  194. _fileNamelabel.text = curShareFileDataModel.fileName;
  195. _fileStatelabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  196. if(curShareFileDataModel.saveboxStateType == saveBoxStateBegin){
  197. _fileStatelabel.text = NSLocalizedString(@"box_receive_file_ing",nil);
  198. }
  199. else if(curShareFileDataModel.saveboxStateType == saveBoxStateDone){
  200. NSString *str1 = NSLocalizedString(@"box_receive_Record_suc",nil);
  201. NSString *str2 = curShareFileDataModel.boxSavePath;
  202. _fileStatelabel.text = [[NSString alloc] initWithFormat:@"%@ %@",str1,str2];
  203. }
  204. else if(curShareFileDataModel.saveboxStateType == saveBoxStateFail){
  205. //_fileStatelabel.text = NSLocalizedString(@"box_receive_Record_fail",nil);
  206. _fileStatelabel.text = NSLocalizedString(@"File_download_error_404",nil);
  207. _fileStatelabel.textColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  208. }
  209. }
  210. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  211. //state属性是所有手势父类提供的方法,用于记录手势的状态
  212. if(press.state == UIGestureRecognizerStateBegan){
  213. //NSLog(@"长按手势开始响应!");
  214. if(_didLongPressClick){
  215. _didLongPressClick();
  216. }
  217. }else if (press.state == UIGestureRecognizerStateChanged){
  218. //NSLog(@"长按手势状态发生改变!");
  219. }else{
  220. //NSLog(@"长按手势结束!");
  221. }
  222. }
  223. - (void)didClickSelectButFun:(UIButton*)but
  224. {
  225. but.selected = !but.selected;
  226. if(_didClckSelectBut){
  227. _didClckSelectBut(but.selected);
  228. }
  229. }
  230. - (void)tapClick:(UIButton*)but{
  231. if(_didTapPressClick){
  232. _didTapPressClick();
  233. }
  234. // if(_curCouldPhoneFileModel.curDownloadStateType == downloadStateUploading){
  235. // [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  236. //
  237. // }
  238. // else if(_curCouldPhoneFileModel.curDownloadStateType == downloadStateSuspend){
  239. //
  240. // [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  241. // }
  242. but.userInteractionEnabled = NO;
  243. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  244. but.userInteractionEnabled = YES;
  245. });
  246. }
  247. @end