uploadFileRecordCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadFileUploadingNotFun:) name:uploadFileUploadingNotification object:nil];
  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.adjustsFontSizeToFitWidth = YES;
  119. [_fileProgresslabel mas_makeConstraints:^(MASConstraintMaker *make) {
  120. make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
  121. make.right.mas_equalTo(_progressBgView.mas_right).offset(-10);
  122. make.height.mas_equalTo(15);
  123. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  124. }];
  125. _fileSpeedlabel = [[UILabel alloc] init];
  126. _fileSpeedlabel.font = [UIFont systemFontOfSize:12.0];
  127. _fileSpeedlabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
  128. _fileSpeedlabel.textAlignment = NSTextAlignmentRight;
  129. //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
  130. [self.contentView addSubview:_fileSpeedlabel];
  131. [_fileSpeedlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
  133. make.left.mas_equalTo(_progressBgView.mas_centerX);
  134. make.height.mas_equalTo(15);
  135. make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
  136. }];
  137. //长按手势
  138. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
  139. //用几个手指触屏,默认1
  140. longPressGesture.numberOfTouchesRequired = 1;
  141. //设置最短长按时间,单位为秒(默认0.5)
  142. longPressGesture.minimumPressDuration = 1;
  143. //设置手势识别期间所允许的手势可移动范围
  144. longPressGesture.allowableMovement = 10;
  145. [self.contentView addGestureRecognizer:longPressGesture];
  146. }
  147. - (void)setIsEditType:(BOOL)isEditType
  148. {
  149. _isEditType = isEditType;
  150. if(isEditType){
  151. self.selectButton.hidden = NO;
  152. // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  153. // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  154. // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  155. _upLoadStateButton.hidden = YES;
  156. //}
  157. }
  158. else{
  159. self.selectButton.hidden = YES;
  160. if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
  161. ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
  162. ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  163. _upLoadStateButton.hidden = NO;
  164. }
  165. }
  166. }
  167. - (void)setIsSelectType:(BOOL)isSelectType
  168. {
  169. _isSelectType = isSelectType;
  170. if(isSelectType){
  171. self.selectButton.selected = YES;
  172. }
  173. else{
  174. self.selectButton.selected = NO;
  175. }
  176. }
  177. - (void)setCurUploadFileDataModel:(uploadFileDataModel *)curUploadFileDataModel
  178. {
  179. _curUploadFileDataModel.imageData = nil;
  180. _curUploadFileDataModel = nil;
  181. _fileSpeedlabel.hidden = YES;
  182. _progressBgView.hidden = NO;
  183. _upLoadStateButton.hidden = NO;
  184. _curUploadFileDataModel = curUploadFileDataModel;
  185. //HLog(@"hhhhhhh %@ %ld %ld",curUploadFileDataModel.bg_id,curUploadFileDataModel.curUploadStateType,curUploadFileDataModel.didUploadBytes);
  186. if(curUploadFileDataModel.imageData){
  187. _fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  188. }
  189. else{
  190. if(curUploadFileDataModel.curUploadFileType == uploadFileTypeImage){
  191. NSString*pathStr = [cachesFileManager getFilePathWithName:curUploadFileDataModel.filename type:curUploadFileDataModel.curUploadFileType];
  192. UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
  193. if(image){
  194. _fileImageView.image = image;
  195. }
  196. else
  197. {
  198. if(!curUploadFileDataModel.asset){
  199. NSString *curLocalIdentifier = curUploadFileDataModel.localIdentifier;
  200. PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[curLocalIdentifier] options:nil];
  201. PHAsset *asset = fetchResult.firstObject;
  202. curUploadFileDataModel.asset = asset;
  203. }
  204. if(!curUploadFileDataModel.asset){
  205. self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  206. }
  207. else{
  208. [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  209. // 直接得到最终的 NSData 数据
  210. if (imageData) {
  211. curUploadFileDataModel.imageData = imageData;
  212. self->_fileImageView.image = [UIImage imageWithData:imageData];
  213. [cachesFileManager getFileNameWithContent:imageData fileName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];
  214. }
  215. else{
  216. self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  217. }
  218. }];
  219. }
  220. }
  221. }
  222. else if(curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  223. NSString*pathStr = [cachesFileManager getFilePathWithName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];
  224. UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
  225. if(image){
  226. _fileImageView.image = image;
  227. }
  228. else
  229. {
  230. _fileImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  231. if(!curUploadFileDataModel.asset){
  232. NSString *curLocalIdentifier = curUploadFileDataModel.localIdentifier;
  233. PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[curLocalIdentifier] options:nil];
  234. PHAsset *asset = fetchResult.firstObject;
  235. curUploadFileDataModel.asset = asset;
  236. }
  237. [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  238. // 直接得到最终的 NSData 数据
  239. if (imageData) {
  240. curUploadFileDataModel.imageData = imageData;
  241. self->_fileImageView.image = [UIImage imageWithData:imageData];
  242. [cachesFileManager getFileNameWithContent:imageData fileName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];;
  243. }
  244. else{
  245. self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  246. }
  247. }];
  248. }
  249. }
  250. else{//文件APP
  251. _fileImageView.image = [UIImage imageNamed:@"uploadFile_other"];
  252. }
  253. }
  254. //_fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  255. if(curUploadFileDataModel.curUploadStateType == uploadStateWait){
  256. _fileSpeedlabel.text = @"";
  257. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
  258. }
  259. else if(curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  260. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  261. _fileSpeedlabel.hidden = NO;
  262. if(curUploadFileDataModel.preTimeInterval <= 0){
  263. _fileSpeedlabel.text = @"--";
  264. }
  265. else{
  266. long sizeDidUploadData = curUploadFileDataModel.didUploadBytes - curUploadFileDataModel.preDidUploadBytes;
  267. if(curUploadFileDataModel.preDidUploadBytes >0
  268. && sizeDidUploadData >0 ){
  269. NSTimeInterval timers = curUploadFileDataModel.curTimeInterval - curUploadFileDataModel.preTimeInterval;
  270. if(timers > 0){
  271. //long speed= 1*1024*1024 / timers;
  272. //long speed= EachPieceSzie / timers;
  273. long speed= sizeDidUploadData / timers;
  274. NSString * speedStr = nil;
  275. NSInteger speed_k = speed / (1024);
  276. if(speed_k < 1024){
  277. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  278. }
  279. else {
  280. speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
  281. }
  282. _fileSpeedlabel.text = speedStr;
  283. }
  284. }
  285. }
  286. curUploadFileDataModel.preTimeInterval = curUploadFileDataModel.curTimeInterval;
  287. curUploadFileDataModel.preDidUploadBytes = curUploadFileDataModel.didUploadBytes;
  288. }
  289. else if(curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  290. _fileSpeedlabel.text = @"";
  291. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  292. }
  293. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  294. _fileSpeedlabel.text = @"";
  295. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
  296. _progressBgView.hidden = YES;
  297. }
  298. else{
  299. _fileSpeedlabel.text = @"";
  300. _upLoadStateButton.hidden = YES;
  301. _progressBgView.hidden = YES;
  302. }
  303. _fileNamelabel.text = curUploadFileDataModel.filename;
  304. //进度设置
  305. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  306. NSInteger totalSize = curUploadFileDataModel.totalBytes;
  307. // if(curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  308. // totalSize = [curUploadFileDataModel.videoData length];
  309. // }
  310. CGFloat curProgress = 0.0;
  311. if(totalSize > 1024){
  312. curProgress = curUploadFileDataModel.didUploadBytes/(totalSize*1.0);
  313. }
  314. //HLog(@"hxdhxdddddddd %@ -- %f -- %ld",curUploadFileDataModel.bg_id,curProgress,curUploadFileDataModel.didUploadBytes );
  315. if(curProgress > 1){
  316. curProgress = 1;
  317. }
  318. frame.size.width = frame.size.width * curProgress;
  319. if (!isnan(frame.size.width))
  320. {
  321. _progressSelectView.frame = frame;
  322. }
  323. // HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
  324. // HLog(@"%@",_progressSelectView);
  325. NSString * totalSizeStr = nil;
  326. NSInteger totalSize_k = totalSize / 1024;
  327. if(totalSize_k < 1024){
  328. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  329. }
  330. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  331. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  332. }
  333. else{
  334. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  335. }
  336. NSString * didUploadStr = nil;
  337. NSInteger didUploadSize_k = curUploadFileDataModel.didUploadBytes / 1024;
  338. if(didUploadSize_k < 1024){
  339. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  340. }
  341. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  342. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
  343. }
  344. else{
  345. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  346. }
  347. if(curUploadFileDataModel.curUploadStateType == uploadStateDone){
  348. NSString *savePath = curUploadFileDataModel.savePath;
  349. if(!savePath||savePath.length == 0){
  350. savePath = Const_default_upload_path;
  351. }
  352. savePath = [iTools changePathToShowPathBy:savePath];
  353. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@ %@:%@",totalSizeStr,NSLocalizedString(@"File_upload_to_tip",nil),savePath];
  354. }
  355. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  356. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
  357. }
  358. else{
  359. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  360. }
  361. }
  362. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  363. //state属性是所有手势父类提供的方法,用于记录手势的状态
  364. if(press.state == UIGestureRecognizerStateBegan){
  365. //NSLog(@"长按手势开始响应!");
  366. if(_didLongPressClick){
  367. _didLongPressClick();
  368. }
  369. }else if (press.state == UIGestureRecognizerStateChanged){
  370. //NSLog(@"长按手势状态发生改变!");
  371. }else{
  372. //NSLog(@"长按手势结束!");
  373. }
  374. }
  375. - (void)didClickSelectButFun:(UIButton*)but
  376. {
  377. but.selected = !but.selected;
  378. if(_didClckSelectBut){
  379. _didClckSelectBut(but.selected);
  380. }
  381. }
  382. - (void)tapClick:(UIButton*)but{
  383. if(_didTapPressClick){
  384. _didTapPressClick();
  385. }
  386. if(_curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  387. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  388. }
  389. else if(_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  390. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  391. }
  392. but.userInteractionEnabled = NO;
  393. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  394. but.userInteractionEnabled = YES;
  395. });
  396. }
  397. #pragma mark 上传通知
  398. - (void)uploadFileUploadingNotFun:(NSNotification *)not
  399. {
  400. if(_curUploadFileDataModel
  401. && _curUploadFileDataModel.curUploadStateType != uploadStateWait
  402. && _curUploadFileDataModel.curUploadStateType != uploadStateUploading){
  403. return;
  404. }
  405. uploadFileDataModel *model = [not object];
  406. if(!model)return;
  407. if(model.bg_id.integerValue != _curUploadFileDataModel.bg_id.integerValue){
  408. return;
  409. }
  410. if(model.curUploadStateType != uploadStateUploading){
  411. return;
  412. }
  413. if(![model.filename isEqualToString:_curUploadFileDataModel.filename]){
  414. return;
  415. }
  416. model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
  417. KWeakSelf
  418. mainBlock(^{
  419. [weakSelf updateDataUploadingBy:model];
  420. });
  421. }
  422. #pragma mark 更新上传进度
  423. - (void)updateDataUploadingBy:(uploadFileDataModel*)model{
  424. NSString * speedStr = nil;
  425. //进度设置
  426. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  427. NSInteger totalSize = model.totalBytes;
  428. if(totalSize == 0.0){
  429. totalSize += 0.0001;
  430. }
  431. CGFloat curProgress = model.didUploadBytes/(totalSize*1.0);
  432. if(curProgress > 1){
  433. curProgress = 1;
  434. }
  435. frame.size.width = frame.size.width * curProgress;
  436. if (isnan(frame.size.width))
  437. {
  438. HLog(@"计算出错了");
  439. frame.size.width = 10.0;
  440. }
  441. _progressSelectView.frame = frame;
  442. //_glayer.frame = frame;
  443. NSString * totalSizeStr = nil;
  444. NSInteger totalSize_k = totalSize / 1024;
  445. if(totalSize_k < 1024){
  446. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  447. }
  448. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  449. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  450. }
  451. else{
  452. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  453. }
  454. NSString * didUploadStr = nil;
  455. NSInteger didUploadSize_k = model.didUploadBytes / 1024;
  456. if(didUploadSize_k < 1024){
  457. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  458. }
  459. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  460. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
  461. }
  462. else{
  463. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  464. }
  465. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  466. if(model.curUploadStateType == uploadStateUploading){
  467. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  468. _fileSpeedlabel.hidden = NO;
  469. if(_curUploadFileDataModel.preTimeInterval <= 0
  470. || _curUploadFileDataModel.didUploadBytes == _curUploadFileDataModel.preDidUploadBytes){
  471. //_fileSpeedlabel.text = @"--";
  472. }
  473. else{
  474. NSTimeInterval timers = _curUploadFileDataModel.curTimeInterval - _curUploadFileDataModel.preTimeInterval;
  475. if(timers > 0){
  476. //long speed= 1*1024*1024 / timers;
  477. long speed= (_curUploadFileDataModel.didUploadBytes - _curUploadFileDataModel.preDidUploadBytes) / timers;
  478. if(speed > 0){
  479. NSInteger speed_k = speed / (1024);
  480. if(speed_k < 1024){
  481. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  482. }
  483. else {
  484. speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
  485. }
  486. }
  487. //HLog(@"22211:%@",_fileSpeedlabel.description);
  488. }
  489. }
  490. _curUploadFileDataModel.preTimeInterval = model.curTimeInterval;
  491. _curUploadFileDataModel.preDidUploadBytes = model.didUploadBytes;
  492. }
  493. if (speedStr) {
  494. self->_fileSpeedlabel.text = speedStr;
  495. }
  496. }
  497. @end