Commit 66f6f4ec authored by Felix Paul Kühne's avatar Felix Paul Kühne

centralize network activity indicator management to fix corner-case issues

parent d8eed78b
......@@ -29,6 +29,10 @@
- (void)disableIdleTimer;
- (void)activateIdleTimer;
- (void)networkActivityStarted;
- (BOOL)haveNetworkActivity;
- (void)networkActivityStopped;
- (void)cleanCache;
- (void)openMediaFromManagedObject:(NSManagedObject *)file;
......
......@@ -33,6 +33,7 @@
VLCGoogleDriveTableViewController *_googleDriveTableViewController;
VLCDownloadViewController *_downloadViewController;
int _idleCounter;
int _networkActivityCounter;
VLCMovieViewController *_movieViewController;
BOOL _passcodeValidated;
}
......@@ -226,6 +227,9 @@
- (void)cleanCache
{
if ([self haveNetworkActivity])
return;
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* uploadDirPath = [searchPaths[0] stringByAppendingPathComponent:@"Upload"];
NSFileManager *fileManager = [NSFileManager defaultManager];
......@@ -317,6 +321,25 @@
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
- (void)networkActivityStarted
{
_networkActivityCounter++;
if ([UIApplication sharedApplication].networkActivityIndicatorVisible == NO)
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (BOOL)haveNetworkActivity
{
return _networkActivityCounter >= 1;
}
- (void)networkActivityStopped
{
_networkActivityCounter--;
if (_networkActivityCounter < 1)
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
#pragma mark - playback view handling
- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
......
......@@ -223,7 +223,7 @@
- (void)downloadStarted
{
[self.activityIndicator stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
self.currentDownloadLabel.text = _humanReadableFilename;
self.progressView.progress = 0.;
[self.progressPercent setText:@"0%%"];
......@@ -237,7 +237,7 @@
- (void)downloadEnded
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
_currentDownloadType = 0;
APLog(@"download ended");
self.progressContainer.hidden = YES;
......
......@@ -204,7 +204,7 @@
{
_outstandingNetworkRequests++;
if (_outstandingNetworkRequests == 1) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -213,7 +213,7 @@
{
_outstandingNetworkRequests--;
if (_outstandingNetworkRequests == 0) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
}
}
......
......@@ -159,7 +159,7 @@
APLog(@"Could not create file at path: %@", _filepath);
_storeFile = [NSFileHandle fileHandleForWritingAtPath:_filepath];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
......
......@@ -50,7 +50,7 @@
_downloadInProgress = NO;
} else {
_downloadInProgress = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -72,7 +72,7 @@
_downloadInProgress = NO;
} else {
_downloadInProgress = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStarted];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -157,7 +157,7 @@
- (void)_downloadEnded
{
_downloadInProgress = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
......
......@@ -170,7 +170,7 @@
[fileManager removeItemAtPath:filepath error:nil];
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate networkActivityStopped];
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
/* update media library when file upload was completed */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment