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

dropbox: rework to navigate correctly on ATV

Felix Paul Kühne преди 9 години
родител
ревизия
0c959ef79d

+ 3 - 1
Sources/VLCDropboxController.h

@@ -27,6 +27,8 @@
 - (BOOL)restoreFromSharedCredentials;
 
 - (void)downloadFileToDocumentFolder:(DBMetadata *)file;
-- (void)streamFile:(DBMetadata *)file;
+- (void)streamFile:(DBMetadata *)file currentNavigationController:(UINavigationController *)navigationController;
+
+- (void)reset;
 
 @end

+ 25 - 2
Sources/VLCDropboxController.m

@@ -19,6 +19,7 @@
 #import "VLCMediaFileDiscoverer.h"
 #endif
 #import "DBKeychain.h"
+#import "VLCDropboxConstants.h"
 
 @interface VLCDropboxController ()
 {
@@ -34,6 +35,8 @@
     CGFloat _fileSize;
     NSTimeInterval _startDL;
     NSTimeInterval _lastStatsUpdate;
+
+    UINavigationController *_lastKnownNavigationController;
 }
 
 @end
@@ -50,6 +53,10 @@
     dispatch_once(&pred, ^{
         sharedInstance = [VLCDropboxController new];
         [sharedInstance shareCredentials];
+
+        DBSession* dbSession = [[DBSession alloc] initWithAppKey:kVLCDropboxAppKey appSecret:kVLCDropboxPrivateKey root:kDBRootDropbox];
+        [DBSession setSharedSession:dbSession];
+        [DBRequest setNetworkRequestDelegate:sharedInstance];
     });
 
     return sharedInstance;
@@ -123,10 +130,12 @@
     }
 }
 
-- (void)streamFile:(DBMetadata *)file
+- (void)streamFile:(DBMetadata *)file currentNavigationController:(UINavigationController *)navigationController
 {
-    if (!file.isDirectory)
+    if (!file.isDirectory) {
+        _lastKnownNavigationController = navigationController;
         [[self restClient] loadStreamableURLForFile:file.path];
+    }
 }
 
 - (void)_triggerNextDownload
@@ -229,6 +238,14 @@
 {
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
     [vpc playURL:url successCallback:nil errorCallback:nil];
+#if TARGET_OS_TV
+    if (_lastKnownNavigationController) {
+        VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
+        [_lastKnownNavigationController presentViewController:movieVC
+                                                     animated:YES
+                                                   completion:nil];
+    }
+#endif
 }
 
 - (void)restClient:(DBRestClient*)restClient loadStreamableURLFailedWithError:(NSError*)error
@@ -328,4 +345,10 @@
 #endif
 }
 
+- (void)reset
+{
+    [_restClient cancelAllRequests];
+    _currentFileList = nil;
+}
+
 @end

+ 2 - 0
Sources/VLCDropboxTableViewController.h

@@ -25,6 +25,8 @@
 
 @interface VLCDropboxTableViewController : VLCCloudStorageTVTableViewController
 
+- (instancetype)initWithPath:(NSString *)path;
+
 @end
 
 #endif

+ 41 - 14
Sources/VLCDropboxTableViewController.m

@@ -16,7 +16,6 @@
 
 #import "VLCDropboxTableViewController.h"
 #import "VLCDropboxController.h"
-#import "VLCDropboxConstants.h"
 #import "VLCCloudStorageTableViewCell.h"
 #import "UIDevice+VLC.h"
 #import "DBKeychain.h"
@@ -29,12 +28,23 @@
 {
     VLCDropboxController *_dropboxController;
     DBMetadata *_selectedFile;
+    NSArray *_mediaList;
 }
 
 @end
 
 @implementation VLCDropboxTableViewController
 
+- (instancetype)initWithPath:(NSString *)path
+{
+    NSLog(@"%s", __PRETTY_FUNCTION__);
+    self = [super init];
+    if (self) {
+        self.currentPath = path;
+    }
+    return self;
+}
+
 - (void)dealloc
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
@@ -53,19 +63,15 @@
                                              selector:@selector(sessionWasUpdated:)
                                                  name:VLCDropboxSessionWasAuthorized
                                                object:nil];
-#endif
-
-    DBSession* dbSession = [[DBSession alloc] initWithAppKey:kVLCDropboxAppKey appSecret:kVLCDropboxPrivateKey root:kDBRootDropbox];
-    [DBSession setSharedSession:dbSession];
-    [DBRequest setNetworkRequestDelegate:_dropboxController];
 
     self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dropbox-white"]];
 
-#if TARGET_OS_IOS
     [self.cloudStorageLogo setImage:[UIImage imageNamed:@"dropbox-white.png"]];
 
     [self.cloudStorageLogo sizeToFit];
     self.cloudStorageLogo.center = self.view.center;
+#else
+    self.title = @"Dropbox";
 #endif
 }
 
@@ -73,9 +79,12 @@
 {
     [super viewWillAppear:animated];
 
-    self.controller = _dropboxController;
+    self.controller = [VLCDropboxController sharedInstance];
     self.controller.delegate = self;
 
+    if (self.currentPath != nil)
+        self.title = self.currentPath.lastPathComponent;
+
     [self updateViewAfterSessionChange];
 }
 
@@ -99,23 +108,41 @@
     if (cell == nil)
         cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier];
 
-    cell.dropboxFile = _dropboxController.currentListFiles[indexPath.row];
-    cell.delegate = self;
+    NSUInteger index = indexPath.row;
+    if (_mediaList) {
+        if (index < _mediaList.count) {
+            cell.dropboxFile = _mediaList[index];
+            cell.delegate = self;
+        }
+    }
 
     return cell;
 }
 
+- (void)mediaListUpdated
+{
+    _mediaList = [self.controller.currentListFiles copy];
+    [self.tableView reloadData];
+}
+
 #pragma mark - Table view delegate
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    _selectedFile = _dropboxController.currentListFiles[indexPath.row];
+    _selectedFile = _mediaList[indexPath.row];
     if (!_selectedFile.isDirectory)
-        [_dropboxController streamFile:_selectedFile];
+        [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
     else {
         /* dive into subdirectory */
-        self.currentPath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.filename];
+        NSString *futurePath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.filename];
+#if TARGET_OS_TV
+        [_dropboxController reset];
+        VLCDropboxTableViewController *targetViewController = [[VLCDropboxTableViewController alloc] initWithPath:futurePath];
+        [self.navigationController pushViewController:targetViewController animated:YES];
+#else
+        self.currentPath = futurePath;
         [self requestInformationForCurrentPath];
+#endif
     }
     _selectedFile = nil;
 
@@ -146,7 +173,7 @@
 #if TARGET_OS_IOS
 - (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
 {
-    _selectedFile = _dropboxController.currentListFiles[[self.tableView indexPathForCell:cell].row];
+    _selectedFile = _mediaList[[self.tableView indexPathForCell:cell].row];
 
     if (_selectedFile.totalBytes < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
         /* selected item is a proper file, ask the user if s/he wants to download it */

+ 2 - 7
VLC for Apple TV/VLCCloudServicesTVViewController.m

@@ -25,10 +25,6 @@
     VLCOneDriveController *_oneDriveController;
     VLCBoxController *_boxController;
 }
-
-@property (nonatomic) VLCDropboxTableViewController *dropboxTableViewController;
-@property (nonatomic) VLCBoxTableViewController *boxTableViewController;
-
 @end
 
 @implementation VLCCloudServicesTVViewController
@@ -44,8 +40,6 @@
     _boxController = [VLCBoxController sharedInstance];
     [_boxController startSession];
 
-    self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:nil bundle:nil];
-
     self.dropboxButton.enabled = self.gDriveButton.enabled = NO;
     [self oneDriveSessionUpdated:nil];
     [self boxSessionUpdated:nil];
@@ -65,7 +59,8 @@
 
 - (IBAction)dropbox:(id)sender
 {
-    [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
+    VLCDropboxTableViewController *targetViewController = [[VLCDropboxTableViewController alloc] initWithPath:nil];
+    [self.navigationController pushViewController:targetViewController animated:YES];
 }
 
 - (void)updateDropbox