uploadFileRecordCell.m 23 KB

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