uploadFileRecordCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  205. // 直接得到最终的 NSData 数据
  206. if (imageData) {
  207. curUploadFileDataModel.imageData = imageData;
  208. self->_fileImageView.image = [UIImage imageWithData:imageData];
  209. [cachesFileManager getFileNameWithContent:imageData fileName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];
  210. }
  211. else{
  212. self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  213. }
  214. }];
  215. }
  216. }
  217. else{
  218. NSString*pathStr = [cachesFileManager getFilePathWithName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];
  219. UIImage *image = [UIImage imageWithContentsOfFile:pathStr];
  220. if(image){
  221. _fileImageView.image = image;
  222. }
  223. else
  224. {
  225. _fileImageView.image = [UIImage imageNamed:@"uploadFile_Video"];
  226. if(!curUploadFileDataModel.asset){
  227. NSString *curLocalIdentifier = curUploadFileDataModel.localIdentifier;
  228. PHFetchResult *fetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[curLocalIdentifier] options:nil];
  229. PHAsset *asset = fetchResult.firstObject;
  230. curUploadFileDataModel.asset = asset;
  231. }
  232. [[PHImageManager defaultManager] requestImageDataForAsset:curUploadFileDataModel.asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
  233. // 直接得到最终的 NSData 数据
  234. if (imageData) {
  235. curUploadFileDataModel.imageData = imageData;
  236. self->_fileImageView.image = [UIImage imageWithData:imageData];
  237. [cachesFileManager getFileNameWithContent:imageData fileName:curUploadFileDataModel.videoFirstImageName type:uploadFileTypeImage];;
  238. }
  239. else{
  240. self->_fileImageView.image = [UIImage imageNamed:@"uploadFile_image"];
  241. }
  242. }];
  243. }
  244. }
  245. }
  246. //_fileImageView.image = [UIImage imageWithData:curUploadFileDataModel.imageData];
  247. if(curUploadFileDataModel.curUploadStateType == uploadStateWait){
  248. _fileSpeedlabel.text = @"";
  249. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
  250. }
  251. else if(curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  252. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  253. _fileSpeedlabel.hidden = NO;
  254. if(curUploadFileDataModel.preTimeInterval <= 0){
  255. _fileSpeedlabel.text = @"--";
  256. }
  257. else{
  258. long sizeDidUploadData = curUploadFileDataModel.didUploadBytes - curUploadFileDataModel.preDidUploadBytes;
  259. if(curUploadFileDataModel.preDidUploadBytes >0
  260. && sizeDidUploadData >0 ){
  261. NSTimeInterval timers = curUploadFileDataModel.curTimeInterval - curUploadFileDataModel.preTimeInterval;
  262. if(timers > 0){
  263. //long speed= 1*1024*1024 / timers;
  264. //long speed= EachPieceSzie / timers;
  265. long speed= sizeDidUploadData / timers;
  266. NSString * speedStr = nil;
  267. NSInteger speed_k = speed / (1024);
  268. if(speed_k < 1024){
  269. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  270. }
  271. else {
  272. speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
  273. }
  274. _fileSpeedlabel.text = speedStr;
  275. }
  276. }
  277. }
  278. curUploadFileDataModel.preTimeInterval = curUploadFileDataModel.curTimeInterval;
  279. curUploadFileDataModel.preDidUploadBytes = curUploadFileDataModel.didUploadBytes;
  280. }
  281. else if(curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  282. _fileSpeedlabel.text = @"";
  283. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  284. }
  285. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  286. _fileSpeedlabel.text = @"";
  287. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
  288. _progressBgView.hidden = YES;
  289. }
  290. else{
  291. _fileSpeedlabel.text = @"";
  292. _upLoadStateButton.hidden = YES;
  293. _progressBgView.hidden = YES;
  294. }
  295. _fileNamelabel.text = curUploadFileDataModel.filename;
  296. //进度设置
  297. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  298. NSInteger totalSize = curUploadFileDataModel.totalBytes;
  299. // if(curUploadFileDataModel.curUploadFileType == uploadFileTypeVideo){
  300. // totalSize = [curUploadFileDataModel.videoData length];
  301. // }
  302. CGFloat curProgress = 0.0;
  303. if(totalSize > 1024){
  304. curProgress = curUploadFileDataModel.didUploadBytes/(totalSize*1.0);
  305. }
  306. //HLog(@"hxdhxdddddddd %@ -- %f -- %ld",curUploadFileDataModel.bg_id,curProgress,curUploadFileDataModel.didUploadBytes );
  307. if(curProgress > 1){
  308. curProgress = 1;
  309. }
  310. frame.size.width = frame.size.width * curProgress;
  311. if (!isnan(frame.size.width))
  312. {
  313. _progressSelectView.frame = frame;
  314. }
  315. // HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
  316. // HLog(@"%@",_progressSelectView);
  317. NSString * totalSizeStr = nil;
  318. NSInteger totalSize_k = totalSize / 1024;
  319. if(totalSize_k < 1024){
  320. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  321. }
  322. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  323. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  324. }
  325. else{
  326. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  327. }
  328. NSString * didUploadStr = nil;
  329. NSInteger didUploadSize_k = curUploadFileDataModel.didUploadBytes / 1024;
  330. if(didUploadSize_k < 1024){
  331. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  332. }
  333. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  334. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
  335. }
  336. else{
  337. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  338. }
  339. if(curUploadFileDataModel.curUploadStateType == uploadStateDone){
  340. NSString *savePath = curUploadFileDataModel.savePath;
  341. if(!savePath||savePath.length == 0){
  342. savePath = Const_default_upload_path;
  343. }
  344. savePath = [iTools changePathToShowPathBy:savePath];
  345. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@ %@:%@",totalSizeStr,NSLocalizedString(@"File_upload_to_tip",nil),savePath];
  346. }
  347. else if(curUploadFileDataModel.curUploadStateType == uploadStateFail){
  348. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
  349. }
  350. else{
  351. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  352. }
  353. }
  354. -(void)longPressClick:(UILongPressGestureRecognizer *)press{
  355. //state属性是所有手势父类提供的方法,用于记录手势的状态
  356. if(press.state == UIGestureRecognizerStateBegan){
  357. //NSLog(@"长按手势开始响应!");
  358. if(_didLongPressClick){
  359. _didLongPressClick();
  360. }
  361. }else if (press.state == UIGestureRecognizerStateChanged){
  362. //NSLog(@"长按手势状态发生改变!");
  363. }else{
  364. //NSLog(@"长按手势结束!");
  365. }
  366. }
  367. - (void)didClickSelectButFun:(UIButton*)but
  368. {
  369. but.selected = !but.selected;
  370. if(_didClckSelectBut){
  371. _didClckSelectBut(but.selected);
  372. }
  373. }
  374. - (void)tapClick:(UIButton*)but{
  375. if(_didTapPressClick){
  376. _didTapPressClick();
  377. }
  378. if(_curUploadFileDataModel.curUploadStateType == uploadStateUploading){
  379. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
  380. }
  381. else if(_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
  382. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  383. }
  384. but.userInteractionEnabled = NO;
  385. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  386. but.userInteractionEnabled = YES;
  387. });
  388. }
  389. #pragma mark 上传通知
  390. - (void)uploadFileUploadingNotFun:(NSNotification *)not
  391. {
  392. if(_curUploadFileDataModel
  393. && _curUploadFileDataModel.curUploadStateType != uploadStateWait
  394. && _curUploadFileDataModel.curUploadStateType != uploadStateUploading){
  395. return;
  396. }
  397. uploadFileDataModel *model = [not object];
  398. if(!model)return;
  399. if(model.bg_id.integerValue != _curUploadFileDataModel.bg_id.integerValue){
  400. return;
  401. }
  402. if(model.curUploadStateType != uploadStateUploading){
  403. return;
  404. }
  405. if(![model.filename isEqualToString:_curUploadFileDataModel.filename]){
  406. return;
  407. }
  408. model.curTimeInterval = [[NSDate date] timeIntervalSince1970];
  409. KWeakSelf
  410. mainBlock(^{
  411. [weakSelf updateDataUploadingBy:model];
  412. });
  413. }
  414. #pragma mark 更新上传进度
  415. - (void)updateDataUploadingBy:(uploadFileDataModel*)model{
  416. NSString * speedStr = nil;
  417. //进度设置
  418. CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
  419. NSInteger totalSize = model.totalBytes;
  420. if(totalSize == 0.0){
  421. totalSize += 0.0001;
  422. }
  423. CGFloat curProgress = model.didUploadBytes/(totalSize*1.0);
  424. if(curProgress > 1){
  425. curProgress = 1;
  426. }
  427. frame.size.width = frame.size.width * curProgress;
  428. if (isnan(frame.size.width))
  429. {
  430. HLog(@"计算出错了");
  431. frame.size.width = 10.0;
  432. }
  433. _progressSelectView.frame = frame;
  434. //_glayer.frame = frame;
  435. NSString * totalSizeStr = nil;
  436. NSInteger totalSize_k = totalSize / 1024;
  437. if(totalSize_k < 1024){
  438. totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
  439. }
  440. else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
  441. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
  442. }
  443. else{
  444. totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
  445. }
  446. NSString * didUploadStr = nil;
  447. NSInteger didUploadSize_k = model.didUploadBytes / 1024;
  448. if(didUploadSize_k < 1024){
  449. didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
  450. }
  451. else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
  452. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
  453. }
  454. else{
  455. didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
  456. }
  457. _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
  458. if(model.curUploadStateType == uploadStateUploading){
  459. [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
  460. _fileSpeedlabel.hidden = NO;
  461. if(_curUploadFileDataModel.preTimeInterval <= 0
  462. || _curUploadFileDataModel.didUploadBytes == _curUploadFileDataModel.preDidUploadBytes){
  463. //_fileSpeedlabel.text = @"--";
  464. }
  465. else{
  466. NSTimeInterval timers = _curUploadFileDataModel.curTimeInterval - _curUploadFileDataModel.preTimeInterval;
  467. if(timers > 0){
  468. //long speed= 1*1024*1024 / timers;
  469. long speed= (_curUploadFileDataModel.didUploadBytes - _curUploadFileDataModel.preDidUploadBytes) / timers;
  470. NSInteger speed_k = speed / (1024);
  471. if(speed_k < 1024){
  472. speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
  473. }
  474. else {
  475. speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
  476. }
  477. //HLog(@"22211:%@",_fileSpeedlabel.description);
  478. }
  479. }
  480. _curUploadFileDataModel.preTimeInterval = model.curTimeInterval;
  481. _curUploadFileDataModel.preTimeInterval = model.didUploadBytes;
  482. }
  483. if (speedStr) {
  484. self->_fileSpeedlabel.text = speedStr;
  485. }
  486. }
  487. @end