Commit 6ba6675a authored by Felix Paul Kühne's avatar Felix Paul Kühne

Box: switch to collection view based layout

parent 8583446b
......@@ -17,7 +17,7 @@
#import "VLCPlayerDisplayController.h"
#import "VLCOneDriveController.h"
#import "VLCOneDriveCollectionViewController.h"
#import "VLCBoxTableViewController.h"
#import "VLCBoxCollectionViewController.h"
#import "VLCBoxController.h"
#import "MetaDataFetcherKit.h"
......@@ -96,7 +96,7 @@
- (IBAction)box:(id)sender
{
VLCBoxTableViewController *targetViewController = [[VLCBoxTableViewController alloc] initWithPath:@""];
VLCBoxCollectionViewController *targetViewController = [[VLCBoxCollectionViewController alloc] initWithPath:@""];
[self.navigationController pushViewController:targetViewController animated:YES];
}
......
/*****************************************************************************
* VLCBoxCollectionViewController.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014-2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCCloudStorageTVViewController.h"
@interface VLCBoxCollectionViewController : VLCCloudStorageTVViewController
- (instancetype)initWithPath:(NSString *)path;
@end
/*****************************************************************************
* VLCBoxCollectionViewController.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014-2015 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
* Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCBoxCollectionViewController.h"
#import "VLCBoxController.h"
#import <SSKeychain/SSKeychain.h>
#import "VLCPlaybackController.h"
@interface VLCBoxCollectionViewController () <VLCCloudStorageDelegate, NSURLConnectionDataDelegate>
{
BoxFile *_selectedFile;
VLCBoxController *_boxController;
NSArray *_listOfFiles;
}
@end
@implementation VLCBoxCollectionViewController
- (instancetype)initWithPath:(NSString *)path
{
self = [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
if (self) {
self.currentPath = path;
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
[super viewDidLoad];
_boxController = [VLCBoxController sharedInstance];
self.controller = _boxController;
self.controller.delegate = self;
self.title = @"Box";
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(boxApiTokenDidRefresh)
name:BoxOAuth2SessionDidRefreshTokensNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[defaultCenter addObserver:self
selector:@selector(boxApiTokenDidRefresh)
name:BoxOAuth2SessionDidBecomeAuthenticatedNotification
object:[BoxSDK sharedSDK].OAuth2Session];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
_boxController = [VLCBoxController sharedInstance];
self.controller = _boxController;
self.controller.delegate = self;
if (!_listOfFiles || _listOfFiles.count == 0)
[self requestInformationForCurrentPath];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if ([UIApplication sharedApplication].delegate.window.rootViewController.presentedViewController == nil) {
[_boxController stopSession];
[self.collectionView reloadData];
}
}
- (void)mediaListUpdated
{
_listOfFiles = [[VLCBoxController sharedInstance].currentListFiles copy];
[self.collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCCloudStorageCollectionViewCell *cell = (VLCCloudStorageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
NSUInteger index = indexPath.row;
if (_listOfFiles) {
if (index < _listOfFiles.count) {
cell.boxFile = _listOfFiles[index];
}
}
return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _listOfFiles.count;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row >= _listOfFiles.count)
return;
_selectedFile = _listOfFiles[indexPath.row];
if (![_selectedFile.type isEqualToString:@"folder"])
[self streamFile:(BoxFile *)_selectedFile];
else {
/* dive into subdirectory */
NSString *path = self.currentPath;
if (![path isEqualToString:@""])
path = [path stringByAppendingString:@"/"];
path = [path stringByAppendingString:_selectedFile.modelID];
VLCBoxCollectionViewController *targetViewController = [[VLCBoxCollectionViewController alloc] initWithPath:path];
[self.navigationController pushViewController:targetViewController animated:YES];
}
}
- (void)streamFile:(BoxFile *)file
{
/* the Box API requires us to set an HTTP header to get the actual URL:
* curl -L https://api.box.com/2.0/files/FILE_ID/content -H "Authorization: Bearer ACCESS_TOKEN"
*
* ... however, libvlc does not support setting custom HTTP headers, so we are resolving the redirect ourselves with a NSURLConnection
* and pass the final location to libvlc, which does not require a custom HTTP header */
NSURL *baseURL = [[[BoxSDK sharedSDK] filesManager] URLWithResource:@"files"
ID:file.modelID
subresource:@"content"
subID:nil];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:baseURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];
[urlRequest setValue:[NSString stringWithFormat:@"Bearer %@", [BoxSDK sharedSDK].OAuth2Session.accessToken] forHTTPHeaderField:@"Authorization"];
NSURLConnection *theTestConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
[theTestConnection start];
}
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response
{
if (response != nil) {
/* we have 1 redirect from the original URL, so as soon as we'd do that,
* we grab the URL and cancel the connection */
NSURL *theActualURL = request.URL;
[connection cancel];
/* now ask VLC to stream the URL we were just passed */
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:theActualURL successCallback:nil errorCallback:nil];
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
[self presentViewController:movieVC
animated:YES
completion:nil];
}
return request;
}
#pragma mark - BoxAuthorizationViewControllerDelegate
- (void)boxApiTokenDidRefresh
{
NSString *token = [BoxSDK sharedSDK].OAuth2Session.refreshToken;
[SSKeychain setPassword:token forService:kVLCBoxService account:kVLCBoxAccount];
NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
[ubiquitousStore setString:token forKey:kVLCStoreBoxCredentials];
[ubiquitousStore synchronize];
self.authorizationInProgress = YES;
[self updateViewAfterSessionChange];
self.authorizationInProgress = NO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger currentOffset = scrollView.contentOffset.y;
NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (_boxController.hasMoreFiles && !self.activityIndicator.isAnimating) {
[self requestInformationForCurrentPath];
}
}
@end
......@@ -61,7 +61,6 @@
[self.collectionView reloadData];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCCloudStorageCollectionViewCell *cell = (VLCCloudStorageCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
......
......@@ -41,6 +41,11 @@
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad
{
[super viewDidLoad];
......
......@@ -220,6 +220,7 @@
7DF383C41BF2329500D71A5C /* VLCDropboxCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF383C31BF2329500D71A5C /* VLCDropboxCollectionViewController.m */; };
7DF383C71BF23AC000D71A5C /* VLCCloudStorageCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF383C61BF23AC000D71A5C /* VLCCloudStorageCollectionViewCell.m */; };
7DF383CB1BF2498800D71A5C /* VLCOneDriveCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF383CA1BF2498800D71A5C /* VLCOneDriveCollectionViewController.m */; };
7DF383D01BF24BB100D71A5C /* VLCBoxCollectionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF383CF1BF24BB100D71A5C /* VLCBoxCollectionViewController.m */; };
7DF7CA0717650C2A00C61739 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DF7CA0617650C2A00C61739 /* AVFoundation.framework */; };
7DF7E791175F47DC0018858D /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DF7E790175F47DC0018858D /* MediaPlayer.framework */; };
7DF90B441BE7A5380059C0E3 /* VLCSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF90B431BE7A5380059C0E3 /* VLCSettingsTableViewController.m */; };
......@@ -811,6 +812,8 @@
7DF383C61BF23AC000D71A5C /* VLCCloudStorageCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCCloudStorageCollectionViewCell.m; path = SharedSources/Clouds/VLCCloudStorageCollectionViewCell.m; sourceTree = "<group>"; };
7DF383C91BF2498800D71A5C /* VLCOneDriveCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCOneDriveCollectionViewController.h; path = SharedSources/Clouds/VLCOneDriveCollectionViewController.h; sourceTree = SOURCE_ROOT; };
7DF383CA1BF2498800D71A5C /* VLCOneDriveCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCOneDriveCollectionViewController.m; path = SharedSources/Clouds/VLCOneDriveCollectionViewController.m; sourceTree = SOURCE_ROOT; };
7DF383CE1BF24BB100D71A5C /* VLCBoxCollectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCBoxCollectionViewController.h; path = SharedSources/Clouds/VLCBoxCollectionViewController.h; sourceTree = SOURCE_ROOT; };
7DF383CF1BF24BB100D71A5C /* VLCBoxCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCBoxCollectionViewController.m; path = SharedSources/Clouds/VLCBoxCollectionViewController.m; sourceTree = SOURCE_ROOT; };
7DF7CA0617650C2A00C61739 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
7DF7E790175F47DC0018858D /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
7DF90B421BE7A5380059C0E3 /* VLCSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCSettingsTableViewController.h; sourceTree = "<group>"; };
......@@ -1132,6 +1135,8 @@
41CD69571A29D72600E60BCE /* VLCBoxConstants.h */,
41CD69581A29D72600E60BCE /* VLCBoxController.h */,
41CD69591A29D72600E60BCE /* VLCBoxController.m */,
7DF383CE1BF24BB100D71A5C /* VLCBoxCollectionViewController.h */,
7DF383CF1BF24BB100D71A5C /* VLCBoxCollectionViewController.m */,
41CD695A1A29D72600E60BCE /* VLCBoxTableViewController.h */,
41CD695B1A29D72600E60BCE /* VLCBoxTableViewController.m */,
);
......@@ -2692,6 +2697,7 @@
DD490B1F1BE95B5C0010F335 /* VLCSiriRemoteGestureRecognizer.m in Sources */,
DD3EFF3C1BDEBCE500B68579 /* VLCNetworkServerBrowserVLCMedia.m in Sources */,
7D1334801BE132F10012E919 /* VLCNetworkServerBrowserUPnP.m in Sources */,
7DF383D01BF24BB100D71A5C /* VLCBoxCollectionViewController.m in Sources */,
DDEAECC71BDEC79D00756C83 /* VLCLocalNetworkServiceBrowserSAP.m in Sources */,
7D1329441BA1F10100BE647E /* AppleTVAppDelegate.m in Sources */,
7D1329411BA1F10100BE647E /* main.m in Sources */,
......
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