Преглед на файлове

Dropbox: add progress indicator shown when downloading files

Felix Paul Kühne преди 12 години
родител
ревизия
ccabc65d86

+ 4 - 0
AspenProject/VLCDropboxController.h

@@ -12,6 +12,10 @@
 @required
 - (void)mediaListUpdated;
 
+@optional
+- (void)operationWithProgressInformationStarted;
+- (void)currentProgressInformation:(float)progress;
+- (void)operationWithProgressInformationStopped;
 @end
 
 @interface VLCDropboxController : NSObject <DBRestClientDelegate, DBSessionDelegate, DBNetworkRequestDelegate>

+ 10 - 1
AspenProject/VLCDropboxController.m

@@ -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

+ 34 - 2
AspenProject/VLCDropboxTableViewController.m

@@ -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

BIN
Resources/de.lproj/Localizable.strings


BIN
Resources/en.lproj/Localizable.strings


BIN
Resources/fr.lproj/Localizable.strings


BIN
Resources/ru.lproj/Localizable.strings