Commit 0c959ef7 authored by Felix Paul Kühne's avatar Felix Paul Kühne

dropbox: rework to navigate correctly on ATV

parent 62d18f1e
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
- (BOOL)restoreFromSharedCredentials; - (BOOL)restoreFromSharedCredentials;
- (void)downloadFileToDocumentFolder:(DBMetadata *)file; - (void)downloadFileToDocumentFolder:(DBMetadata *)file;
- (void)streamFile:(DBMetadata *)file; - (void)streamFile:(DBMetadata *)file currentNavigationController:(UINavigationController *)navigationController;
- (void)reset;
@end @end
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#import "VLCMediaFileDiscoverer.h" #import "VLCMediaFileDiscoverer.h"
#endif #endif
#import "DBKeychain.h" #import "DBKeychain.h"
#import "VLCDropboxConstants.h"
@interface VLCDropboxController () @interface VLCDropboxController ()
{ {
...@@ -34,6 +35,8 @@ ...@@ -34,6 +35,8 @@
CGFloat _fileSize; CGFloat _fileSize;
NSTimeInterval _startDL; NSTimeInterval _startDL;
NSTimeInterval _lastStatsUpdate; NSTimeInterval _lastStatsUpdate;
UINavigationController *_lastKnownNavigationController;
} }
@end @end
...@@ -50,6 +53,10 @@ ...@@ -50,6 +53,10 @@
dispatch_once(&pred, ^{ dispatch_once(&pred, ^{
sharedInstance = [VLCDropboxController new]; sharedInstance = [VLCDropboxController new];
[sharedInstance shareCredentials]; [sharedInstance shareCredentials];
DBSession* dbSession = [[DBSession alloc] initWithAppKey:kVLCDropboxAppKey appSecret:kVLCDropboxPrivateKey root:kDBRootDropbox];
[DBSession setSharedSession:dbSession];
[DBRequest setNetworkRequestDelegate:sharedInstance];
}); });
return sharedInstance; return sharedInstance;
...@@ -123,10 +130,12 @@ ...@@ -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]; [[self restClient] loadStreamableURLForFile:file.path];
}
} }
- (void)_triggerNextDownload - (void)_triggerNextDownload
...@@ -229,6 +238,14 @@ ...@@ -229,6 +238,14 @@
{ {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:url successCallback:nil errorCallback:nil]; [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 - (void)restClient:(DBRestClient*)restClient loadStreamableURLFailedWithError:(NSError*)error
...@@ -328,4 +345,10 @@ ...@@ -328,4 +345,10 @@
#endif #endif
} }
- (void)reset
{
[_restClient cancelAllRequests];
_currentFileList = nil;
}
@end @end
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
@interface VLCDropboxTableViewController : VLCCloudStorageTVTableViewController @interface VLCDropboxTableViewController : VLCCloudStorageTVTableViewController
- (instancetype)initWithPath:(NSString *)path;
@end @end
#endif #endif
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#import "VLCDropboxTableViewController.h" #import "VLCDropboxTableViewController.h"
#import "VLCDropboxController.h" #import "VLCDropboxController.h"
#import "VLCDropboxConstants.h"
#import "VLCCloudStorageTableViewCell.h" #import "VLCCloudStorageTableViewCell.h"
#import "UIDevice+VLC.h" #import "UIDevice+VLC.h"
#import "DBKeychain.h" #import "DBKeychain.h"
...@@ -29,12 +28,23 @@ ...@@ -29,12 +28,23 @@
{ {
VLCDropboxController *_dropboxController; VLCDropboxController *_dropboxController;
DBMetadata *_selectedFile; DBMetadata *_selectedFile;
NSArray *_mediaList;
} }
@end @end
@implementation VLCDropboxTableViewController @implementation VLCDropboxTableViewController
- (instancetype)initWithPath:(NSString *)path
{
NSLog(@"%s", __PRETTY_FUNCTION__);
self = [super init];
if (self) {
self.currentPath = path;
}
return self;
}
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
...@@ -53,19 +63,15 @@ ...@@ -53,19 +63,15 @@
selector:@selector(sessionWasUpdated:) selector:@selector(sessionWasUpdated:)
name:VLCDropboxSessionWasAuthorized name:VLCDropboxSessionWasAuthorized
object:nil]; 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"]]; self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"dropbox-white"]];
#if TARGET_OS_IOS
[self.cloudStorageLogo setImage:[UIImage imageNamed:@"dropbox-white.png"]]; [self.cloudStorageLogo setImage:[UIImage imageNamed:@"dropbox-white.png"]];
[self.cloudStorageLogo sizeToFit]; [self.cloudStorageLogo sizeToFit];
self.cloudStorageLogo.center = self.view.center; self.cloudStorageLogo.center = self.view.center;
#else
self.title = @"Dropbox";
#endif #endif
} }
...@@ -73,9 +79,12 @@ ...@@ -73,9 +79,12 @@
{ {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
self.controller = _dropboxController; self.controller = [VLCDropboxController sharedInstance];
self.controller.delegate = self; self.controller.delegate = self;
if (self.currentPath != nil)
self.title = self.currentPath.lastPathComponent;
[self updateViewAfterSessionChange]; [self updateViewAfterSessionChange];
} }
...@@ -99,23 +108,41 @@ ...@@ -99,23 +108,41 @@
if (cell == nil) if (cell == nil)
cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier]; cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier];
cell.dropboxFile = _dropboxController.currentListFiles[indexPath.row]; NSUInteger index = indexPath.row;
cell.delegate = self; if (_mediaList) {
if (index < _mediaList.count) {
cell.dropboxFile = _mediaList[index];
cell.delegate = self;
}
}
return cell; return cell;
} }
- (void)mediaListUpdated
{
_mediaList = [self.controller.currentListFiles copy];
[self.tableView reloadData];
}
#pragma mark - Table view delegate #pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
_selectedFile = _dropboxController.currentListFiles[indexPath.row]; _selectedFile = _mediaList[indexPath.row];
if (!_selectedFile.isDirectory) if (!_selectedFile.isDirectory)
[_dropboxController streamFile:_selectedFile]; [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
else { else {
/* dive into subdirectory */ /* 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]; [self requestInformationForCurrentPath];
#endif
} }
_selectedFile = nil; _selectedFile = nil;
...@@ -146,7 +173,7 @@ ...@@ -146,7 +173,7 @@
#if TARGET_OS_IOS #if TARGET_OS_IOS
- (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell - (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) { if (_selectedFile.totalBytes < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
/* selected item is a proper file, ask the user if s/he wants to download it */ /* selected item is a proper file, ask the user if s/he wants to download it */
......
...@@ -25,10 +25,6 @@ ...@@ -25,10 +25,6 @@
VLCOneDriveController *_oneDriveController; VLCOneDriveController *_oneDriveController;
VLCBoxController *_boxController; VLCBoxController *_boxController;
} }
@property (nonatomic) VLCDropboxTableViewController *dropboxTableViewController;
@property (nonatomic) VLCBoxTableViewController *boxTableViewController;
@end @end
@implementation VLCCloudServicesTVViewController @implementation VLCCloudServicesTVViewController
...@@ -44,8 +40,6 @@ ...@@ -44,8 +40,6 @@
_boxController = [VLCBoxController sharedInstance]; _boxController = [VLCBoxController sharedInstance];
[_boxController startSession]; [_boxController startSession];
self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:nil bundle:nil];
self.dropboxButton.enabled = self.gDriveButton.enabled = NO; self.dropboxButton.enabled = self.gDriveButton.enabled = NO;
[self oneDriveSessionUpdated:nil]; [self oneDriveSessionUpdated:nil];
[self boxSessionUpdated:nil]; [self boxSessionUpdated:nil];
...@@ -65,7 +59,8 @@ ...@@ -65,7 +59,8 @@
- (IBAction)dropbox:(id)sender - (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 - (void)updateDropbox
......
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