|
|
@@ -10,6 +10,7 @@
|
|
|
#import "cachesFileManager.h"
|
|
|
#import <SDWebImage/SDWebImage.h>
|
|
|
#import "downloadThumbnailManager.h"
|
|
|
+#import "SGDownloadManager.h"
|
|
|
|
|
|
@interface boxDownloadFileRecordCell ()
|
|
|
@property(nonatomic,strong) UIImageView *fileImageView;
|
|
|
@@ -34,6 +35,14 @@
|
|
|
|
|
|
if (self)
|
|
|
{
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeIng:) name:SGDownloadTaskExeing object:nil];
|
|
|
+
|
|
|
+// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeEnd:) name:SGDownloadTaskExeEnd object:nil];
|
|
|
+//
|
|
|
+// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeError:) name:SGDownloadTaskExeError object:nil];
|
|
|
+
|
|
|
+ //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadTaskExeSupend:) name:SGDownloadTaskExeSuspend object:nil];
|
|
|
+
|
|
|
[self drawView];
|
|
|
}
|
|
|
|
|
|
@@ -229,6 +238,13 @@
|
|
|
[self setFixedValueByModel:curShareFileDataModel];
|
|
|
}
|
|
|
|
|
|
+// if(_curShareFileDataModel
|
|
|
+// &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
|
|
|
+// ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
|
|
|
+// ){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
_curShareFileDataModel = curShareFileDataModel;
|
|
|
|
|
|
|
|
|
@@ -340,6 +356,7 @@
|
|
|
else{
|
|
|
_upLoadStateButton.hidden = YES;
|
|
|
_progressBgView.hidden = YES;
|
|
|
+ _fileSpeedlabel.text = @"";
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -452,6 +469,145 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
+//下载中最更进度
|
|
|
+- (void)updateDataDownloadingBy:(ShareFileDataModel*)curShareFileDataModel{
|
|
|
+
|
|
|
+ if(_curShareFileDataModel
|
|
|
+ &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
|
|
|
+ ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
|
|
|
+ ){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //进度设置
|
|
|
+ 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:@"%.1fMB",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:@"%.1fMB",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;
|
|
|
+
|
|
|
+ //
|
|
|
+ _fileSpeedlabel.text = @"";
|
|
|
+
|
|
|
+ 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:@"%.1fMB/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){
|
|
|
+ _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@",totalSizeStr];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ _fileProgresslabel.text = [[NSString alloc] initWithFormat:@"%@/%@",didUploadStr,totalSizeStr];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
-(void)longPressClick:(UILongPressGestureRecognizer *)press{
|
|
|
//state属性是所有手势父类提供的方法,用于记录手势的状态
|
|
|
if(press.state == UIGestureRecognizerStateBegan){
|
|
|
@@ -498,4 +654,88 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+- (void)downloadTaskExeIng:(NSNotification *)notification
|
|
|
+{
|
|
|
+ SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
|
|
|
+
|
|
|
+ NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+
|
|
|
+ //HLog(@"%@\n %@",urlString,_curShareFileDataModel.fileUrl);
|
|
|
+ if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]
|
|
|
+ ||model.totalSize == model.currentSize) { // 不是这一个任务
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(_curShareFileDataModel
|
|
|
+ &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
|
|
|
+ ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
|
|
|
+ ){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDownloadloading;
|
|
|
+ _curShareFileDataModel.currentSize = model.currentSize;
|
|
|
+ _curShareFileDataModel.curTimeInterval = [[NSDate date] timeIntervalSince1970];
|
|
|
+
|
|
|
+ mainBlock(^{
|
|
|
+ [self updateDataDownloadingBy:self->_curShareFileDataModel];
|
|
|
+ });
|
|
|
+ HLog(@"下载中");
|
|
|
+}
|
|
|
+
|
|
|
+- (void)downloadTaskExeSupend:(NSNotification *)notification
|
|
|
+{
|
|
|
+ SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
|
|
|
+ NSString * urlString = [model.url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
+ if (![urlString isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ HLog(@"%@",_curShareFileDataModel);
|
|
|
+ if(_curShareFileDataModel
|
|
|
+ &&(_curShareFileDataModel.downloadBoxStateType == downloadBoxStateDone
|
|
|
+ ||_curShareFileDataModel.downloadBoxStateType == downloadBoxStateFail)
|
|
|
+ ){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _curShareFileDataModel.downloadBoxStateType = downloadBoxStateSuspend;
|
|
|
+
|
|
|
+ mainBlock(^{
|
|
|
+ [self updateDataDownloadingBy:self->_curShareFileDataModel];
|
|
|
+ });
|
|
|
+ HLog(@"暂停/下载等待中");
|
|
|
+}
|
|
|
+
|
|
|
+//- (void)downloadTaskExeEnd:(NSNotification *)notification
|
|
|
+//{
|
|
|
+// SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
|
|
|
+//
|
|
|
+// if (![model.url isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// _curShareFileDataModel.downloadBoxStateType = downloadBoxStateDone;
|
|
|
+// mainBlock(^{
|
|
|
+// [self updateDataDownloadingBy:self->_curShareFileDataModel];
|
|
|
+// });
|
|
|
+// HLog(@"下载成功");
|
|
|
+//}
|
|
|
+
|
|
|
+//- (void)downloadTaskExeError:(NSNotification *)notification
|
|
|
+//{
|
|
|
+// SGDownloadOperation *model = notification.userInfo.allValues.firstObject;
|
|
|
+//
|
|
|
+// if (![model.url isEqualToString:_curShareFileDataModel.fileUrl]) { // 不是这一个任务
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// _curShareFileDataModel.downloadBoxStateType = downloadBoxStateFail;
|
|
|
+// mainBlock(^{
|
|
|
+// [self updateDataDownloadingBy:self->_curShareFileDataModel];
|
|
|
+// });
|
|
|
+// HLog(@"下载失败");
|
|
|
+//}
|
|
|
+
|
|
|
+
|
|
|
@end
|