Commit 1b9a05ff authored by Carola's avatar Carola Committed by Felix Paul Kühne
Browse files

Google Drive: add data pagination and streaming



Replace single call for max 150 results with data pagination to increase performance.
Scrolling down triggers next 100 results. Added calls for streaming.
Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent a0c320bd
......@@ -38,6 +38,7 @@
- (void)startSession;
- (void)logout;
- (void)requestDirectoryListingAtPath:(NSString *)path;
- (BOOL)hasMoreFiles;
- (void)downloadFileToDocumentFolder:(GTLDriveFile *)file;
- (void)streamFile:(GTLDriveFile *)file;
......
......@@ -28,6 +28,7 @@
BOOL _downloadInProgress;
NSInteger _outstandingNetworkRequests;
NSString *_nextPageToken;
}
@end
......@@ -38,14 +39,14 @@
+ (VLCGoogleDriveController *)sharedInstance
{
static VLCGoogleDriveController *sharedInstance = nil;
static dispatch_once_t pred;
static VLCGoogleDriveController *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[self alloc] init];
});
dispatch_once(&pred, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
return sharedInstance;
}
- (void)startSession
......@@ -86,6 +87,11 @@
[self listFiles];
}
- (BOOL)hasMoreFiles
{
return _nextPageToken != nil;
}
- (void)downloadFileToDocumentFolder:(GTLDriveFile *)file
{
if (![file.mimeType isEqualToString:@"application/vnd.google-apps.folder"]) {
......@@ -107,18 +113,21 @@
GTLServiceDrive *service = self.driveService;
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.maxResults = 150;
GTLQueryDrive *query;
query.fields = @"items(originalFilename,title,mimeType,fileExtension,fileSize,iconLink,downloadUrl)";
query = [GTLQueryDrive queryForFilesList];
query.fields = @"items(originalFilename,title,mimeType,fileExtension,fileSize,iconLink,downloadUrl,webContentLink),nextPageToken";
query.pageToken = _nextPageToken;
query.maxResults = 100;
APLog(@"fetching files with following queryfields:%@", query.fields);
_fileListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFileList *fileList,
NSError *error) {
if (error == nil) {
_fileList = fileList;
_nextPageToken = fileList.nextPageToken;
_fileListFetchError = error;
_fileListTicket = nil;
[self listOfGoodFilesAndFolders];
......@@ -131,9 +140,10 @@
- (void)streamFile:(GTLDriveFile *)file
{
BOOL isDirectory = [file.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
BOOL isDirectory = [file.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
if (!isDirectory) {
// [[self restClient] loadStreamableURLForFile:file.path];
VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate openMovieFromURL:[NSURL URLWithString:file.webContentLink]];
}
}
......@@ -172,7 +182,7 @@
- (void)listOfGoodFilesAndFolders
{
NSMutableArray *listOfGoodFilesAndFolders = [[NSMutableArray alloc] init];
for (GTLDriveFile *driveFile in _fileList.items)
{
BOOL isDirectory = [driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
......@@ -180,8 +190,14 @@
[listOfGoodFilesAndFolders addObject:driveFile];
}
}
NSMutableSet *mergedSet = [NSMutableSet setWithArray:_currentFileList];
[mergedSet unionSet:[NSSet setWithArray:listOfGoodFilesAndFolders]];
_currentFileList = [mergedSet allObjects];
_currentFileList = [NSArray arrayWithArray:listOfGoodFilesAndFolders];
if ([_currentFileList count] <= 10 && [self hasMoreFiles]) {
[self requestDirectoryListingAtPath:@""];
return;
}
APLog(@"found filtered metadata for %i files", _currentFileList.count);
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
......
......@@ -228,6 +228,18 @@
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger currentOffset = scrollView.contentOffset.y;
NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (maximumOffset - currentOffset <= - self.tableView.rowHeight) {
if (_googleDriveController.hasMoreFiles && !_activityIndicator.isAnimating) {
[self _requestInformationForCurrentPath];
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
......
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