uploadFileRecordCell.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. //
  2. // uploadFileRecordCell.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/16.
  6. //
  7. #import "uploadFileRecordCell.h"
  8. #import "cachesFileManager.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. @interface uploadFileRecordCell ()
  11. @property(nonatomic,strong) UIImageView *fileImageView;
  12. @property(nonatomic,strong) UIButton *upLoadStateButton;
  13. @property (nonatomic, strong) UIButton *selectButton;
  14. @property(nonatomic,strong) UIView *progressBgView;
  15. @property(nonatomic,strong) UIView *progressSelectView;
  16. @property(nonatomic,strong) CAGradientLayer *glayer;
  17. @property(nonatomic,strong) UILabel *fileNamelabel;
  18. @property(nonatomic,strong) UILabel *fileProgresslabel;
  19. @property(nonatomic,strong) UILabel *fileSpeedlabel;
  20. @end
  21. @implementation uploadFileRecordCell
  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. _fileImageView = [[UIImageView alloc] init];
  34. //_fileImageView.backgroundColor = [UIColor greenColor];
  35. [self.contentView addSubview:_fileImageView];
  36. [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.mas_equalTo(15);
  38. make.width.mas_equalTo(34);
  39. make.height.mas_equalTo(34);
  40. make.bottom.mas_equalTo(-18);
  41. }];
  42. _upLoadStateButton = [[UIButton alloc] init];
  43. //_upLoadStateButton.backgroundColor = [UIColor redColor];
  44. [self.contentView addSubview:_upLoadStateButton];
  45. [_upLoadStateButton addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
  46. [_upLoadStateButton mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.right.mas_equalTo(-5);
  48. make.width.mas_equalTo(50);
  49. make.height.mas_equalTo(50);
  50. make.bottom.mas_equalTo(-18);
  51. }];
  52. if (self.selectButton == nil) {
  53. UIButton *but = [[UIButton alloc] init];
  54. [but setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  55. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  56. [self.contentView addSubview:but];
  57. [but addTarget:self action:@selector(didClickSelectButFun:) forControlEvents:UIControlEventTouchUpInside];
  58. but.hidden = YES;
  59. //but.backgroundColor = [UIColor greenColor];
  60. //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
  61. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.width.mas_equalTo(30);
  63. make.height.mas_equalTo(30);
  64. make.centerX.mas_equalTo(_upLoadStateButton.mas_centerX);
  65. make.centerY.mas_equalTo(_upLoadStateButton.mas_centerY);
  66. }];
  67. self.selectButton = but;
  68. }
  69. _progressBgView = [[UIView alloc] init];
  70. _progressBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  71. _progressBgView.layer.cornerRadius = 1.5;
  72. _progressBgView.layer.masksToBounds = YES;
  73. [self.contentView addSubview:_progressBgView];
  74. [_progressBgView 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(2);
  78. make.centerY.mas_equalTo(0);
  79. }];
  80. _progressSelectView = [[UIView alloc] init];
  81. //_progressSelectView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  82. _progressSelectView.layer.cornerRadius = 1.5;
  83. _progressSelectView.layer.masksToBounds = YES;
  84. [_progressBgView addSubview:_progressSelectView];
  85. // [_progressSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. // make.left.mas_equalTo(0);
  87. // make.right.mas_equalTo(-100);
  88. // make.height.mas_equalTo(3);
  89. // make.centerY.mas_equalTo(0);
  90. // }];
  91. // gradient
  92. _glayer = [CAGradientLayer layer];
  93. _glayer.startPoint = CGPointMake(0, 0.5);
  94. _glayer.endPoint = CGPointMake(1, 0.5);
  95. _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor];
  96. _glayer.locations = @[@(0), @(1.0f)];
  97. [_progressSelectView.layer addSublayer:_glayer];
  98. CGRect frame = CGRectMake(0, 0, SCREEN_W, 2);
  99. //_progressSelectView.frame = frame;
  100. _glayer.frame = frame;
  101. _fileNamelabel = [[UILabel alloc] init];
  102. _fileNamelabel.font = [UIFont boldSystemFontOfSize:16.0];
  103. _fileNamelabel.textColor = [UIColor blackColor];
  104. //_fileNamelabel.backgroundColor = [UIColor greenColor];
  105. [self.contentView addSubview:_fileNamelabel];
  106. [_fileNamelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  108. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  109. make.height.mas_equalTo(19);
  110. make.bottom.mas_equalTo(_progressBgView.mas_top).offset(-3);
  111. }];
  112. _fileProgresslabel = [[UILabel alloc] init];
  113. _fileProgresslabel.font = [UIFont systemFontOfSize:12.0];
  114. _fileProgresslabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  115. //_fileProgresslabel.backgroundColor = [UIColor greenColor];
  116. [self.contentView addSubview:_fileProgresslabel];
  117. [_fileProgresslabel mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  119. make.right.mas_equalTo(_progressBgView.mas_centerX).offset(100);
  120. make.height.mas_equalTo(15);
  121. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  122. }];
  123. _fileSpeedlabel = [[UILabel alloc] init];
  124. _fileSpeedlabel.font = [UIFont systemFontOfSize:12.0];
  125. _fileSpeedlabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  126. _fileSpeedlabel.textAlignment = NSTextAlignmentRight;
  127. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  128. [self.contentView addSubview:_fileSpeedlabel];
  129. [_fileSpeedlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  130. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  131. make.left.mas_equalTo(_progressBgView.mas_centerX);
  132. make.height.mas_equalTo(15);
  133. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  134. }];
  135. //长按手势
  136. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  137. //用几个手指触屏,默认1
  138. longPressGesture.numberOfTouchesRequired = 1;
  139. //设置最短长按时间,单位为秒(默认0.5)
  140. longPressGesture.minimumPressDuration = 1;
  141. //设置手势识别期间所允许的手势可移动范围
  142. longPressGesture.allowableMovement = 10;
  143. [self.contentView addGestureRecognizer:longPressGesture];
  144. }
  145. - (void)setIsEditType:(BOOL)isEditType
  146. {
  147. _isEditType = isEditType;
  148. if(isEditType){
  149. self.selectButton.hidden = NO;
  150. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  151. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  152. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  153. _upLoadStateButton.hidden = YES;
  154. //}
  155. }
  156. else{
  157. self.selectButton.hidden = YES;
  158. if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  159. ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  160. ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  161. _upLoadStateButton.hidden = NO;
  162. }
  163. }
  164. }
  165. - (void)setIsSelectType:(BOOL)isSelectType
  166. {
  167. _isSelectType = isSelectType;
  168. if(isSelectType){
  169. self.selectButton.selected = YES;
  170. }
  171. else{
  172. self.selectButton.selected = NO;
  173. }
  174. }
  175. - (void)setCurUploadFileDataModel:(uploadFileDataModel *)curUploadFileDataModel
  176. {
  177. _curUploadFileDataModel.imageData = nil;
  178. _curUploadFileDataModel = nil;
  179. _fileSpeedlabel.hidden = YES;
  180. _progressBgView.hidden = NO;
  181. _upLoadStateButton.hidden = NO;
  182. _curUploadFileDataModel = curUploadFileDataModel;
  183. //HLog(@"hhhhhhh %@ %ld %ld",curUploadFileDataModel.bg_id,curUploadFileDataModel.curUploadStateType,curUploadFileDataModel.didUploadBytes);
  184. if(curUploadFileDataModel.imageData){
  185. _fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  186. }
  187. else{
  188. if(curUploadFileDataModel.curUploadFileType == uploadFileTypeImage){
  189. NSString*pathStr = [cachesFileManager getFilePathWithName:curUploadFileDataModel.filename type:curUploadFileDataModel.curUploadFileType];
  190. UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
  191. if(image){
  192. _fileImageView.image = image;
  193. }
  194. else
  195. {
  196. _fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  197. }
  198. }
  199. else{
  200. NSString*pathStr = [cachesFileManager getFilePathWithName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];
  201. UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
  202. if(image){
  203. _fileImageView.image = image;
  204. }
  205. else
  206. {
  207. _fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  208. }
  209. }
  210. }
  211. //_fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  212. if(curUploadFileDataModel.curUploadStateType == uploadStateWait){
  213. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
  214. }
  215. else if(curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  216. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  217. _fileSpeedlabel.hidden = NO;
  218. //
  219. _fileSpeedlabel.text = @"";
  220. if(curUploadFileDataModel.preTimeInterval <= 0){
  221. _fileSpeedlabel.text = @"--";
  222. }
  223. else{
  224. NSTimeInterval timers = curUploadFileDataModel.curTimeInterval - curUploadFileDataModel.preTimeInterval;
  225. if(timers > 0){
  226. long speed= 1*1024*1024 / timers;
  227. NSString * speedStr = nil;
  228. NSInteger speed_k = speed / (1024);
  229. if(speed_k < 1024){
  230. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  231. }
  232. else {
  233. speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
  234. }
  235. _fileSpeedlabel.text = speedStr;
  236. }
  237. }
  238. curUploadFileDataModel.preTimeInterval = curUploadFileDataModel.curTimeInterval;
  239. }
  240. else if(curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  241. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  242. }
  243. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  244. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
  245. _progressBgView.hidden = YES;
  246. }
  247. else{
  248. _upLoadStateButton.hidden = YES;
  249. _progressBgView.hidden = YES;
  250. }
  251. _fileNamelabel.text = curUploadFileDataModel.filename;
  252. //进度设置
  253. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  254. NSInteger totalSize = curUploadFileDataModel.totalBytes;
  255. // if(curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  256. // totalSize = [curUploadFileDataModel.videoData length];
  257. // }
  258. CGFloat curProgress = 0.0;
  259. if(totalSize > 1024){
  260. curProgress = curUploadFileDataModel.didUploadBytes/(totalSize*1.0);
  261. }
  262. //HLog(@"hxdhxdddddddd %@ -- %f -- %ld",curUploadFileDataModel.bg_id,curProgress,curUploadFileDataModel.didUploadBytes );
  263. if(curProgress > 1){
  264. curProgress = 1;
  265. }
  266. frame.size.width = frame.size.width * curProgress;
  267. if (!isnan(frame.size.width))
  268. {
  269. _progressSelectView.frame = frame;
  270. }
  271. // HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
  272. // HLog(@"%@",_progressSelectView);
  273. NSString * totalSizeStr = nil;
  274. NSInteger totalSize_k = totalSize / 1024;
  275. if(totalSize_k < 1024){
  276. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  277. }
  278. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  279. totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  280. }
  281. else{
  282. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  283. }
  284. NSString * didUploadStr = nil;
  285. NSInteger didUploadSize_k = curUploadFileDataModel.didUploadBytes / 1024;
  286. if(didUploadSize_k < 1024){
  287. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  288. }
  289. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  290. didUploadStr = [[NSString alloc] initWithFormat:@"%.1fMB",didUploadSize_k/1024.0];
  291. }
  292. else{
  293. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  294. }
  295. if(curUploadFileDataModel.curUploadStateType == uploadStateDone){
  296. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@ %@:%@",totalSizeStr,NSLocalizedString(@"File_upload_to_tip",nil),Const_default_upload_path];
  297. }
  298. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  299. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
  300. }
  301. else{
  302. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  303. }
  304. }
  305. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  306. //state属性是所有手势父类提供的方法,用于记录手势的状态
  307. if(press.state == UIGestureRecognizerStateBegan){
  308. //NSLog(@"长按手势开始响应!");
  309. if(_didLongPressClick){
  310. _didLongPressClick();
  311. }
  312. }else if (press.state == UIGestureRecognizerStateChanged){
  313. //NSLog(@"长按手势状态发生改变!");
  314. }else{
  315. //NSLog(@"长按手势结束!");
  316. }
  317. }
  318. - (void)didClickSelectButFun:(UIButton*)but
  319. {
  320. but.selected = !but.selected;
  321. if(_didClckSelectBut){
  322. _didClckSelectBut(but.selected);
  323. }
  324. }
  325. - (void)tapClick:(UIButton*)but{
  326. if(_didTapPressClick){
  327. _didTapPressClick();
  328. }
  329. if(_curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  330. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  331. }
  332. else if(_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  333. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  334. }
  335. but.userInteractionEnabled = NO;
  336. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  337. but.userInteractionEnabled = YES;
  338. });
  339. }
  340. @end