Commit 8b031c38 authored by Carola Nitz's avatar Carola Nitz Committed by Felix Paul Kühne

Google Drive:removed folder, update files correctly

files are listed on toplevel therefore folder-related code was removed
Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent bd44312f
......@@ -36,8 +36,9 @@
+ (VLCGoogleDriveController *)sharedInstance;
- (void)startSession;
- (void)stopSession;
- (void)logout;
- (void)requestDirectoryListingAtPath:(NSString *)path;
- (void)requestFileListing;
- (BOOL)hasMoreFiles;
- (void)downloadFileToDocumentFolder:(GTLDriveFile *)file;
- (void)streamFile:(GTLDriveFile *)file;
......
......@@ -20,14 +20,12 @@
{
GTLDriveFileList *_fileList;
GTLServiceTicket *_fileListTicket;
NSError *_fileListFetchError;
NSArray *_currentFileList;
NSMutableArray *_listOfGoogleDriveFilesToDownload;
BOOL _downloadInProgress;
NSInteger _outstandingNetworkRequests;
NSString *_nextPageToken;
}
......@@ -55,11 +53,18 @@
self.driveService.authorizer = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:kVLCGoogleDriveClientID clientSecret:kVLCGoogleDriveClientSecret];
}
- (void)stopSession
{
[_fileListTicket cancelTicket];
_nextPageToken = nil;
_currentFileList = nil;
}
- (void)logout
{
[GTMOAuth2ViewControllerTouch removeAuthFromKeychainForName:kKeychainItemName];
self.driveService.authorizer = nil;
_currentFileList = 0;
_currentFileList = nil;
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
[self.delegate mediaListUpdated];
}
......@@ -81,7 +86,7 @@
}
#pragma mark - file management
- (void)requestDirectoryListingAtPath:(NSString *)path
- (void)requestFileListing
{
if (self.isAuthorized)
[self listFiles];
......@@ -94,24 +99,20 @@
- (void)downloadFileToDocumentFolder:(GTLDriveFile *)file
{
if (![file.mimeType isEqualToString:@"application/vnd.google-apps.folder"]) {
if (!_listOfGoogleDriveFilesToDownload)
_listOfGoogleDriveFilesToDownload = [[NSMutableArray alloc] init];
[_listOfGoogleDriveFilesToDownload addObject:file];
if (!_listOfGoogleDriveFilesToDownload)
_listOfGoogleDriveFilesToDownload = [[NSMutableArray alloc] init];
if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
[self.delegate numberOfFilesWaitingToBeDownloadedChanged];
[_listOfGoogleDriveFilesToDownload addObject:file];
[self _triggerNextDownload];
}
if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
[self.delegate numberOfFilesWaitingToBeDownloadedChanged];
[self _triggerNextDownload];
}
- (void)listFiles
{
_fileList = nil;
_fileListFetchError = nil;
GTLServiceDrive *service = self.driveService;
GTLQueryDrive *query;
......@@ -121,16 +122,15 @@
query.maxResults = 100;
APLog(@"fetching files with following queryfields:%@", query.fields);
_fileListTicket = [service executeQuery:query
_fileListTicket = [self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *fileList,
NSError *error) {
if (error == nil) {
_fileList = fileList;
_nextPageToken = fileList.nextPageToken;
_fileListFetchError = error;
_fileListTicket = nil;
[self listOfGoodFilesAndFolders];
[self _listOfGoodFiles];
} else {
//TODO: localize
[self showAlert:@"Fetching Files Error" message:error.localizedDescription];
......@@ -140,11 +140,8 @@
- (void)streamFile:(GTLDriveFile *)file
{
BOOL isDirectory = [file.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
if (!isDirectory) {
VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate openMovieFromURL:[NSURL URLWithString:file.webContentLink]];
}
VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate openMovieFromURL:[NSURL URLWithString:file.webContentLink]];
}
- (void)_triggerNextDownload
......@@ -179,23 +176,21 @@
return NO;
}
- (void)listOfGoodFilesAndFolders
- (void)_listOfGoodFiles
{
NSMutableArray *listOfGoodFilesAndFolders = [[NSMutableArray alloc] init];
for (GTLDriveFile *driveFile in _fileList.items)
{
BOOL isDirectory = [driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
if (isDirectory || [self _supportedFileExtension:[NSString stringWithFormat:@".%@",driveFile.fileExtension ]]) {
if (!isDirectory && [self _supportedFileExtension:[NSString stringWithFormat:@".%@",driveFile.fileExtension ]]) {
[listOfGoodFilesAndFolders addObject:driveFile];
}
}
NSMutableSet *mergedSet = [NSMutableSet setWithArray:_currentFileList];
[mergedSet unionSet:[NSSet setWithArray:listOfGoodFilesAndFolders]];
_currentFileList = [mergedSet allObjects];
_currentFileList = [_currentFileList count] ? [_currentFileList arrayByAddingObjectsFromArray:listOfGoodFilesAndFolders] : [NSArray arrayWithArray:listOfGoodFilesAndFolders];
if ([_currentFileList count] <= 10 && [self hasMoreFiles]) {
[self requestDirectoryListingAtPath:@""];
[self requestFileListing];
return;
}
......@@ -206,7 +201,6 @@
- (void)loadFile:(GTLDriveFile*)file intoPath:(NSString*)destinationPath
{
NSString *exportURLStr = file.downloadUrl;
if ([exportURLStr length] > 0) {
......
......@@ -25,8 +25,6 @@
GTLDriveFile *_selectedFile;
GTMOAuth2ViewControllerTouch *_authController;
NSString *_currentPath;
UIBarButtonItem *_backButton;
UIBarButtonItem *_backToMenuButton;
......@@ -142,6 +140,10 @@
- (void)viewWillDisappear:(BOOL)animated
{
self.navigationController.toolbarHidden = YES;
if ((VLCAppDelegate*)[UIApplication sharedApplication].delegate.window.rootViewController.presentedViewController == nil) {
[_googleDriveController stopSession];
[self.tableView reloadData];
}
[super viewWillDisappear:animated];
}
......@@ -155,12 +157,12 @@
}
}
- (void)_requestInformationForCurrentPath
- (void)_requestInformationForFiles
{
[_activityIndicator startAnimating];
[_googleDriveController requestDirectoryListingAtPath:_currentPath];
[_googleDriveController requestFileListing];
self.navigationItem.leftBarButtonItem = ![_currentPath isEqualToString:@"/"] ? _backButton : _backToMenuButton;
self.navigationItem.leftBarButtonItem = _backToMenuButton;
}
#pragma mark - interface interaction
......@@ -174,11 +176,7 @@
- (IBAction)goBack:(id)sender
{
if (![_currentPath isEqualToString:@"/"] && [_currentPath length] > 0) {
_currentPath = [_currentPath stringByDeletingLastPathComponent];
[self _requestInformationForCurrentPath];
} else
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
[[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
}
#pragma mark - Table view data source
......@@ -217,13 +215,7 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
_selectedFile = _googleDriveController.currentListFiles[indexPath.row];
if (![_selectedFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"]) {
[_googleDriveController streamFile:_selectedFile];
} else {
/* dive into subdirectory */
_currentPath = [_currentPath stringByAppendingFormat:@"/%@", _selectedFile.title];
[self _requestInformationForCurrentPath];
}
[_googleDriveController streamFile:_selectedFile];
_selectedFile = nil;
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
......@@ -235,7 +227,7 @@
if (maximumOffset - currentOffset <= - self.tableView.rowHeight) {
if (_googleDriveController.hasMoreFiles && !_activityIndicator.isAnimating) {
[self _requestInformationForCurrentPath];
[self _requestInformationForFiles];
}
}
}
......@@ -308,8 +300,9 @@
} else if (self.loginToGoogleDriveView.superview)
[self.loginToGoogleDriveView removeFromSuperview];
_currentPath = @"/";
[self _requestInformationForCurrentPath];
//reload if we didn't come back from streaming
if([_googleDriveController.currentListFiles count] == 0)
[self _requestInformationForFiles];
}
#pragma mark - login dialog
......
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