uploadFileRecordCell.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. //
  2. // uploadFileRecordCell.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/16.
  6. //
  7. #import "uploadFileRecordCell.h"
  8. @interface uploadFileRecordCell ()
  9. @property(nonatomic,strong) UIImageView *fileImageView;
  10. @property(nonatomic,strong) UIButton *upLoadStateButton;
  11. @property (nonatomic, strong) UIButton *selectButton;
  12. @property(nonatomic,strong) UIView *progressBgView;
  13. @property(nonatomic,strong) UIView *progressSelectView;
  14. @property(nonatomic,strong) CAGradientLayer *glayer;
  15. @property(nonatomic,strong) UILabel *fileNamelabel;
  16. @property(nonatomic,strong) UILabel *fileProgresslabel;
  17. @property(nonatomic,strong) UILabel *fileSpeedlabel;
  18. @end
  19. @implementation uploadFileRecordCell
  20. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  21. {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self)
  24. {
  25. [self drawView];
  26. }
  27. return self;
  28. }
  29. - (void)drawView
  30. {
  31. _fileImageView = [[UIImageView alloc] init];
  32. //_fileImageView.backgroundColor = [UIColor greenColor];
  33. [self.contentView addSubview:_fileImageView];
  34. [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(15);
  36. make.width.mas_equalTo(34);
  37. make.height.mas_equalTo(34);
  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. _progressBgView = [[UIView alloc] init];
  68. _progressBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  69. _progressBgView.layer.cornerRadius = 1.5;
  70. _progressBgView.layer.masksToBounds = YES;
  71. [self.contentView addSubview:_progressBgView];
  72. [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  74. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  75. make.height.mas_equalTo(2);
  76. make.centerY.mas_equalTo(0);
  77. }];
  78. _progressSelectView = [[UIView alloc] init];
  79. //_progressSelectView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  80. _progressSelectView.layer.cornerRadius = 1.5;
  81. _progressSelectView.layer.masksToBounds = YES;
  82. [_progressBgView addSubview:_progressSelectView];
  83. // [_progressSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. // make.left.mas_equalTo(0);
  85. // make.right.mas_equalTo(-100);
  86. // make.height.mas_equalTo(3);
  87. // make.centerY.mas_equalTo(0);
  88. // }];
  89. // gradient
  90. _glayer = [CAGradientLayer layer];
  91. _glayer.startPoint = CGPointMake(0, 0.5);
  92. _glayer.endPoint = CGPointMake(1, 0.5);
  93. _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor];
  94. _glayer.locations = @[@(0), @(1.0f)];
  95. [_progressSelectView.layer addSublayer:_glayer];
  96. CGRect frame = CGRectMake(0, 0, SCREEN_W, 2);
  97. //_progressSelectView.frame = frame;
  98. _glayer.frame = frame;
  99. _fileNamelabel = [[UILabel alloc] init];
  100. _fileNamelabel.font = [UIFont boldSystemFontOfSize:16.0];
  101. //_fileNamelabel.backgroundColor = [UIColor greenColor];
  102. [self.contentView addSubview:_fileNamelabel];
  103. [_fileNamelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  105. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  106. make.height.mas_equalTo(19);
  107. make.bottom.mas_equalTo(_progressBgView.mas_top).offset(-3);
  108. }];
  109. _fileProgresslabel = [[UILabel alloc] init];
  110. _fileProgresslabel.font = [UIFont systemFontOfSize:12.0];
  111. _fileProgresslabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  112. //_fileProgresslabel.backgroundColor = [UIColor greenColor];
  113. [self.contentView addSubview:_fileProgresslabel];
  114. [_fileProgresslabel mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  116. make.right.mas_equalTo(_progressBgView.mas_centerX).offset(100);
  117. make.height.mas_equalTo(15);
  118. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  119. }];
  120. _fileSpeedlabel = [[UILabel alloc] init];
  121. _fileSpeedlabel.font = [UIFont systemFontOfSize:12.0];
  122. _fileSpeedlabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  123. _fileSpeedlabel.textAlignment = NSTextAlignmentRight;
  124. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  125. [self.contentView addSubview:_fileSpeedlabel];
  126. [_fileSpeedlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  128. make.left.mas_equalTo(_progressBgView.mas_centerX);
  129. make.height.mas_equalTo(15);
  130. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  131. }];
  132. //长按手势
  133. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  134. //用几个手指触屏,默认1
  135. longPressGesture.numberOfTouchesRequired = 1;
  136. //设置最短长按时间,单位为秒(默认0.5)
  137. longPressGesture.minimumPressDuration = 1;
  138. //设置手势识别期间所允许的手势可移动范围
  139. longPressGesture.allowableMovement = 10;
  140. [self.contentView addGestureRecognizer:longPressGesture];
  141. }
  142. - (void)setIsEditType:(BOOL)isEditType
  143. {
  144. _isEditType = isEditType;
  145. if(isEditType){
  146. self.selectButton.hidden = NO;
  147. }
  148. else{
  149. self.selectButton.hidden = YES;
  150. }
  151. }
  152. - (void)setIsSelectType:(BOOL)isSelectType
  153. {
  154. _isSelectType = isSelectType;
  155. if(isSelectType){
  156. self.selectButton.selected = YES;
  157. }
  158. else{
  159. self.selectButton.selected = NO;
  160. }
  161. }
  162. - (void)setCurUploadFileDataModel:(uploadFileDataModel *)curUploadFileDataModel
  163. {
  164. _curUploadFileDataModel = curUploadFileDataModel;
  165. //HLog(@"hhhhhhh %@ %ld %ld",curUploadFileDataModel.bg_id,curUploadFileDataModel.curUploadStateType,curUploadFileDataModel.didUploadBytes);
  166. _fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  167. _fileSpeedlabel.hidden = YES;
  168. if(curUploadFileDataModel.curUploadStateType == uploadStateWait){
  169. //_upLoadStateButton.image = [UIImage imageNamed:@"uploadFile_wait"];
  170. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
  171. }
  172. else if(curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  173. //_upLoadStateButton.image = [UIImage imageNamed:@"uploadFile_suspend"];
  174. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  175. _fileSpeedlabel.hidden = NO;
  176. }
  177. else if(curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  178. //_upLoadStateButton.image = [UIImage imageNamed:@"uploadFile_start"];
  179. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  180. }
  181. else{
  182. _upLoadStateButton.hidden = YES;
  183. _progressBgView.hidden = YES;
  184. }
  185. _fileNamelabel.text = curUploadFileDataModel.filename;
  186. //进度设置
  187. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  188. NSInteger totalSize = [curUploadFileDataModel.imageData length];
  189. if(curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  190. totalSize = [curUploadFileDataModel.videoData length];
  191. }
  192. CGFloat curProgress = curUploadFileDataModel.didUploadBytes/(totalSize*1.0);
  193. HLog(@"hxdhxdddddddd %@ -- %f -- %ld",curUploadFileDataModel.bg_id,curProgress,curUploadFileDataModel.didUploadBytes );
  194. if(curProgress > 1){
  195. curProgress = 1;
  196. }
  197. frame.size.width = frame.size.width * curProgress;
  198. _progressSelectView.frame = frame;
  199. //_glayer.frame = frame;
  200. NSString * totalSizeStr = nil;
  201. NSInteger totalSize_k = totalSize / 1024;
  202. if(totalSize_k < 1024){
  203. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  204. }
  205. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  206. totalSizeStr = [[NSString alloc] initWithFormat:@"%.1fMB",totalSize_k/1024.0];
  207. }
  208. else{
  209. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  210. }
  211. NSString * didUploadStr = nil;
  212. NSInteger didUploadSize_k = curUploadFileDataModel.didUploadBytes / 1024;
  213. if(didUploadSize_k < 1024){
  214. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  215. }
  216. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  217. didUploadStr = [[NSString alloc] initWithFormat:@"%.1fMB",didUploadSize_k/1024.0];
  218. }
  219. else{
  220. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  221. }
  222. if(curUploadFileDataModel.curUploadStateType == uploadStateDone){
  223. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalSizeStr,@"上传到:/sdcard/Download/"];
  224. }
  225. else{
  226. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  227. }
  228. _fileSpeedlabel.text = @"--";
  229. }
  230. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  231. //state属性是所有手势父类提供的方法,用于记录手势的状态
  232. if(press.state == UIGestureRecognizerStateBegan){
  233. //NSLog(@"长按手势开始响应!");
  234. if(_didLongPressClick){
  235. _didLongPressClick();
  236. }
  237. }else if (press.state == UIGestureRecognizerStateChanged){
  238. //NSLog(@"长按手势状态发生改变!");
  239. }else{
  240. //NSLog(@"长按手势结束!");
  241. }
  242. }
  243. - (void)didClickSelectButFun:(UIButton*)but
  244. {
  245. but.selected = !but.selected;
  246. if(_didClckSelectBut){
  247. _didClckSelectBut(but.selected);
  248. }
  249. }
  250. - (void)tapClick:(UIButton*)but{
  251. if(_didTapPressClick){
  252. _didTapPressClick();
  253. }
  254. if(_curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  255. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  256. }
  257. else if(_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  258. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  259. }
  260. but.userInteractionEnabled = NO;
  261. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  262. but.userInteractionEnabled = YES;
  263. });
  264. HLog(@"hxdhxdddddddd");
  265. }
  266. @end