Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
VLC-iOS
Commits
90b3225c
Commit
90b3225c
authored
May 02, 2014
by
Carola
Browse files
GDrive: show folder structure
parent
92515f7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Sources/VLCGoogleDriveController.h
View file @
90b3225c
...
...
@@ -39,7 +39,7 @@
-
(
void
)
startSession
;
-
(
void
)
stopSession
;
-
(
void
)
logout
;
-
(
void
)
request
FileListing
;
-
(
void
)
request
DirectoryListingWithFolderId
:(
NSString
*
)
folderId
;
-
(
BOOL
)
hasMoreFiles
;
-
(
void
)
downloadFileToDocumentFolder
:(
GTLDriveFile
*
)
file
;
...
...
Sources/VLCGoogleDriveController.m
View file @
90b3225c
...
...
@@ -27,6 +27,7 @@
BOOL
_downloadInProgress
;
NSString
*
_nextPageToken
;
NSString
*
_folderId
;
CGFloat
_averageSpeed
;
NSTimeInterval
_startDL
;
...
...
@@ -90,10 +91,14 @@
}
#pragma mark - file management
-
(
void
)
request
FileListing
-
(
void
)
request
DirectoryListingWithFolderId
:(
NSString
*
)
folderId
{
if
(
self
.
isAuthorized
)
[
self
listFiles
];
if
(
self
.
isAuthorized
)
{
//we entered a different folder so discard all current files
if
(
!
[
folderId
isEqualToString
:
_folderId
])
_currentFileList
=
nil
;
[
self
listFilesWithID
:
folderId
];
}
}
-
(
BOOL
)
hasMoreFiles
...
...
@@ -103,6 +108,8 @@
-
(
void
)
downloadFileToDocumentFolder
:(
GTLDriveFile
*
)
file
{
if
([
file
.
mimeType
isEqualToString
:
@"application/vnd.google-apps.folder"
])
return
;
if
(
!
_listOfGoogleDriveFilesToDownload
)
_listOfGoogleDriveFilesToDownload
=
[[
NSMutableArray
alloc
]
init
];
...
...
@@ -114,18 +121,18 @@
[
self
_triggerNextDownload
];
}
-
(
void
)
listFiles
-
(
void
)
listFiles
WithID
:(
NSString
*
)
folderId
{
_fileList
=
nil
;
_folderId
=
folderId
;
GTLQueryDrive
*
query
;
query
=
[
GTLQueryDrive
queryForFilesList
];
query
.
fields
=
@"items(originalFilename,title,mimeType,fileExtension,fileSize,iconLink,downloadUrl,webContentLink,thumbnailLink),nextPageToken"
;
query
.
pageToken
=
_nextPageToken
;
query
.
maxResults
=
100
;
APLog
(
@"fetching files with following queryfields:%@"
,
query
.
fields
);
if
(
!
[
_folderId
isEqualToString
:
@""
])
{
query
.
q
=
[
NSString
stringWithFormat
:
@"'%@' in parents"
,
[
_folderId
lastPathComponent
]];
}
_fileListTicket
=
[
self
.
driveService
executeQuery
:
query
completionHandler:
^
(
GTLServiceTicket
*
ticket
,
GTLDriveFileList
*
fileList
,
...
...
@@ -134,7 +141,7 @@
_fileList
=
fileList
;
_nextPageToken
=
fileList
.
nextPageToken
;
_fileListTicket
=
nil
;
[
self
_listOfGoodFiles
];
[
self
_listOfGoodFiles
AndFolders
];
}
else
{
[
self
showAlert
:
NSLocalizedString
(
@"GDRIVE_ERROR_FETCHING_FILES"
,
nil
)
message
:
error
.
localizedDescription
];
}
...
...
@@ -173,25 +180,42 @@
return
NO
;
}
-
(
void
)
_listOfGoodFiles
-
(
void
)
_listOfGoodFiles
AndFolders
{
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
]])
{
[
listOfGoodFilesAndFolders
addObject
:
driveFile
];
BOOL
inDirectory
=
NO
;
if
(
driveFile
.
parents
.
count
>
0
)
{
GTLDriveParentReference
*
parent
=
(
GTLDriveParentReference
*
)
driveFile
.
parents
[
0
];
//since there is no rootfolder display the files right away
if
(
!
[
parent
.
isRoot
boolValue
])
inDirectory
=
!
[
parent
.
identifier
isEqualToString
:[
_folderId
lastPathComponent
]];
}
BOOL
supportedFile
=
[
self
_supportedFileExtension
:[
NSString
stringWithFormat
:
@".%@"
,
driveFile
.
fileExtension
]];
if
((
isDirectory
||
supportedFile
)
&&
!
inDirectory
)
[
listOfGoodFilesAndFolders
addObject
:
driveFile
];
}
_currentFileList
=
[
_currentFileList
count
]
?
[
_currentFileList
arrayByAddingObjectsFromArray
:
listOfGoodFilesAndFolders
]
:
[
NSArray
arrayWithArray
:
listOfGoodFilesAndFolders
];
if
([
_currentFileList
count
]
<=
10
&&
[
self
hasMoreFiles
])
{
[
self
reque
stFile
Listing
];
[
self
li
stFile
sWithID
:
_folderId
];
return
;
}
APLog
(
@"found filtered metadata for %lu files"
,
(
unsigned
long
)
_currentFileList
.
count
);
//the files come in a chaotic order so we order alphabetically
NSArray
*
sortedArray
=
[
_currentFileList
sortedArrayUsingComparator
:
^
NSComparisonResult
(
id
a
,
id
b
)
{
NSString
*
first
=
[(
GTLDriveFile
*
)
a
title
];
NSString
*
second
=
[(
GTLDriveFile
*
)
b
title
];
return
[
first
compare
:
second
];
}];
_currentFileList
=
sortedArray
;
if
([
self
.
delegate
respondsToSelector
:
@selector
(
mediaListUpdated
)])
[
self
.
delegate
mediaListUpdated
];
}
...
...
Sources/VLCGoogleDriveTableViewController.m
View file @
90b3225c
...
...
@@ -26,6 +26,8 @@
GTLDriveFile
*
_selectedFile
;
GTMOAuth2ViewControllerTouch
*
_authController
;
NSString
*
_currentFolderId
;
UIBarButtonItem
*
_backButton
;
UIBarButtonItem
*
_backToMenuButton
;
...
...
@@ -181,12 +183,12 @@
}
}
-
(
void
)
_requestInformationFor
Files
-
(
void
)
_requestInformationFor
CurrentFolderId
{
[
_activityIndicator
startAnimating
];
[
_googleDriveController
request
FileListing
];
[
_googleDriveController
request
DirectoryListingWithFolderId
:
_currentFolderId
];
self
.
navigationItem
.
leftBarButtonItem
=
_backToMenuButton
;
self
.
navigationItem
.
leftBarButtonItem
=
!
[
_currentFolderId
isEqualToString
:
@""
]
?
_backButton
:
_backToMenuButton
;
}
#pragma mark - interface interaction
...
...
@@ -200,7 +202,11 @@
-
(
IBAction
)
goBack
:(
id
)
sender
{
[[(
VLCAppDelegate
*
)[
UIApplication
sharedApplication
].
delegate
revealController
]
toggleSidebar
:
!
[(
VLCAppDelegate
*
)[
UIApplication
sharedApplication
].
delegate
revealController
].
sidebarShowing
duration
:
kGHRevealSidebarDefaultAnimationDuration
];
if
(
!
[
_currentFolderId
isEqualToString
:
@""
]
&&
[
_currentFolderId
length
]
>
0
)
{
_currentFolderId
=
[
_currentFolderId
stringByDeletingLastPathComponent
];
[
self
_requestInformationForCurrentFolderId
];
}
else
[[(
VLCAppDelegate
*
)[
UIApplication
sharedApplication
].
delegate
revealController
]
toggleSidebar
:
!
[(
VLCAppDelegate
*
)[
UIApplication
sharedApplication
].
delegate
revealController
].
sidebarShowing
duration
:
kGHRevealSidebarDefaultAnimationDuration
];
}
#pragma mark - Table view data source
...
...
@@ -240,8 +246,17 @@
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
_selectedFile
=
_googleDriveController
.
currentListFiles
[
indexPath
.
row
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
NSLocalizedString
(
@"DROPBOX_DOWNLOAD"
,
@""
)
message
:[
NSString
stringWithFormat
:
NSLocalizedString
(
@"DROPBOX_DL_LONG"
,
@""
),
_selectedFile
.
title
,
[[
UIDevice
currentDevice
]
model
]]
delegate
:
self
cancelButtonTitle
:
NSLocalizedString
(
@"BUTTON_CANCEL"
,
@""
)
otherButtonTitles
:
NSLocalizedString
(
@"BUTTON_DOWNLOAD"
,
@""
),
nil
];
[
alert
show
];
if
(
!
[
_selectedFile
.
mimeType
isEqualToString
:
@"application/vnd.google-apps.folder"
])
{
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
NSLocalizedString
(
@"DROPBOX_DOWNLOAD"
,
@""
)
message
:[
NSString
stringWithFormat
:
NSLocalizedString
(
@"DROPBOX_DL_LONG"
,
@""
),
_selectedFile
.
title
,
[[
UIDevice
currentDevice
]
model
]]
delegate
:
self
cancelButtonTitle
:
NSLocalizedString
(
@"BUTTON_CANCEL"
,
@""
)
otherButtonTitles
:
NSLocalizedString
(
@"BUTTON_DOWNLOAD"
,
@""
),
nil
];
[
alert
show
];
}
else
{
/* dive into subdirectory */
if
(
!
[
_currentFolderId
isEqualToString
:
@""
])
_currentFolderId
=
[
_currentFolderId
stringByAppendingString
:
@"/"
];
_currentFolderId
=
[
_currentFolderId
stringByAppendingString
:
_selectedFile
.
identifier
];
[
self
_requestInformationForCurrentFolderId
];
}
_selectedFile
=
nil
;
[
self
.
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
NO
];
}
...
...
@@ -252,7 +267,7 @@
if
(
maximumOffset
-
currentOffset
<=
-
self
.
tableView
.
rowHeight
)
{
if
(
_googleDriveController
.
hasMoreFiles
&&
!
_activityIndicator
.
isAnimating
)
{
[
self
_requestInformationFor
Files
];
[
self
_requestInformationFor
CurrentFolderId
];
}
}
}
...
...
@@ -319,8 +334,9 @@
[
self
.
loginToCloudStorageView
removeFromSuperview
];
//reload if we didn't come back from streaming
_currentFolderId
=
@""
;
if
([
_googleDriveController
.
currentListFiles
count
]
==
0
)
[
self
_requestInformationFor
Files
];
[
self
_requestInformationFor
CurrentFolderId
];
}
#pragma mark - login dialog
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment