updating progress indicator work

This commit is contained in:
dante ruiz 2019-07-02 20:56:49 -07:00
parent fb8027bdf5
commit f210be32dc
5 changed files with 48 additions and 7 deletions

View file

@ -3,6 +3,7 @@
@interface DownloadDomainContent : NSObject<NSURLSessionDataDelegate, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLDownloadDelegate> {
}
@property (nonatomic, assign) double progressPercentage;
@property (nonatomic, assign) double taskProgressPercentage;
- (void) downloadDomainContent:(NSString*) domainContentUrl;
- (double) getProgressPercentage;

View file

@ -5,12 +5,13 @@
- (double) getProgressPercentage
{
return self.progressPercentage;
return (self.progressPercentage * .90) + (self.taskProgressPercentage * .10);
}
- (void) downloadDomainContent:(NSString *)domainContentUrl
{
self.progressPercentage = 0.0;
self.taskProgressPercentage = 0.0;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:domainContentUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
@ -36,6 +37,11 @@
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url");
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(updatePercentage:)
userInfo:nil
repeats: YES];
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
@ -56,6 +62,7 @@
if (error) {
NSLog(@"DownlodDomainContent: failed to move file to destintation -> error: %@", error);
[timer invalidate];
[sharedLauncher displayErrorPage];
return;
}
@ -64,18 +71,27 @@
BOOL extractionSuccessful = [sharedLauncher extractZipFileAtDestination:[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:@"content"] :[[sharedLauncher getDownloadPathForContentAndScripts] stringByAppendingString:[sharedLauncher getDownloadContentFilename]]];
if (!extractionSuccessful) {
[timer invalidate];
[sharedLauncher displayErrorPage];
return;
}
NSLog(@"finished extracting content file");
[timer invalidate];
self.taskProgressPercentage = 100.0;
[sharedLauncher updateProgressIndicator];
[sharedLauncher domainContentDownloadFinished];
}
-(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
NSLog(@"completed; error: %@", error);
if (error) {
[[Launcher sharedLauncher] displayErrorPage];
}
}
- (void) updatePercentage:(NSTimer*) timer {
self.taskProgressPercentage += 3.0;
[[Launcher sharedLauncher] updateProgressIndicator];
}
@end

View file

@ -4,8 +4,9 @@
}
@property (nonatomic, assign) NSString* finalFilePath;
@property (nonatomic, assign) double progressPercentage;
@property (nonatomic, assign) double taskProgressPercentage;
- (void) downloadInterface:(NSString*) downloadUrl;
- (double) getProgressPercentage;
- (double) getProgressPercentage;
@end

View file

@ -7,6 +7,7 @@
- (void) downloadInterface:(NSString*) downloadUrl
{
self.progressPercentage = 0.0;
self.taskProgressPercentage = 0.0;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
@ -29,7 +30,7 @@
- (double) getProgressPercentage
{
return self.progressPercentage;
return (self.progressPercentage * 0.90) + (self.taskProgressPercentage * 0.10);
}
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didResumeAtOffset:(int64_t)fileOffset expectedTotalBytes:(int64_t)expectedTotalBytes {
@ -38,6 +39,11 @@
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
NSLog(@"Did finish downloading to url");
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
target: self
selector: @selector(updateTaskPercentage:)
userInfo:nil
repeats: YES];
NSError *error = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *destinationFileName = downloadTask.originalRequest.URL.lastPathComponent;
@ -53,6 +59,7 @@
if (error) {
NSLog(@"Download Interface: failed to move file to destination -> error: %@", error);
[timer invalidate];
[sharedLauncher displayErrorPage];
return;
}
@ -63,6 +70,7 @@
NSLog(@"extract interface zip");
BOOL success = [sharedLauncher extractZipFileAtDestination:appPath :[appPath stringByAppendingString:downloadFileName]];
if (!success) {
[timer invalidate];
[sharedLauncher displayErrorPage];
return;
}
@ -80,6 +88,9 @@
NSString* launcherPath = [appPath stringByAppendingString:@"Launcher"];
[[Settings sharedSettings] setLauncherPath:launcherPath];
[timer invalidate];
self.taskProgressPercentage = 100.0;
[sharedLauncher updateProgressIndicator];
[sharedLauncher interfaceFinishedDownloading];
}
@ -90,5 +101,10 @@
}
}
- (void) updateTaskPercentage:(NSTimer*) timer {
self.taskProgressPercentage += 3.0;
[[Launcher sharedLauncher] updateProgressIndicator];
}
@end

View file

@ -84,13 +84,20 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
- (void) updateProgressIndicator
{
NSProgressIndicator* progressIndicator = [self getProgressView];
//double oldValue = progressIndicator.doubleValue;
double oldValue = progressIndicator.doubleValue;
double contentPercentage = [self.downloadDomainContent getProgressPercentage];
double interfacePercentage = [self.downloadInterface getProgressPercentage];
//double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5);
double currentTotalPercentage = (contentPercentage * 0.5) + (interfacePercentage * 0.5);
//[progressIndicator incrementBy: (currentTotalPercentage - oldValue)];
progressIndicator.doubleValue = (contentPercentage * 0.4) + (interfacePercentage * 0.4);
progressIndicator.doubleValue = [self lerp:oldValue :currentTotalPercentage :0.7];
}
- (double) lerp:(double) pointA :(double) pointB :(double) interp
{
double lerpValue = pointA + interp * (pointB - pointA);
NSLog(@"----> lerp value: %f", lerpValue);
return lerpValue;
}
- (BOOL) extractZipFileAtDestination:(NSString *)destination :(NSString*)file