Commit ccabc65d authored by Felix Paul Kühne's avatar Felix Paul Kühne

Dropbox: add progress indicator shown when downloading files

parent 1de26dad
......@@ -12,6 +12,10 @@
@required
- (void)mediaListUpdated;
@optional
- (void)operationWithProgressInformationStarted;
- (void)currentProgressInformation:(float)progress;
- (void)operationWithProgressInformationStopped;
@end
@interface VLCDropboxController : NSObject <DBRestClientDelegate, DBSessionDelegate, DBNetworkRequestDelegate>
......
......@@ -60,6 +60,9 @@
//FIXME: add UI hook to display activity
[[self restClient] loadFile:file.path intoPath:filePath];
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)])
[self.delegate operationWithProgressInformationStarted];
}
}
......@@ -102,16 +105,22 @@
/* update library now that we got a file */
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate updateMediaList];
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
[self.delegate operationWithProgressInformationStopped];
}
- (void)restClient:(DBRestClient*)client loadFileFailedWithError:(NSError*)error
{
APLog(@"DBFile download failed with error %i", error.code);
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
[self.delegate operationWithProgressInformationStopped];
}
- (void)restClient:(DBRestClient*)client loadProgress:(CGFloat)progress forFile:(NSString*)destPath
{
APLog(@"Download progress for DBFile '%@' %f", destPath.lastPathComponent, progress);
if ([self.delegate respondsToSelector:@selector(currentProgressInformation:)])
[self.delegate currentProgressInformation:progress];
}
#pragma mark - DBSession delegate
......
......@@ -20,6 +20,8 @@
UIBarButtonItem *_numberOfFilesBarButtonItem;
UIBarButtonItem *_progressBarButtonItem;
UIBarButtonItem *_downloadingBarLabel;
UIProgressView *_progressView;
}
@end
......@@ -56,12 +58,27 @@
self.tableView.rowHeight = [VLCDropboxTableViewCell heightOfCell];
self.tableView.separatorColor = [UIColor colorWithWhite:.2 alpha:1.];
_numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", @""), 0] style:UIBarButtonItemStylePlain target:self action:nil];
_numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", @""), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
[_numberOfFilesBarButtonItem setTitleTextAttributes:@{ UITextAttributeFont : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
_downloadingBarLabel = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"DOWNLOADING",@"") style:UIBarButtonItemStylePlain target:nil action:nil];
[_downloadingBarLabel setTitleTextAttributes:@{ UITextAttributeFont : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:NO];
[self _showProgressInToolbar:NO];
}
- (void)_showProgressInToolbar:(BOOL)value
{
if (!value)
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
else {
_progressView.progress = 0.;
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _downloadingBarLabel, _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
}
}
- (void)viewWillAppear:(BOOL)animated
......@@ -135,6 +152,21 @@
_numberOfFilesBarButtonItem.title = NSLocalizedString(@"ONE_FILE", @"");
}
- (void)operationWithProgressInformationStarted
{
[self _showProgressInToolbar:YES];
}
- (void)currentProgressInformation:(float)progress
{
[_progressView setProgress: progress animated:YES];
}
- (void)operationWithProgressInformationStopped
{
[self _showProgressInToolbar:NO];
}
#pragma mark - communication with app delegate
- (void)updateViewAfterSessionChange
......
B"CHOOSE_AUDIO_TRACK"="Audiospur wählen";
......
B"CHOOSE_AUDIO_TRACK"="Choose Audio Track";
......
B"CHOOSE_AUDIO_TRACK"="Choisir Piste Audio";
......
B"CHOOSE_AUDIO_TRACK"="Выберите аудио поток";
......
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