backupsFileRecordCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. //
  2. // backupsFileRecordCell.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/4.
  6. //
  7. #import "backupsFileRecordCell.h"
  8. #import "cachesFileManager.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. @interface backupsFileRecordCell ()
  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. @property(nonatomic,strong) UILabel *rightTiplabel;
  21. @end
  22. @implementation backupsFileRecordCell
  23. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  24. {
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self)
  27. {
  28. [self drawView];
  29. }
  30. return self;
  31. }
  32. - (void)drawView
  33. {
  34. _fileImageView = [[UIImageView alloc] init];
  35. //_fileImageView.backgroundColor = [UIColor greenColor];
  36. [self.contentView addSubview:_fileImageView];
  37. [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.left.mas_equalTo(15);
  39. make.width.mas_equalTo(34);
  40. make.height.mas_equalTo(34);
  41. make.bottom.mas_equalTo(-18);
  42. }];
  43. _upLoadStateButton = [[UIButton alloc] init];
  44. //_upLoadStateButton.backgroundColor = [UIColor redColor];
  45. [self.contentView addSubview:_upLoadStateButton];
  46. [_upLoadStateButton addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
  47. [_upLoadStateButton mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.right.mas_equalTo(-5);
  49. make.width.mas_equalTo(50);
  50. make.height.mas_equalTo(50);
  51. make.bottom.mas_equalTo(-18);
  52. }];
  53. if (self.selectButton == nil) {
  54. UIButton *but = [[UIButton alloc] init];
  55. [but setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
  56. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  57. [self.contentView addSubview:but];
  58. [but addTarget:self action:@selector(didClickSelectButFun:) forControlEvents:UIControlEventTouchUpInside];
  59. but.hidden = YES;
  60. //but.backgroundColor = [UIColor greenColor];
  61. //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
  62. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.width.mas_equalTo(30);
  64. make.height.mas_equalTo(30);
  65. make.centerX.mas_equalTo(_upLoadStateButton.mas_centerX);
  66. make.centerY.mas_equalTo(_upLoadStateButton.mas_centerY);
  67. }];
  68. self.selectButton = but;
  69. }
  70. _progressBgView = [[UIView alloc] init];
  71. _progressBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  72. _progressBgView.layer.cornerRadius = 1.5;
  73. _progressBgView.layer.masksToBounds = YES;
  74. [self.contentView addSubview:_progressBgView];
  75. [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  77. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  78. make.height.mas_equalTo(2);
  79. make.centerY.mas_equalTo(0);
  80. }];
  81. _progressSelectView = [[UIView alloc] init];
  82. //_progressSelectView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
  83. _progressSelectView.layer.cornerRadius = 1.5;
  84. _progressSelectView.layer.masksToBounds = YES;
  85. [_progressBgView addSubview:_progressSelectView];
  86. // [_progressSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. // make.left.mas_equalTo(0);
  88. // make.right.mas_equalTo(-100);
  89. // make.height.mas_equalTo(3);
  90. // make.centerY.mas_equalTo(0);
  91. // }];
  92. // gradient
  93. _glayer = [CAGradientLayer layer];
  94. _glayer.startPoint = CGPointMake(0, 0.5);
  95. _glayer.endPoint = CGPointMake(1, 0.5);
  96. _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor];
  97. _glayer.locations = @[@(0), @(1.0f)];
  98. [_progressSelectView.layer addSublayer:_glayer];
  99. CGRect frame = CGRectMake(0, 0, SCREEN_W, 2);
  100. //_progressSelectView.frame = frame;
  101. _glayer.frame = frame;
  102. _fileNamelabel = [[UILabel alloc] init];
  103. _fileNamelabel.font = [UIFont boldSystemFontOfSize:16.0];
  104. _fileNamelabel.textColor = [UIColor blackColor];
  105. //_fileNamelabel.backgroundColor = [UIColor greenColor];
  106. [self.contentView addSubview:_fileNamelabel];
  107. [_fileNamelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  109. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  110. make.height.mas_equalTo(19);
  111. make.bottom.mas_equalTo(_progressBgView.mas_top).offset(-3);
  112. }];
  113. _fileProgresslabel = [[UILabel alloc] init];
  114. _fileProgresslabel.font = [UIFont systemFontOfSize:12.0];
  115. _fileProgresslabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  116. //_fileProgresslabel.backgroundColor = [UIColor greenColor];
  117. [self.contentView addSubview:_fileProgresslabel];
  118. [_fileProgresslabel mas_makeConstraints:^(MASConstraintMaker *make) {
  119. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  120. make.right.mas_equalTo(_progressBgView.mas_centerX).offset(100);
  121. make.height.mas_equalTo(15);
  122. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  123. }];
  124. _fileSpeedlabel = [[UILabel alloc] init];
  125. _fileSpeedlabel.font = [UIFont systemFontOfSize:12.0];
  126. _fileSpeedlabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  127. _fileSpeedlabel.textAlignment = NSTextAlignmentRight;
  128. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  129. [self.contentView addSubview:_fileSpeedlabel];
  130. [_fileSpeedlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  132. make.left.mas_equalTo(_progressBgView.mas_centerX);
  133. make.height.mas_equalTo(15);
  134. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  135. }];
  136. _rightTiplabel = [[UILabel alloc] init];
  137. _rightTiplabel.font = [UIFont systemFontOfSize:12.0];
  138. _rightTiplabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  139. _rightTiplabel.textAlignment = NSTextAlignmentRight;
  140. _rightTiplabel.numberOfLines = 0;
  141. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  142. [self.contentView addSubview:_rightTiplabel];
  143. [_rightTiplabel mas_makeConstraints:^(MASConstraintMaker *make) {
  144. make.right.mas_equalTo(-15.0);
  145. make.left.mas_equalTo(_progressBgView.mas_centerX);
  146. make.height.mas_equalTo(30);
  147. make.centerY.mas_equalTo(0);
  148. }];
  149. //长按手势
  150. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  151. //用几个手指触屏,默认1
  152. longPressGesture.numberOfTouchesRequired = 1;
  153. //设置最短长按时间,单位为秒(默认0.5)
  154. longPressGesture.minimumPressDuration = 1;
  155. //设置手势识别期间所允许的手势可移动范围
  156. longPressGesture.allowableMovement = 10;
  157. [self.contentView addGestureRecognizer:longPressGesture];
  158. }
  159. - (void)setIsEditType:(BOOL)isEditType
  160. {
  161. _isEditType = isEditType;
  162. if(isEditType){
  163. self.selectButton.hidden = NO;
  164. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  165. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  166. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  167. _upLoadStateButton.hidden = YES;
  168. //}
  169. }
  170. else{
  171. self.selectButton.hidden = YES;
  172. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  173. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  174. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  175. _upLoadStateButton.hidden = NO;
  176. //}
  177. }
  178. }
  179. - (void)setIsSelectType:(BOOL)isSelectType
  180. {
  181. _isSelectType = isSelectType;
  182. if(isSelectType){
  183. self.selectButton.selected = YES;
  184. }
  185. else{
  186. self.selectButton.selected = NO;
  187. }
  188. }
  189. - (void)setCurPhotosBackupsTaskModel:(photosBackupsTaskModel *)curPhotosBackupsTaskModel
  190. {
  191. _curPhotosBackupsTaskModel = curPhotosBackupsTaskModel;
  192. //test code
  193. //_curPhotosBackupsTaskModel.curBackupsState = backupsStateUploading;
  194. _fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  195. _fileSpeedlabel.hidden = YES;
  196. _rightTiplabel.hidden = YES;
  197. _progressBgView.hidden = NO;
  198. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateUploading){
  199. _upLoadStateButton.hidden = NO;
  200. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  201. _fileSpeedlabel.hidden = NO;
  202. //
  203. _fileSpeedlabel.text = @"";
  204. if(_curPhotosBackupsTaskModel.preTimeInterval <= 0){
  205. _fileSpeedlabel.text = @"--";
  206. }
  207. else{
  208. NSTimeInterval timers = _curPhotosBackupsTaskModel.curTimeInterval - _curPhotosBackupsTaskModel.preTimeInterval;
  209. if(timers > 0){
  210. long speed= 1*1024*1024 / timers;
  211. NSString * speedStr = nil;
  212. NSInteger speed_k = speed / (1024);
  213. if(speed_k < 1024){
  214. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  215. }
  216. else {
  217. speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
  218. }
  219. _fileSpeedlabel.text = speedStr;
  220. }
  221. }
  222. _curPhotosBackupsTaskModel.preTimeInterval = _curPhotosBackupsTaskModel.curTimeInterval;
  223. }
  224. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateSuspend){
  225. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  226. _fileSpeedlabel.text = _curPhotosBackupsTaskModel.backupsTipMsg;
  227. _fileSpeedlabel.hidden = NO;
  228. _upLoadStateButton.hidden = NO;
  229. }
  230. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateFail){
  231. _upLoadStateButton.hidden = YES;
  232. _progressBgView.hidden = YES;
  233. }
  234. else{
  235. _upLoadStateButton.hidden = YES;
  236. _progressBgView.hidden = YES;
  237. }
  238. _fileNamelabel.text = NSLocalizedString(@"set_Privacy_title_image",nil);
  239. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateDone){
  240. NSString * curTimerStr = _curPhotosBackupsTaskModel.bg_updateTime;
  241. if(!curTimerStr){
  242. curTimerStr = _curPhotosBackupsTaskModel.bg_createTime;
  243. }
  244. if(curTimerStr){
  245. curTimerStr = [curTimerStr substringToIndex:(curTimerStr.length -4)];
  246. }
  247. _fileProgresslabel.text = curTimerStr;
  248. _rightTiplabel.hidden = NO;
  249. _rightTiplabel.text = [[NSString alloc] initWithFormat:@"%@:%ld",NSLocalizedString(@"File_Transfer_List_head_title_done",nil),_curPhotosBackupsTaskModel.didBackupsCount];
  250. }
  251. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateFail){
  252. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%ld/%ld",_curPhotosBackupsTaskModel.didBackupsCount,_curPhotosBackupsTaskModel.count];
  253. //_curPhotosBackupsTaskModel.backupsTipMsg = @"备份失败,备份路径不存在";
  254. _rightTiplabel.hidden = NO;
  255. _rightTiplabel.textColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  256. _rightTiplabel.text = _curPhotosBackupsTaskModel.backupsTipMsg;
  257. }
  258. else{
  259. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%ld/%ld",_curPhotosBackupsTaskModel.didBackupsCount,_curPhotosBackupsTaskModel.count - _curPhotosBackupsTaskModel.failCount];
  260. //进度设置
  261. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  262. CGFloat curProgress = _curPhotosBackupsTaskModel.didBackupsCount/((_curPhotosBackupsTaskModel.count - _curPhotosBackupsTaskModel.failCount)*1.0);
  263. if(curProgress > 1){
  264. curProgress = 1;
  265. }
  266. frame.size.width = frame.size.width * curProgress;
  267. if (isnan(frame.size.width))
  268. {
  269. return;
  270. }
  271. _progressSelectView.frame = frame;
  272. //_glayer.frame = frame;
  273. }
  274. }
  275. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  276. //state属性是所有手势父类提供的方法,用于记录手势的状态
  277. if(press.state == UIGestureRecognizerStateBegan){
  278. //NSLog(@"长按手势开始响应!");
  279. if(_didLongPressClick){
  280. _didLongPressClick();
  281. }
  282. }else if (press.state == UIGestureRecognizerStateChanged){
  283. //NSLog(@"长按手势状态发生改变!");
  284. }else{
  285. //NSLog(@"长按手势结束!");
  286. }
  287. }
  288. - (void)didClickSelectButFun:(UIButton*)but
  289. {
  290. but.selected = !but.selected;
  291. if(_didClckSelectBut){
  292. _didClckSelectBut(but.selected);
  293. }
  294. }
  295. - (void)tapClick:(UIButton*)but{
  296. if(_didTapPressClick){
  297. _didTapPressClick();
  298. }
  299. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateUploading){
  300. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  301. }
  302. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateSuspend){
  303. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  304. }
  305. but.userInteractionEnabled = NO;
  306. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  307. but.userInteractionEnabled = YES;
  308. });
  309. }
  310. @end