123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676 |
- //
- // boxDownloadFileRecordCell.m
- // Private-X
- //
- // Created by xd h on 2024/5/25.
- //
- #import "boxDownloadFileRecordCell.h"
- #import "cachesFileManager.h"
- #import <SDWebImage/SDWebImage.h>
- #import "customDownloadManager.h"
- @interface boxDownloadFileRecordCell ()
- @property(nonatomic,strong) UIImageView *fileImageView;
- @property(nonatomic,strong) UIButton *upLoadStateButton;
- @property (nonatomic, strong) UIButton *selectButton;
- @property(nonatomic,strong) UIView *progressBgView;
- @property(nonatomic,strong) UIView *progressSelectView;
- @property(nonatomic,strong) CAGradientLayer *glayer;
- @property(nonatomic,strong) UILabel *fileNamelabel;
- @property(nonatomic,strong) UILabel *fileProgresslabel;
- @property(nonatomic,strong) UILabel *fileSpeedlabel;
- @end
- @implementation boxDownloadFileRecordCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
-
- if (self)
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskDownloadingNoti:) name:customDownloadTaskExeing object:nil];
- [self drawView];
- }
-
- return self;
- }
- - (void)drawView
- {
- _fileImageView = [[UIImageView alloc] init];
- //_fileImageView.backgroundColor = [UIColor greenColor];
- [_fileImageView setContentMode:(UIViewContentModeScaleAspectFit)];
- [self.contentView addSubview:_fileImageView];
-
- [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(15);
- make.width.mas_equalTo(34);
- make.height.mas_equalTo(34);
- make.bottom.mas_equalTo(-18);
- }];
-
- _upLoadStateButton = [[UIButton alloc] init];
- //_upLoadStateButton.backgroundColor = [UIColor redColor];
- [self.contentView addSubview:_upLoadStateButton];
- [_upLoadStateButton addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [_upLoadStateButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(-5);
- make.width.mas_equalTo(50);
- make.height.mas_equalTo(50);
- make.bottom.mas_equalTo(-18);
- }];
-
- if (self.selectButton == nil) {
- UIButton *but = [[UIButton alloc] init];
- [but setImage:[UIImage imageNamed:@"upload_file_uncheck"] forState:UIControlStateNormal];
- [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
- [self.contentView addSubview:but];
- [but addTarget:self action:@selector(didClickSelectButFun:) forControlEvents:UIControlEventTouchUpInside];
- but.hidden = YES;
- //but.backgroundColor = [UIColor greenColor];
- //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
- [but mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(30);
- make.height.mas_equalTo(30);
- make.centerX.mas_equalTo(_upLoadStateButton.mas_centerX);
- make.centerY.mas_equalTo(_upLoadStateButton.mas_centerY);
- }];
-
- self.selectButton = but;
- }
-
- _progressBgView = [[UIView alloc] init];
- _progressBgView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
- _progressBgView.layer.cornerRadius = 1.5;
- _progressBgView.layer.masksToBounds = YES;
- [self.contentView addSubview:_progressBgView];
-
- [_progressBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
- make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
- make.height.mas_equalTo(2);
- make.centerY.mas_equalTo(0);
- }];
-
- _progressSelectView = [[UIView alloc] init];
- //_progressSelectView.backgroundColor = [UIColor hwColor:@"#F9F9F9" alpha:1.0];
- _progressSelectView.layer.cornerRadius = 1.5;
- _progressSelectView.layer.masksToBounds = YES;
- [_progressBgView addSubview:_progressSelectView];
-
- // [_progressSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.left.mas_equalTo(0);
- // make.right.mas_equalTo(-100);
- // make.height.mas_equalTo(3);
- // make.centerY.mas_equalTo(0);
- // }];
-
- // gradient
- _glayer = [CAGradientLayer layer];
- _glayer.startPoint = CGPointMake(0, 0.5);
- _glayer.endPoint = CGPointMake(1, 0.5);
- _glayer.colors = @[(__bridge id)[UIColor hwColor:@"#0BDDFD" alpha:1.0].CGColor, (__bridge id)[UIColor hwColor:@"#048CFB" alpha:1.0].CGColor];
- _glayer.locations = @[@(0), @(1.0f)];
- [_progressSelectView.layer addSublayer:_glayer];
-
- CGRect frame = CGRectMake(0, 0, SCREEN_W, 2);
- //_progressSelectView.frame = frame;
- _glayer.frame = frame;
-
- _fileNamelabel = [[UILabel alloc] init];
- _fileNamelabel.font = [UIFont boldSystemFontOfSize:16.0];
- _fileNamelabel.textColor = [UIColor blackColor];
- //_fileNamelabel.backgroundColor = [UIColor greenColor];
- _fileNamelabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
- [self.contentView addSubview:_fileNamelabel];
-
- [_fileNamelabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
- make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
- make.height.mas_equalTo(19);
- make.bottom.mas_equalTo(_progressBgView.mas_top).offset(-3);
- }];
-
- _fileProgresslabel = [[UILabel alloc] init];
- _fileProgresslabel.font = [UIFont systemFontOfSize:12.0];
- _fileProgresslabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
- //_fileProgresslabel.backgroundColor = [UIColor greenColor];
- [self.contentView addSubview:_fileProgresslabel];
-
- [_fileProgresslabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(_fileImageView.mas_right).offset(10);
- make.right.mas_equalTo(_progressBgView.mas_centerX).offset(100);
- make.height.mas_equalTo(15);
- make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
- }];
-
- _fileSpeedlabel = [[UILabel alloc] init];
- _fileSpeedlabel.font = [UIFont systemFontOfSize:12.0];
- _fileSpeedlabel.textColor = [UIColor hwColor:@"#959799" alpha:1.0];
- _fileSpeedlabel.textAlignment = NSTextAlignmentRight;
- //_fileSpeedlabel.backgroundColor = [UIColor blackColor];
- [self.contentView addSubview:_fileSpeedlabel];
-
- [_fileSpeedlabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(_upLoadStateButton.mas_left).offset(-10);
- make.left.mas_equalTo(_progressBgView.mas_centerX);
- // make.height.mas_equalTo(15);
- make.top.mas_equalTo(_progressBgView.mas_bottom).offset(3);
- }];
-
- //长按手势
- UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
- //用几个手指触屏,默认1
- longPressGesture.numberOfTouchesRequired = 1;
- //设置最短长按时间,单位为秒(默认0.5)
- longPressGesture.minimumPressDuration = 1;
- //设置手势识别期间所允许的手势可移动范围
- longPressGesture.allowableMovement = 10;
- [self.contentView addGestureRecognizer:longPressGesture];
- }
- - (void)setIsEditType:(BOOL)isEditType
- {
- _isEditType = isEditType;
-
- if(isEditType){
- self.selectButton.hidden = NO;
-
- // if(_curUploadFileDataModel.curUploadStateType == uploadStateWait
- // ||_curUploadFileDataModel.curUploadStateType == uploadStateUploading
- // ||_curUploadFileDataModel.curUploadStateType == uploadStateSuspend){
- _upLoadStateButton.hidden = YES;
- //}
- }
- else{
- self.selectButton.hidden = YES;
-
- if(//_curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin
- _curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading
- ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
- _upLoadStateButton.hidden = NO;
- }
- }
- }
- - (void)setIsSelectType:(BOOL)isSelectType
- {
- _isSelectType = isSelectType;
-
- if(isSelectType){
- self.selectButton.selected = YES;
- }
- else{
- self.selectButton.selected = NO;
- }
- }
- - (void)setCurShareFileDataModel:(ShareFileDataModel *)curShareFileDataModel
- {
-
- _progressBgView.hidden = NO;
- _upLoadStateButton.hidden = NO;
-
- if (!_curShareFileDataModel ||
- ![_curShareFileDataModel.fileUrl isEqualToString:curShareFileDataModel.fileUrl])
- {
-
- if(_curShareFileDataModel){
- HLog(@"%@\n%@",_curShareFileDataModel.fileUrl,curShareFileDataModel.fileUrl);
- }
-
- [self setFixedValueByModel:curShareFileDataModel];
- }
-
- // if(_curShareFileDataModel
- // &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
- // ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
- // ){
- // return;
- // }
-
- _curShareFileDataModel = curShareFileDataModel;
-
- if(_curShareFileDataModel.downloadBoxStateType != downloadBoxStateDownloadloading){
- _fileSpeedlabel.hidden = YES;
- _fileSpeedlabel.text = @" ";
- }
-
- //HLog(@"1111111: %@ %@",curShareFileDataModel.fileUrl,curShareFileDataModel.fileSize);
- //进度设置
- CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
-
- if(curShareFileDataModel.totalSize == 0){
- curShareFileDataModel.totalSize = curShareFileDataModel.fileSize.longLongValue;
- }
-
- NSInteger totalSize = curShareFileDataModel.totalSize;
- if(totalSize == 0.0){
- totalSize += 0.0001;
- }
-
- CGFloat curProgress = curShareFileDataModel.currentSize/(totalSize*1.0);
-
- if(curProgress > 1){
- curProgress = 1;
- }
-
- frame.size.width = frame.size.width * curProgress;
-
- if (isnan(frame.size.width))
- {
- HLog(@"计算出错了");
- frame.size.width = 10.0;
- }
-
- // HLog(@"%f, %f, %f, %f,",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);
- // HLog(@"%@",_progressSelectView);
-
- _progressSelectView.frame = frame;
- //_glayer.frame = frame;
-
- NSString * totalSizeStr = nil;
- NSInteger totalSize_k = totalSize / 1024;
- if(totalSize_k < 1024){
- totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
- }
- else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
- totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
-
- }
- else{
- totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
- }
-
- NSString * didUploadStr = nil;
- NSInteger didUploadSize_k = curShareFileDataModel.currentSize / 1024;
- if(didUploadSize_k < 1024){
- didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
- }
- else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
- didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
-
- }
- else{
- didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
- }
-
- // if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateBegin){
- // [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_wait"] forState:UIControlStateNormal];
- // }
- // else
- if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
- _fileSpeedlabel.hidden = NO;
-
- if(curShareFileDataModel.preTimeInterval <= 0
- || curShareFileDataModel.currentSize == curShareFileDataModel.preDownloadBytes){
- //_fileSpeedlabel.text = @"--";
- }
- else{
- NSTimeInterval timers = curShareFileDataModel.curTimeInterval - curShareFileDataModel.preTimeInterval;
-
- if(timers > 0){
- //long speed= 1*1024*1024 / timers;
-
- long speed= (curShareFileDataModel.currentSize - curShareFileDataModel.preDownloadBytes) / timers;
-
- NSString * speedStr = nil;
- NSInteger speed_k = speed / (1024);
- if(speed_k < 1024){
- speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
- }
- else {
- speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
- }
-
- _fileSpeedlabel.text = speedStr;
- }
- }
-
- curShareFileDataModel.preTimeInterval = curShareFileDataModel.curTimeInterval;
- curShareFileDataModel.preDownloadBytes = curShareFileDataModel.currentSize;
- }
- else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
- }
- else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_reStart"] forState:UIControlStateNormal];
- _progressBgView.hidden = YES;
- }
- else{
- _upLoadStateButton.hidden = YES;
- _progressBgView.hidden = YES;
- }
-
-
- if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone){
- NSString*tipStr = NSLocalizedString(@"File_download_Path_other_done",nil);
-
- if([iTools canSaveFileToAlbumByPhoto:YES withName:curShareFileDataModel.fileName]
- ||[iTools canSaveFileToAlbumByPhoto:NO withName:curShareFileDataModel.fileName]){
- tipStr = NSLocalizedString(@"File_download_Path_default_done",nil);
- }
-
- _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@ %@",totalSizeStr,tipStr];
- }
- else if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail){
- NSString*tipStr = curShareFileDataModel.failMsg ? curShareFileDataModel.failMsg : @"";
- NSString *allStr = [[NSString alloc] initWithFormat:@"%@ %@",totalSizeStr,tipStr];
-
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:allStr];
- NSRange redRange = NSMakeRange([allStr rangeOfString:tipStr].location, [allStr rangeOfString:tipStr].length);
- UIColor *noteColor =[UIColor hwColor:@"#DD4E4E" alpha:1.0];
- [attrStr addAttribute:NSForegroundColorAttributeName value:noteColor range:redRange];
- //[attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12.0] range:redRange];
- _fileProgresslabel.attributedText = attrStr;
- }
- else{
- _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
- }
-
- }
- #pragma mark setImage
- - (void)setFixedValueByModel:(ShareFileDataModel *)curShareFileDataModel
- {
- if ([_fileNamelabel.text isEqualToString:curShareFileDataModel.fileName]) {
- return;
- }
-
- _fileNamelabel.text = curShareFileDataModel.fileName;
-
- NSArray *nameArr= [curShareFileDataModel.fileName componentsSeparatedByString:@"."];
-
- //HLog(@"fileName: %@",curShareFileDataModel.fileName);
- if (nameArr.count >= 2) {
- NSString *lastName = nameArr.lastObject;
-
- lastName = [lastName lowercaseString];
- //HLog(@"lastName: %@",lastName);
- if ([lastName rangeOfString:@"txt"].location != NSNotFound) {
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_TXT"];
- }
- else if ([lastName rangeOfString:@"pdf"].location != NSNotFound) {
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_pdf"];
- }
- else if ([lastName rangeOfString:@"xlsx"].location != NSNotFound) {
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_xlsx"];
- }
- else if ([lastName rangeOfString:@"doc"].location != NSNotFound
- ||[lastName rangeOfString:@"docx"].location != NSNotFound) {
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_doc"];
- }
- else if ([iTools isAudioFilewithName:lastName]) {
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_audio"];
- }
- else if ([iTools isPhotoFilewithName:lastName]) {//JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
- //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
-
- NSString *fileUrl = curShareFileDataModel.headUrl;
- HLog(@"11图片1:%@",fileUrl);
- fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- __block UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_image"];
-
- UIImage *cacheImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:fileUrl];
- if(cacheImage){
- _fileImageView.image = cacheImage;
- }
- else{
- [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- if(image){
- //HLog(@"11图片1:%@",imageURL.absoluteString);
- }
- else{
- //HLog(@"11图片0:%@",imageURL.absoluteString);
- //self->_fileImageView.image = defaultImage;
- }
-
- }];
- }
- }
- else if ([iTools isVideoFilewithName:lastName]) {//JPG、JPEG、PNG、GIF、BMP、SVG、TIFF、HEIC。
- //MP4、AVI、FLV、WMV、MKV、TS、MOV、RMVB。
-
- NSString *fileUrl = curShareFileDataModel.headUrl;
- HLog(@"11图片1:%@",fileUrl);
- fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- __block UIImage * defaultImage = [UIImage imageNamed:@"uploadFile_Video"];
- UIImage *cacheImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:fileUrl];
- if(cacheImage){
- _fileImageView.image = cacheImage;
- }
- else{
- [_fileImageView sd_setImageWithURL:[NSURL URLWithString:fileUrl] placeholderImage:defaultImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
- if(image){
- //HLog(@"11图片1:%@",imageURL.absoluteString);
- }
- else{
- //HLog(@"11图片0:%@",imageURL.absoluteString);
- //self->_fileImageView.image = defaultImage;
- }
-
- }];
- }
- }
- else{
- _fileImageView.image = [UIImage imageNamed:@"uploadFile_other"];
- }
- }
-
-
- }
- //下载中最更进度
- - (void)updateDataDownloadingBy:(ShareFileDataModel*)curShareFileDataModel{
-
- if(_curShareFileDataModel
- &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
- ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
- ){
- return;
- }
- NSString * speedStr = nil;
- //进度设置
- CGRect frame = CGRectMake(0, 0, SCREEN_W - 15*2 - 34*2, 2);
-
- if(curShareFileDataModel.totalSize == 0){
- curShareFileDataModel.totalSize = curShareFileDataModel.fileSize.longLongValue;
- }
-
- NSInteger totalSize = curShareFileDataModel.totalSize;
- if(totalSize == 0.0){
- totalSize += 0.0001;
- }
-
- CGFloat curProgress = curShareFileDataModel.currentSize/(totalSize*1.0);
-
- if(curProgress > 1){
- curProgress = 1;
- }
-
- frame.size.width = frame.size.width * curProgress;
-
- if (isnan(frame.size.width))
- {
- HLog(@"计算出错了");
- frame.size.width = 10.0;
- }
-
- _progressSelectView.frame = frame;
- //_glayer.frame = frame;
-
- NSString * totalSizeStr = nil;
- NSInteger totalSize_k = totalSize / 1024;
- if(totalSize_k < 1024){
- totalSizeStr = [[NSString alloc] initWithFormat:@"%ldKB",totalSize_k];
- }
- else if( totalSize_k >= 1024 && totalSize_k < 1024*1024){
- totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fMB",totalSize_k/1024.0];
-
- }
- else{
- totalSizeStr = [[NSString alloc] initWithFormat:@"%.2fG",totalSize_k/1024.0/1024.0];
- }
-
- NSString * didUploadStr = nil;
- NSInteger didUploadSize_k = curShareFileDataModel.currentSize / 1024;
- if(didUploadSize_k < 1024){
- didUploadStr = [[NSString alloc] initWithFormat:@"%ldKB",didUploadSize_k];
- }
- else if( didUploadSize_k >= 1024 && didUploadSize_k < 1024*1024){
- didUploadStr = [[NSString alloc] initWithFormat:@"%.2fMB",didUploadSize_k/1024.0];
-
- }
- else{
- didUploadStr = [[NSString alloc] initWithFormat:@"%.2fG",didUploadSize_k/1024.0/1024.0];
- }
-
- _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
- if(curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
- _fileSpeedlabel.hidden = NO;
-
- if(curShareFileDataModel.preTimeInterval <= 0
- || curShareFileDataModel.currentSize == curShareFileDataModel.preDownloadBytes){
- //_fileSpeedlabel.text = @"--";
- }
- else{
- NSTimeInterval timers = curShareFileDataModel.curTimeInterval - curShareFileDataModel.preTimeInterval;
-
- if(timers > 0){
- //long speed= 1*1024*1024 / timers;
-
- long speed= (curShareFileDataModel.currentSize - curShareFileDataModel.preDownloadBytes) / timers;
-
-
- NSInteger speed_k = speed / (1024);
- if(speed_k < 1024){
- speedStr = [[NSString alloc] initWithFormat:@"%ldKB/s",speed_k];
- }
- else {
- speedStr = [[NSString alloc] initWithFormat:@"%.2fMB/s",speed_k/1024.0];
- }
-
- //HLog(@"22211:%@",_fileSpeedlabel.description);
- }
- }
-
- curShareFileDataModel.preTimeInterval = curShareFileDataModel.curTimeInterval;
- curShareFileDataModel.preDownloadBytes = curShareFileDataModel.currentSize;
- }
- if (speedStr) {
- self->_fileSpeedlabel.text = speedStr;
- }
- }
- -(void)longPressClick:(UILongPressGestureRecognizer *)press{
- //state属性是所有手势父类提供的方法,用于记录手势的状态
- if(press.state == UIGestureRecognizerStateBegan){
- //NSLog(@"长按手势开始响应!");
-
- if(_didLongPressClick){
- _didLongPressClick();
- }
-
- }else if (press.state == UIGestureRecognizerStateChanged){
- //NSLog(@"长按手势状态发生改变!");
- }else{
- //NSLog(@"长按手势结束!");
- }
- }
- - (void)didClickSelectButFun:(UIButton*)but
- {
- but.selected = !but.selected;
- if(_didClckSelectBut){
- _didClckSelectBut(but.selected);
- }
- }
- - (void)tapClick:(UIButton*)but{
- if(_didTapPressClick){
- _didTapPressClick();
- }
-
- if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDownloadloading){
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_start"] forState:UIControlStateNormal];
-
- }
- else if(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateSuspend){
- _fileSpeedlabel.text = @"";
- [_upLoadStateButton setImage:[UIImage imageNamed:@"uploadFile_suspend"] forState:UIControlStateNormal];
- }
-
-
- but.userInteractionEnabled = NO;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- but.userInteractionEnabled = YES;
- });
- }
- //#pragma mark 下载通知
- - (void)downloadTaskDownloadingNoti:(NSNotification *)notification
- {
- customDownloadOperation *model = notification.userInfo.allValues.firstObject;
- if(!model)return;
-
- if (model.downloadState != customDownloadStateDoing) {
- return;
- }
- mainBlock(^{
- [self downloadItem:model downloadedSize:model.currentSize totalSize:model.totalSize];
- });
- }
- - (void)downloadItem:(customDownloadOperation *)model downloadedSize:(int64_t)downloadedSize totalSize:(int64_t)totalSize {
-
- //解码
- NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- HLog(@"下载中:%lld --- %lld \n%@\n%@",downloadedSize,totalSize,urlString,_curShareFileDataModel.fileUrl);
-
- if(_curShareFileDataModel
- &&(_curShareFileDataModel.downloadBoxStateType != downloadBoxStateDownloadloading)
- ){
- HLog(@"当前状态 -- %u",_curShareFileDataModel.downloadBoxStateType);
- return;
- }
-
- if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
- ||downloadedSize == totalSize) { // 不是这一个任务
- return;
- }
- _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
- _curShareFileDataModel.currentSize = downloadedSize;
- _curShareFileDataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
-
- KWeakSelf
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf updateDataDownloadingBy:self->_curShareFileDataModel];
- });
- // mainBlock(^{
- // [self updateDataDownloadingBy:self->_curShareFileDataModel];
- // });
- }
- @end
|