|
@@ -76,9 +76,7 @@
|
|
[self ldvCreateUI];
|
|
[self ldvCreateUI];
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
// 清理几天前 downloadFilesPath && otherAppFilesPath 文件
|
|
// 清理几天前 downloadFilesPath && otherAppFilesPath 文件
|
|
[self.fileUtil cleanFileAfterDays:self.loadDocViewParamModel.daysAgo filePathArray:nil];
|
|
[self.fileUtil cleanFileAfterDays:self.loadDocViewParamModel.daysAgo filePathArray:nil];
|
|
@@ -95,6 +93,24 @@
|
|
_shareblock = block;
|
|
_shareblock = block;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+-(void)previewFileView:(BOOL)b {
|
|
|
|
+ if (b) {
|
|
|
|
+ [UIView animateWithDuration:0.5 animations:^{
|
|
|
|
+ [self.docWebView setY:self.height];
|
|
|
|
+ } completion:^(BOOL finished) {
|
|
|
|
+
|
|
|
|
+ }];
|
|
|
|
+ }else {
|
|
|
|
+ [UIView animateWithDuration:0.5 animations:^{
|
|
|
|
+ [self.docWebView setY:0];
|
|
|
|
+ } completion:^(BOOL finished) {
|
|
|
|
+
|
|
|
|
+ }];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
#pragma mark - Private Method
|
|
#pragma mark - Private Method
|
|
/** 创建文件工具类 */
|
|
/** 创建文件工具类 */
|
|
- (void)ldvCreatefileUtil {
|
|
- (void)ldvCreatefileUtil {
|
|
@@ -133,28 +149,22 @@
|
|
__weak typeof(self) weakSelf = self;
|
|
__weak typeof(self) weakSelf = self;
|
|
// 点击block 0-重新加载,1-点击关闭
|
|
// 点击block 0-重新加载,1-点击关闭
|
|
[self.downloadView clickBtnBlock:^(NSInteger index) {
|
|
[self.downloadView clickBtnBlock:^(NSInteger index) {
|
|
- if (index == 0) {
|
|
|
|
- // 重新加载
|
|
|
|
|
|
+ if (index == 0) {// 重新加载
|
|
[self ldvDrawProgressUIForDowningFile];
|
|
[self ldvDrawProgressUIForDowningFile];
|
|
[weakSelf ldvRetryClick];
|
|
[weakSelf ldvRetryClick];
|
|
- } else if (index == 3) {
|
|
|
|
- NSString *pathUrl = [[_fileUtil stitchLocalFilePath] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- if (_shareblock) {
|
|
|
|
- _shareblock(pathUrl);
|
|
|
|
|
|
+ } else if (index == 3) { //分享点击
|
|
|
|
+ NSString *pathUrl = [[self->_fileUtil stitchLocalFilePath] stringByRemovingPercentEncoding];
|
|
|
|
+ if (self->_shareblock) {
|
|
|
|
+ self->_shareblock(pathUrl);
|
|
}
|
|
}
|
|
- } else if (index == 2) {
|
|
|
|
- //打开页面
|
|
|
|
- self.downloadView.hidden = YES;
|
|
|
|
- // 创建WebView
|
|
|
|
|
|
+ } else if (index == 2) { //预览页面
|
|
[weakSelf ldvCreateWebView];
|
|
[weakSelf ldvCreateWebView];
|
|
- //网络下载成功,本地路径
|
|
|
|
- NSString *pathUrl = [[_fileUtil stitchLocalFilePath] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
- if (_block) {
|
|
|
|
- _block(pathUrl);
|
|
|
|
|
|
+ NSString *pathUrl = [[self->_fileUtil stitchLocalFilePath] stringByRemovingPercentEncoding];
|
|
|
|
+ if (self->_block) {
|
|
|
|
+ self->_block(pathUrl);
|
|
}
|
|
}
|
|
- self.docWebView.hidden = NO;
|
|
|
|
- }else {
|
|
|
|
- // 点击关闭
|
|
|
|
|
|
+ [self previewFileView:false];
|
|
|
|
+ }else { //点击关闭
|
|
[weakSelf ldvCloseClick];
|
|
[weakSelf ldvCloseClick];
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
@@ -167,24 +177,18 @@
|
|
#pragma mark 判断是否具备下载条件(网络 && 存储空间)
|
|
#pragma mark 判断是否具备下载条件(网络 && 存储空间)
|
|
/** 判断是否具备下载条件(网络) */
|
|
/** 判断是否具备下载条件(网络) */
|
|
- (void)ldvJudgeDownloadConditions {
|
|
- (void)ldvJudgeDownloadConditions {
|
|
- if ([self ldvCurrentFreeDiskSpaceToFileSize] < 0) {
|
|
|
|
- // 内存不足
|
|
|
|
|
|
+ if ([self ldvCurrentFreeDiskSpaceToFileSize] < 0) {// 内存不足
|
|
[self ldvShowDumpingView:self.loadDocViewParamModel.notEnoughMemoryHint];
|
|
[self ldvShowDumpingView:self.loadDocViewParamModel.notEnoughMemoryHint];
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
- return;
|
|
|
|
if (([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_2G) || ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_3G) || ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_4G)) {
|
|
if (([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_2G) || ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_3G) || ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_4G)) {
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"下载流量提醒" message:@"当前处于非wifi环境,继续查看将会产生手机流量" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
|
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"下载流量提醒" message:@"当前处于非wifi环境,继续查看将会产生手机流量" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
|
|
-
|
|
|
|
alert.tag = 123;
|
|
alert.tag = 123;
|
|
[alert show];
|
|
[alert show];
|
|
-
|
|
|
|
} else if ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_None) {
|
|
} else if ([JhtNetworkCheckTools currentNetWork_Status] == NetWorkStatus_None) {
|
|
- // 没网啥都不做
|
|
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
- // 开始下载
|
|
|
|
- [self ldvDrawProgressUIForDowningFile];
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -236,8 +240,8 @@
|
|
[self.downloadView.fileProgressView setProgress:downloadProgress.fractionCompleted animated:YES];
|
|
[self.downloadView.fileProgressView setProgress:downloadProgress.fractionCompleted animated:YES];
|
|
});
|
|
});
|
|
} setupFilePath:^NSURL *(NSURLResponse *response) {
|
|
} setupFilePath:^NSURL *(NSURLResponse *response) {
|
|
- NSString *cachePath = [NSString stringWithFormat:@"%@", _currentFileModel.fileName];
|
|
|
|
- NSString *filePath = [_fileUtil stitchDownloadFilePath];
|
|
|
|
|
|
+ NSString *cachePath = [NSString stringWithFormat:@"%@", self->_currentFileModel.fileName];
|
|
|
|
+ NSString *filePath = [self->_fileUtil stitchDownloadFilePath];
|
|
BOOL isDir = NO;
|
|
BOOL isDir = NO;
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
|
|
BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
|
|
@@ -250,15 +254,14 @@
|
|
} downloadCompletionHandler:^(NSURL *filePath, NSError *error) {
|
|
} downloadCompletionHandler:^(NSURL *filePath, NSError *error) {
|
|
NSLog(@"fileDownloadError ==> %@", error);
|
|
NSLog(@"fileDownloadError ==> %@", error);
|
|
if (!error) {
|
|
if (!error) {
|
|
- NSString *filePath = [_fileUtil stitchLocalFilePath];
|
|
|
|
|
|
+ NSString *filePath = [self->_fileUtil stitchLocalFilePath];
|
|
CGFloat fileSize = [self ldvFileSizeForPath:filePath];
|
|
CGFloat fileSize = [self ldvFileSizeForPath:filePath];
|
|
- self.downloadView.hidden = NO;
|
|
|
|
self.downloadView.fileProgressView.hidden = YES;
|
|
self.downloadView.fileProgressView.hidden = YES;
|
|
self.downloadView.closeBtn.hidden = YES;
|
|
self.downloadView.closeBtn.hidden = YES;
|
|
self.downloadView.downloadBtn.hidden = YES;
|
|
self.downloadView.downloadBtn.hidden = YES;
|
|
self.downloadView.downloadingStateLabel.hidden = NO;
|
|
self.downloadView.downloadingStateLabel.hidden = NO;
|
|
- self.downloadView.downloadingStateLabel.text = [NSString stringWithFormat:@"文件大小:%.f",fileSize];
|
|
|
|
- if(_currentFileModel.viewFileType==Type_Unknow) {
|
|
|
|
|
|
+ self.downloadView.downloadingStateLabel.text = [NSString stringWithFormat:@"文件大小:%@",[NSByteCountFormatter stringFromByteCount:fileSize countStyle:NSByteCountFormatterCountStyleFile]];
|
|
|
|
+ if(self->_currentFileModel.viewFileType==Type_Unknow) {
|
|
self.downloadView.openBtn.hidden = YES;
|
|
self.downloadView.openBtn.hidden = YES;
|
|
self.downloadView.shareBtn.hidden = NO;
|
|
self.downloadView.shareBtn.hidden = NO;
|
|
}else{
|
|
}else{
|
|
@@ -266,14 +269,11 @@
|
|
self.downloadView.shareBtn.hidden = YES;
|
|
self.downloadView.shareBtn.hidden = YES;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
- self.downloadView.hidden = NO;
|
|
|
|
self.downloadView.downloadingStateLabel.text = self.loadDocViewParamModel.downloadFailedHint;
|
|
self.downloadView.downloadingStateLabel.text = self.loadDocViewParamModel.downloadFailedHint;
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
- self.docWebView.hidden = YES;
|
|
|
|
// 文件下载失败时,清除文件路径
|
|
// 文件下载失败时,清除文件路径
|
|
- [_fileUtil removeFileWhenDownloadFileFailure];
|
|
|
|
|
|
+ [self->_fileUtil removeFileWhenDownloadFileFailure];
|
|
}
|
|
}
|
|
}];
|
|
}];
|
|
}
|
|
}
|
|
@@ -298,7 +298,7 @@
|
|
#pragma mark - Getter
|
|
#pragma mark - Getter
|
|
- (JhtDocWebView *)docWebView {
|
|
- (JhtDocWebView *)docWebView {
|
|
if (!_docWebView) {
|
|
if (!_docWebView) {
|
|
- _docWebView = [[JhtDocWebView alloc] initWithFrame:CGRectMake(0, 0, FrameW, FrameH)];
|
|
|
|
|
|
+ _docWebView = [[JhtDocWebView alloc] initWithFrame:CGRectMake(0, FrameH, FrameW, FrameH)];
|
|
}
|
|
}
|
|
|
|
|
|
return _docWebView;
|
|
return _docWebView;
|
|
@@ -402,19 +402,15 @@
|
|
#pragma mark - UIAlertViewDelegate
|
|
#pragma mark - UIAlertViewDelegate
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
if (alertView.tag == 123) {
|
|
if (alertView.tag == 123) {
|
|
- if (buttonIndex == 1) {
|
|
|
|
- // 开始下载
|
|
|
|
|
|
+ if (buttonIndex == 1) {// 开始下载
|
|
[self ldvDrawProgressUIForDowningFile];
|
|
[self ldvDrawProgressUIForDowningFile];
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
// 展示下载
|
|
// 展示下载
|
|
- self.downloadView.hidden = NO;
|
|
|
|
self.downloadView.fileProgressView.hidden = YES;
|
|
self.downloadView.fileProgressView.hidden = YES;
|
|
self.downloadView.closeBtn.hidden = YES;
|
|
self.downloadView.closeBtn.hidden = YES;
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
self.downloadView.downloadBtn.hidden = NO;
|
|
self.downloadView.downloadingStateLabel.hidden = NO;
|
|
self.downloadView.downloadingStateLabel.hidden = NO;
|
|
self.downloadView.downloadingStateLabel.text = @"该文件暂不支持在线预览,请下载后查看";
|
|
self.downloadView.downloadingStateLabel.text = @"该文件暂不支持在线预览,请下载后查看";
|
|
- self.docWebView.hidden = YES;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|