Skip to content

Commit f443cc4

Browse files
EshanSingh-ESfkuehne
authored andcommitted
Cloud Services: Support for downloadingFolders
1 parent 836a925 commit f443cc4

File tree

9 files changed

+197
-76
lines changed

9 files changed

+197
-76
lines changed

Resources/iOS/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
<string>GoogleAuth</string>
246246
<key>CFBundleURLSchemes</key>
247247
<array>
248-
<string>com.googleusercontent.apps.CLIENT</string>
248+
<string>com.googleusercontent.apps.1014939615316-3pbavebokl0smjlr0r03uqqjha0ie3l7</string>
249249
</array>
250250
</dict>
251251
</array>

Sources/Cloud/Content List/Cells/VLCCloudStorageTableViewCell.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ - (void)_updatedDisplayedInformation
158158
self.folderTitleLabel.text = self.dropboxFile.name;
159159
self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
160160
self.folderTitleLabel.hidden = NO;
161-
self.downloadButton.hidden = YES;
161+
self.downloadButton.hidden = NO;
162162
self.isFavourable = YES;
163163

164164
VLCFavoriteService *service = [VLCAppCoordinator sharedInstance].favoriteService;
@@ -167,8 +167,8 @@ - (void)_updatedDisplayedInformation
167167
NSString *urlString = [NSString stringWithFormat:@"file://DropBox/%@", selectedFilePath];
168168
NSURL *url = [NSURL URLWithString:urlString];
169169
self.isFavourite = [service isFavoriteURL:url];
170-
171170
self.thumbnailView.image = [UIImage imageNamed:@"folder"];
171+
172172
} else if ([_dropboxFile isKindOfClass:[DBFILESFileMetadata class]]) {
173173
DBFILESFileMetadata *file = (DBFILESFileMetadata *)_dropboxFile;
174174
self.titleLabel.text = file.name;
@@ -229,6 +229,7 @@ - (void)_updatedDisplayedInformation
229229
self.folderTitleLabel.text = self.boxFile.name;
230230
self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
231231
self.folderTitleLabel.hidden = NO;
232+
<<<<<<< HEAD
232233
self.downloadButton.hidden = YES;
233234
self.isFavourable = YES;
234235

@@ -239,6 +240,9 @@ - (void)_updatedDisplayedInformation
239240
NSURL *url = [NSURL URLWithString:urlString];
240241

241242
self.isFavourite = [service isFavoriteURL:url];
243+
=======
244+
self.downloadButton.hidden = NO;
245+
>>>>>>> 4af7124fe (Cloud Services: Support for downloadingFolders)
242246
} else {
243247
NSString *title = self.boxFile.name;
244248
self.titleLabel.text = title;

Sources/Cloud/Services/Box/VLCBoxController.m

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ @interface VLCBoxController ()
2323
BoxAPIJSONOperation *_operation;
2424

2525
NSArray *_currentFileList;
26-
26+
NSArray *_folderFileList;
27+
2728
NSMutableArray *_listOfBoxFilesToDownload;
2829
BOOL _downloadInProgress;
2930

@@ -134,7 +135,7 @@ - (void)requestDirectoryListingAtPath:(NSString *)path
134135
//we entered a different folder so discard all current files
135136
if (![path isEqualToString:_folderId])
136137
_currentFileList = nil;
137-
[self listFilesWithID:path];
138+
[self listFilesWithID:path: NO];
138139
}
139140

140141
- (BOOL)hasMoreFiles
@@ -149,7 +150,7 @@ - (void)getFolderInformation
149150
BoxFolder *folder = collection.parent;
150151
NSString *parentId = folder.modelID;
151152
self->_currentFileList = nil;
152-
[self listFilesWithID:parentId];
153+
[self listFilesWithID:parentId: NO];
153154
[self.delegate updateCurrentPath:parentId];
154155
};
155156

@@ -162,7 +163,7 @@ - (void)getFolderInformation
162163
_operation = [[BoxSDK sharedSDK].foldersManager folderInfoWithID:_folderId requestBuilder:nil success:success failure:failure];
163164
}
164165

165-
- (void)listFilesWithID:(NSString *)folderId
166+
- (void)listFilesWithID:(NSString *)folderId : (BOOL)isDownloadingFolder
166167
{
167168
_fileList = nil;
168169
_folderId = folderId;
@@ -173,7 +174,11 @@ - (void)listFilesWithID:(NSString *)folderId
173174
BoxCollectionBlock success = ^(BoxCollection *collection)
174175
{
175176
self->_fileList = collection;
176-
[self _listOfGoodFilesAndFolders];
177+
if (isDownloadingFolder) {
178+
[self _listOfGoodFilesAndFolders: YES];
179+
} else {
180+
[self _listOfGoodFilesAndFolders: NO];
181+
}
177182
};
178183

179184
BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
@@ -187,15 +192,23 @@ - (void)listFilesWithID:(NSString *)folderId
187192

188193
- (void)downloadFileToDocumentFolder:(BoxItem *)file
189194
{
190-
if (file != nil) {
191-
if ([file.type isEqualToString:BoxAPIItemTypeFolder]) return;
192-
193-
if (!_listOfBoxFilesToDownload)
194-
_listOfBoxFilesToDownload = [NSMutableArray new];
195-
196-
[_listOfBoxFilesToDownload addObject:file];
195+
if (file != nil) {
196+
if ([file.type isEqualToString:BoxAPIItemTypeFolder]) {
197+
198+
[self listFilesWithID: file.modelID: YES];
199+
} else {
200+
[self queueDownloads:file];
201+
}
197202
}
203+
}
204+
205+
-(void)queueDownloads:(BoxItem *)file
206+
{
207+
if (!_listOfBoxFilesToDownload)
208+
_listOfBoxFilesToDownload = [NSMutableArray new];
198209

210+
[_listOfBoxFilesToDownload addObject:file];
211+
199212
if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
200213
[self.delegate numberOfFilesWaitingToBeDownloadedChanged];
201214

@@ -230,7 +243,7 @@ - (void)_reallyDownloadFileToDocumentFolder:(BoxFile *)file
230243
//just pick out Directories and supported formats.
231244
//if the resulting list contains less than 10 items try to get more
232245

233-
- (void)_listOfGoodFilesAndFolders
246+
- (void)_listOfGoodFilesAndFolders: (BOOL)isDownloadingFolder
234247
{
235248
NSMutableArray *listOfGoodFilesAndFolders = [NSMutableArray new];
236249
_maxOffset = _fileList.totalCount.intValue;
@@ -246,26 +259,45 @@ - (void)_listOfGoodFilesAndFolders
246259
BoxFile * file = (BoxFile *)boxFile;
247260
supportedFile = [[NSString stringWithFormat:@".%@",file.name.lastPathComponent] isSupportedFormat];
248261
}
249-
250-
if (isDirectory || supportedFile)
251-
[listOfGoodFilesAndFolders addObject:boxFile];
262+
if (isDownloadingFolder) {
263+
if (supportedFile)
264+
[listOfGoodFilesAndFolders addObject:boxFile];
265+
} else {
266+
if (isDirectory || supportedFile)
267+
[listOfGoodFilesAndFolders addObject:boxFile];
268+
}
269+
252270
}
253-
_currentFileList = [_currentFileList count] ? [_currentFileList arrayByAddingObjectsFromArray:listOfGoodFilesAndFolders] : [NSArray arrayWithArray:listOfGoodFilesAndFolders];
254-
255-
if ([_currentFileList count] <= 10 && [self hasMoreFiles]) {
256-
[self listFilesWithID:_folderId];
257-
return;
271+
272+
if (isDownloadingFolder) {
273+
_folderFileList = [_folderFileList count] ? [_folderFileList arrayByAddingObjectsFromArray:listOfGoodFilesAndFolders] : [NSArray arrayWithArray:listOfGoodFilesAndFolders];
274+
275+
if ([_folderFileList count] <= 10 && [self hasMoreFiles]) {
276+
[self listFilesWithID:_folderId: isDownloadingFolder];
277+
return;
278+
}
279+
for (BoxItem *file in _folderFileList) {
280+
[self queueDownloads:file];
281+
}
282+
_folderFileList = nil;
283+
} else {
284+
_currentFileList = [_currentFileList count] ? [_currentFileList arrayByAddingObjectsFromArray:listOfGoodFilesAndFolders] : [NSArray arrayWithArray:listOfGoodFilesAndFolders];
285+
286+
if ([_currentFileList count] <= 10 && [self hasMoreFiles]) {
287+
[self listFilesWithID:_folderId: isDownloadingFolder];
288+
return;
289+
}
290+
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
291+
[self.delegate mediaListUpdated];
292+
293+
APLog(@"found filtered metadata for %lu files", (unsigned long)_currentFileList.count);
258294
}
259-
260-
APLog(@"found filtered metadata for %lu files", (unsigned long)_currentFileList.count);
261-
262-
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
263-
[self.delegate mediaListUpdated];
264295
}
265296

266297
- (void)loadFile:(BoxFile *)file intoPath:(NSString*)destinationPath
267298
{
268299
NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:destinationPath append:NO];
300+
269301
_startDL = [NSDate timeIntervalSinceReferenceDate];
270302
BoxDownloadSuccessBlock successBlock = ^(NSString *downloadedFileID, long long expectedContentLength)
271303
{

Sources/Cloud/Services/Dropbox/VLCDropboxController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- (BOOL)restoreFromSharedCredentials;
2424

2525
- (void)downloadFileToDocumentFolder:(DBFILESMetadata *)file;
26+
-(void)downloadFolderFiles:(DBFILESFolderMetadata *)folder;
2627
- (void)streamFile:(DBFILESMetadata *)file currentNavigationController:(UINavigationController *)navigationController;
2728

2829
- (void)reset;

Sources/Cloud/Services/Dropbox/VLCDropboxController.m

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
99
* Jean-Baptiste Kempf <jb # videolan.org>
10-
*
10+
* Eshan Singh <[email protected]>
1111
* Refer to the COPYING file of the official project for license.
1212
*****************************************************************************/
1313

@@ -26,7 +26,7 @@ @interface VLCDropboxController ()
2626

2727
@property (strong, nonatomic) DBUserClient *client;
2828
@property (strong, nonatomic) NSArray *currentFileList;
29-
29+
@property (strong, nonatomic) NSArray *folderFileList;
3030
@property (strong, nonatomic) NSMutableArray *listOfDropboxFilesToDownload;
3131
@property (assign, nonatomic) BOOL downloadInProgress;
3232

@@ -125,7 +125,14 @@ - (BOOL)canPlayAll
125125
- (void)requestDirectoryListingAtPath:(NSString *)path
126126
{
127127
if (self.isAuthorized) {
128-
[self listFiles:path];
128+
[self listFiles: path : NO];
129+
}
130+
}
131+
132+
-(void)downloadFolderFiles:(DBFILESFolderMetadata *)folder
133+
{
134+
if ([folder isKindOfClass:[DBFILESFolderMetadata class]]) {
135+
[self listFiles: folder.pathLower :YES];
129136
}
130137
}
131138

@@ -182,37 +189,57 @@ - (void)streamFile:(DBFILESMetadata *)file currentNavigationController:(UINaviga
182189

183190
# pragma mark - Dropbox API Request
184191

185-
- (void)listFolderContinueWithClient:(DBUserClient *)client cursor:(NSString *)cursor list:(NSMutableArray *)list {
192+
- (void)listFolderContinueWithClient:(DBUserClient *)client cursor:(NSString *)cursor list:(NSMutableArray *)list : (BOOL)downloadingFolder {
186193
[[[self client].filesRoutes listFolderContinue:cursor]
187194
setResponseBlock:^(DBFILESListFolderResult *response, DBFILESListFolderContinueError *routeError,
188195
DBRequestError *networkError) {
189196
if (response) {
190197
[list addObjectsFromArray:response.entries];
191198
if ([response.hasMore boolValue]) {
192-
[self listFolderContinueWithClient:client cursor:response.cursor list:list];
199+
if (downloadingFolder) {
200+
[self listFolderContinueWithClient: client cursor:response.cursor list:list: downloadingFolder];
201+
}
193202
} else {
194-
[self sendMediaListUpdatedWithList:list];
203+
if (downloadingFolder) {
204+
[self sendMediaListUpdatedWithList:list :YES];
205+
} else {
206+
[self sendMediaListUpdatedWithList:list: NO];
207+
}
195208
}
196209
} else {
197210
NSLog(@"%@\n%@\n", routeError, networkError);
198211
}
199212
}];
200213
}
201214

202-
- (void)sendMediaListUpdatedWithList:(NSArray *)list
215+
- (void)sendMediaListUpdatedWithList:(NSArray *)list : (BOOL)downloadingFolder
203216
{
204-
self.currentFileList = [[list sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
205-
NSString *first = [(DBFILESMetadata*)a name];
206-
NSString *second = [(DBFILESMetadata*)b name];
207-
return [first caseInsensitiveCompare:second];
208-
}] copy];
209-
APLog(@"found filtered metadata for %lu files", (unsigned long)self.currentFileList.count);
210-
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)]) {
211-
[self.delegate mediaListUpdated];
217+
if (downloadingFolder) {
218+
self.folderFileList = [[list sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
219+
NSString *first = [(DBFILESMetadata*)a name];
220+
NSString *second = [(DBFILESMetadata*)b name];
221+
return [first caseInsensitiveCompare:second];
222+
}] copy];
223+
for (DBFILESMetadata *file in self.folderFileList) {
224+
if ([file isKindOfClass:[DBFILESFileMetadata class]]) {
225+
[self downloadFileToDocumentFolder:file];
226+
}
227+
}
228+
self.folderFileList = nil;
229+
} else {
230+
self.currentFileList = [[list sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
231+
NSString *first = [(DBFILESMetadata*)a name];
232+
NSString *second = [(DBFILESMetadata*)b name];
233+
return [first caseInsensitiveCompare:second];
234+
}] copy];
235+
APLog(@"found filtered metadata for %lu files", (unsigned long)self.currentFileList.count);
236+
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)]) {
237+
[self.delegate mediaListUpdated];
238+
}
212239
}
213240
}
214241

215-
- (void)listFiles:(NSString *)path
242+
- (void)listFiles:(NSString *)path : (BOOL)downloadingFolder
216243
{
217244
// DropBox API prefers an empty path than a '/'
218245
if (!path || [path isEqualToString:@"/"]) {
@@ -224,9 +251,17 @@ - (void)listFiles:(NSString *)path
224251
[[[self client].filesRoutes listFolder:path] setResponseBlock:^(DBFILESListFolderResult * _Nullable result, DBFILESListFolderError * _Nullable routeError, DBRequestError * _Nullable networkError) {
225252
if (result) {
226253
if ([result.hasMore boolValue]) {
227-
[self listFolderContinueWithClient:self->_client cursor:result.cursor list:stock];
254+
if (downloadingFolder) {
255+
[self listFolderContinueWithClient:self->_client cursor:result.cursor list:stock: YES];
256+
} else {
257+
[self listFolderContinueWithClient:self->_client cursor:result.cursor list:stock: NO];
258+
}
228259
} else {
229-
[self sendMediaListUpdatedWithList:result.entries];
260+
if (downloadingFolder) {
261+
[self sendMediaListUpdatedWithList:result.entries : YES];
262+
} else {
263+
[self sendMediaListUpdatedWithList:result.entries : NO];
264+
}
230265
}
231266
} else {
232267
APLog(@"listFiles failed with network error %li and error tag %li", (long)networkError.statusCode, (long)networkError.tag);

Sources/Cloud/Services/Dropbox/VLCDropboxTableViewController.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ @interface VLCDropboxTableViewController () <VLCCloudStorageTableViewCell, VLCCl
2424
{
2525
VLCDropboxController *_dropboxController;
2626
DBFILESMetadata *_selectedFile;
27+
DBFILESFolderMetadata *_folder;
2728
NSArray *_mediaList;
2829
}
2930

@@ -156,8 +157,13 @@ - (void)sessionWasUpdated:(NSNotification *)aNotification
156157

157158
- (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
158159
{
159-
_selectedFile = _mediaList[[self.tableView indexPathForCell:cell].row];
160-
160+
161+
if ([_mediaList[[self.tableView indexPathForCell:cell].row] isKindOfClass:[DBFILESFolderMetadata class]]) {
162+
_folder = _mediaList[[self.tableView indexPathForCell:cell].row];
163+
} else {
164+
_selectedFile = _mediaList[[self.tableView indexPathForCell:cell].row];
165+
}
166+
161167
/* selected item is a proper file, ask the user if s/he wants to download it */
162168
NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
163169
style: UIAlertActionStyleCancel
@@ -166,8 +172,13 @@ - (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
166172
}],
167173
[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_DOWNLOAD", nil)
168174
action: ^(UIAlertAction *action) {
169-
[self->_dropboxController downloadFileToDocumentFolder:self->_selectedFile];
170-
self->_selectedFile = nil;
175+
if (!(self->_folder == NULL)) {
176+
[self->_dropboxController downloadFolderFiles:self->_folder];
177+
self->_folder = nil;
178+
} else {
179+
[self->_dropboxController downloadFileToDocumentFolder:self->_selectedFile];
180+
self->_selectedFile = nil;
181+
}
171182
}]
172183
];
173184
[VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)

Sources/Cloud/Services/Google Drive/VLCGoogleDriveController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
- (void)stopSession;
2323
- (void)streamFile:(GTLRDrive_File *)file;
24-
- (void)downloadFileToDocumentFolder:(GTLRDrive_File *)file;
24+
- (void)downloadFileToDocumentFolder:(GTLRDrive_File *)file : (NSString *) currentPath;
2525
- (BOOL)hasMoreFiles;
2626
- (BOOL)supportSorting;
2727
@end

0 commit comments

Comments
 (0)