backupsFileRecordCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.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. _rightTiplabel = [[UILabel alloc] init];
  136. _rightTiplabel.font = [UIFont systemFontOfSize:12.0];
  137. _rightTiplabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  138. _rightTiplabel.textAlignment = NSTextAlignmentRight;
  139. _rightTiplabel.numberOfLines = 0;
  140. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  141. [self.contentView addSubview:_rightTiplabel];
  142. [_rightTiplabel mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.right.mas_equalTo(-15.0);
  144. make.left.mas_equalTo(_progressBgView.mas_centerX);
  145. make.height.mas_equalTo(30);
  146. make.centerY.mas_equalTo(0);
  147. }];
  148. //长按手势
  149. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  150. //用几个手指触屏,默认1
  151. longPressGesture.numberOfTouchesRequired = 1;
  152. //设置最短长按时间,单位为秒(默认0.5)
  153. longPressGesture.minimumPressDuration = 1;
  154. //设置手势识别期间所允许的手势可移动范围
  155. longPressGesture.allowableMovement = 10;
  156. [self.contentView addGestureRecognizer:longPressGesture];
  157. }
  158. - (void)setIsEditType:(BOOL)isEditType
  159. {
  160. _isEditType = isEditType;
  161. if(isEditType){
  162. self.selectButton.hidden = NO;
  163. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  164. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  165. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  166. _upLoadStateButton.hidden = YES;
  167. //}
  168. }
  169. else{
  170. self.selectButton.hidden = YES;
  171. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  172. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  173. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  174. _upLoadStateButton.hidden = NO;
  175. //}
  176. }
  177. }
  178. - (void)setIsSelectType:(BOOL)isSelectType
  179. {
  180. _isSelectType = isSelectType;
  181. if(isSelectType){
  182. self.selectButton.selected = YES;
  183. }
  184. else{
  185. self.selectButton.selected = NO;
  186. }
  187. }
  188. - (void)setCurPhotosBackupsTaskModel:(photosBackupsTaskModel *)curPhotosBackupsTaskModel
  189. {
  190. _curPhotosBackupsTaskModel = curPhotosBackupsTaskModel;
  191. //test code
  192. //_curPhotosBackupsTaskModel.curBackupsState = backupsStateUploading;
  193. _fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  194. _fileSpeedlabel.hidden = YES;
  195. _rightTiplabel.hidden = YES;
  196. _progressBgView.hidden = NO;
  197. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateUploading){
  198. _upLoadStateButton.hidden = NO;
  199. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  200. _fileSpeedlabel.hidden = NO;
  201. //
  202. _fileSpeedlabel.text = @"";
  203. if(_curPhotosBackupsTaskModel.preTimeInterval <= 0){
  204. _fileSpeedlabel.text = @"--";
  205. }
  206. else{
  207. NSTimeInterval timers = _curPhotosBackupsTaskModel.curTimeInterval - _curPhotosBackupsTaskModel.preTimeInterval;
  208. if(timers > 0){
  209. long speed= 1*1024*1024 / timers;
  210. NSString * speedStr = nil;
  211. NSInteger speed_k = speed / (1024);
  212. if(speed_k < 1024){
  213. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  214. }
  215. else {
  216. speedStr = [[NSString alloc] initWithFormat:@"%.1fMB/s",speed_k/1024.0];
  217. }
  218. _fileSpeedlabel.text = speedStr;
  219. }
  220. }
  221. _curPhotosBackupsTaskModel.preTimeInterval = _curPhotosBackupsTaskModel.curTimeInterval;
  222. }
  223. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateSuspend){
  224. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  225. _fileSpeedlabel.text = _curPhotosBackupsTaskModel.backupsTipMsg;
  226. _fileSpeedlabel.hidden = NO;
  227. _upLoadStateButton.hidden = NO;
  228. }
  229. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateFail){
  230. _upLoadStateButton.hidden = YES;
  231. _progressBgView.hidden = YES;
  232. }
  233. else{
  234. _upLoadStateButton.hidden = YES;
  235. _progressBgView.hidden = YES;
  236. }
  237. _fileNamelabel.text = NSLocalizedString(@"set_Privacy_title_image",nil);
  238. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateDone){
  239. NSString * curTimerStr = _curPhotosBackupsTaskModel.bg_updateTime;
  240. if(!curTimerStr){
  241. curTimerStr = _curPhotosBackupsTaskModel.bg_createTime;
  242. }
  243. if(curTimerStr){
  244. curTimerStr = [curTimerStr substringToIndex:(curTimerStr.length -4)];
  245. }
  246. _fileProgresslabel.text = curTimerStr;
  247. _rightTiplabel.hidden = NO;
  248. _rightTiplabel.text = [[NSString alloc] initWithFormat:@"%@:%ld",NSLocalizedString(@"File_Transfer_List_head_title_done",nil),_curPhotosBackupsTaskModel.didBackupsCount];
  249. }
  250. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateFail){
  251. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%ld/%ld",_curPhotosBackupsTaskModel.didBackupsCount,_curPhotosBackupsTaskModel.count];
  252. //_curPhotosBackupsTaskModel.backupsTipMsg = @"备份失败,备份路径不存在";
  253. _rightTiplabel.hidden = NO;
  254. _rightTiplabel.textColor = [UIColor hwColor:@"#DD4E4E" alpha:1.0];
  255. _rightTiplabel.text = _curPhotosBackupsTaskModel.backupsTipMsg;
  256. }
  257. else{
  258. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%ld/%ld",_curPhotosBackupsTaskModel.didBackupsCount,_curPhotosBackupsTaskModel.count - _curPhotosBackupsTaskModel.failCount];
  259. //进度设置
  260. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  261. CGFloat curProgress = _curPhotosBackupsTaskModel.didBackupsCount/((_curPhotosBackupsTaskModel.count - _curPhotosBackupsTaskModel.failCount)*1.0);
  262. if(curProgress > 1){
  263. curProgress = 1;
  264. }
  265. frame.size.width = frame.size.width * curProgress;
  266. if (isnan(frame.size.width))
  267. {
  268. return;
  269. }
  270. _progressSelectView.frame = frame;
  271. //_glayer.frame = frame;
  272. }
  273. }
  274. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  275. //state属性是所有手势父类提供的方法,用于记录手势的状态
  276. if(press.state == UIGestureRecognizerStateBegan){
  277. //NSLog(@"长按手势开始响应!");
  278. if(_didLongPressClick){
  279. _didLongPressClick();
  280. }
  281. }else if (press.state == UIGestureRecognizerStateChanged){
  282. //NSLog(@"长按手势状态发生改变!");
  283. }else{
  284. //NSLog(@"长按手势结束!");
  285. }
  286. }
  287. - (void)didClickSelectButFun:(UIButton*)but
  288. {
  289. but.selected = !but.selected;
  290. if(_didClckSelectBut){
  291. _didClckSelectBut(but.selected);
  292. }
  293. }
  294. - (void)tapClick:(UIButton*)but{
  295. if(_didTapPressClick){
  296. _didTapPressClick();
  297. }
  298. if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateUploading){
  299. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  300. }
  301. else if(_curPhotosBackupsTaskModel.curBackupsState == backupsStateSuspend){
  302. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  303. }
  304. but.userInteractionEnabled = NO;
  305. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  306. but.userInteractionEnabled = YES;
  307. });
  308. }
  309. @end