Commit 086b4fef authored by Felix Paul Kühne's avatar Felix Paul Kühne

Factorize idle timer handling

parent ee606932
......@@ -16,6 +16,8 @@
@interface VLCAppDelegate : UIResponder <UIApplicationDelegate>
- (void)updateMediaList;
- (void)disableIdleTimer;
- (void)activateIdleTimer;
@property (nonatomic, readonly) VLCPlaylistViewController *playlistViewController;
@property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController;
......
......@@ -23,6 +23,7 @@
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, VLCMediaFileDiscovererDelegate> {
PAPasscodeViewController *_passcodeLockController;
VLCDropboxTableViewController *_dropboxTableViewController;
int _idleCounter;
}
@property (nonatomic) BOOL passcodeValidated;
......@@ -249,4 +250,19 @@
// TODO handle error attempts
}
#pragma mark - idle timer preventer
- (void)disableIdleTimer
{
_idleCounter++;
if ([UIApplication sharedApplication].idleTimerDisabled == NO)
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
- (void)activateIdleTimer
{
_idleCounter--;
if (_idleCounter < 1)
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
@end
......@@ -172,7 +172,7 @@
_outstandingNetworkRequests++;
if (_outstandingNetworkRequests == 1) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[UIApplication sharedApplication].idleTimerDisabled = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -181,7 +181,7 @@
_outstandingNetworkRequests--;
if (_outstandingNetworkRequests == 0) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[UIApplication sharedApplication].idleTimerDisabled = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
}
}
......
......@@ -44,7 +44,7 @@
} else {
_downloadInProgress = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].idleTimerDisabled = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -129,7 +129,7 @@
{
_downloadInProgress = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[UIApplication sharedApplication].idleTimerDisabled = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
[self.delegate downloadEnded];
}
......
......@@ -284,7 +284,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
storeFile = [NSFileHandle fileHandleForWritingAtPath:filePath];
[uploadedFiles addObject: [NSString stringWithFormat:@"/upload/%@", filename]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].idleTimerDisabled = YES;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate disableIdleTimer];
}
}
......@@ -302,7 +302,7 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
[storeFile closeFile];
storeFile = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[UIApplication sharedApplication].idleTimerDisabled = NO;
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate activateIdleTimer];
/* update media library when file upload was completed */
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
......
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