Commit 44c53541 authored by Carola Nitz's avatar Carola Nitz

added Box integration

parent 0566bf76
......@@ -11,6 +11,8 @@ pod 'PLCrashReporter', '1.2-rc5'
pod 'GHSidebarNav', '1.0.0'
pod 'InAppSettingsKit', '2.2.2'
pod 'upnpx', '1.3.0'
pod 'box-ios-sdk-v2', :git => 'https://github.com/carolanitz/box-ios-sdk-v2.git'
pod 'SSKeychain'
end
post_install do |installer_representation|
......
PODS:
- box-ios-sdk-v2 (1.2.2):
- box-ios-sdk-v2/no-arc (= 1.2.2)
- box-ios-sdk-v2/no-arc (1.2.2)
- GHSidebarNav (1.0.0)
- InAppSettingsKit (2.2.2)
- OBSlider (1.1.0)
- PLCrashReporter (1.2-rc5)
- QuincyKit (3.0.0)
- SSKeychain (1.2.2)
- upnpx (1.3.0)
DEPENDENCIES:
- box-ios-sdk-v2 (from `https://github.com/carolanitz/box-ios-sdk-v2.git`)
- GHSidebarNav (= 1.0.0)
- InAppSettingsKit (= 2.2.2)
- OBSlider (= 1.1.0)
- PLCrashReporter (= 1.2-rc5)
- QuincyKit (from `https://github.com/carolanitz/QuincyKit.git`)
- SSKeychain
- upnpx (= 1.3.0)
EXTERNAL SOURCES:
box-ios-sdk-v2:
:git: https://github.com/carolanitz/box-ios-sdk-v2.git
QuincyKit:
:git: https://github.com/carolanitz/QuincyKit.git
CHECKOUT OPTIONS:
box-ios-sdk-v2:
:commit: 5b9af5cf7ad1a19eff911b2fee6ce16dfeaeab3b
:git: https://github.com/carolanitz/box-ios-sdk-v2.git
QuincyKit:
:commit: 5e7938a2e1f3bf08c4ed9f7f1aa3c67826df3625
:git: https://github.com/carolanitz/QuincyKit.git
SPEC CHECKSUMS:
box-ios-sdk-v2: c06d3009266dc2c5c27bbb3882f1e5cf1f3c72cb
GHSidebarNav: 59f2b760cb788f8b1c50250963f5120f4525a5a1
InAppSettingsKit: cd8ffa4266fb5c4778af8bda8aa9bf08b6733fd4
OBSlider: 3536461f3dd47dfcbd0972c5aafb88aa7081fb79
PLCrashReporter: 979cd3c5bda33655f4df58fa6219d067183d7a7e
QuincyKit: 31f49bf0aa0b20fd25ba3084f617a43424b7af99
SSKeychain: cc48bd3ad24fcd9125adb9e0d23dd50b8bbd08b9
upnpx: d113ac6dc8ead563b840e6c9c9e03c10d9f4bd4b
COCOAPODS: 0.35.0
......@@ -426,6 +426,14 @@
<key>Type</key>
<string>IASKButtonSpecifier</string>
</dict>
<dict>
<key>Key</key>
<string>UnlinkBox</string>
<key>Title</key>
<string>SETTINGS_UNLINK_BOX</string>
<key>Type</key>
<string>IASKButtonSpecifier</string>
</dict>
<dict>
<key>Key</key>
<string>UnlinkOneDrive</string>
......
......@@ -182,6 +182,16 @@
<string>vlc-x-callback</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Box</string>
<key>CFBundleURLSchemes</key>
<array>
<string>boxsdk-nrjwriavk0mf8j6bhra56tyn58d5i7ci://boxsdkoauth2redirect</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>5</string>
......
......@@ -17,6 +17,7 @@
#import "VLCDropboxTableViewController.h"
#import "VLCGoogleDriveTableViewController.h"
#import "VLCOneDriveTableViewController.h"
#import "VLCBoxTableViewController.h"
#import "VLCHTTPUploaderController.h"
#import "GHRevealViewController.h"
#import "VLCMenuTableViewController.h"
......@@ -47,6 +48,7 @@
@property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController;
@property (nonatomic, readonly) VLCGoogleDriveTableViewController *googleDriveTableViewController;
@property (nonatomic, readonly) VLCOneDriveTableViewController *oneDriveTableViewController;
@property (nonatomic, readonly) VLCBoxTableViewController *boxTableViewController;
@property (nonatomic, readonly) VLCDownloadViewController *downloadViewController;
@property (nonatomic, readonly) VLCDocumentPickerController *documentPickerController;
......
......@@ -29,12 +29,14 @@
#import "VLCMenuTableViewController.h"
#import "BWQuincyManager.h"
#import "VLCAlertView.h"
#import <BoxSDK/BoxSDK.h>
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, VLCMediaFileDiscovererDelegate, BWQuincyManagerDelegate> {
PAPasscodeViewController *_passcodeLockController;
VLCDropboxTableViewController *_dropboxTableViewController;
VLCGoogleDriveTableViewController *_googleDriveTableViewController;
VLCOneDriveTableViewController *_oneDriveTableViewController;
VLCBoxTableViewController *_boxTableViewController;
VLCDownloadViewController *_downloadViewController;
VLCDocumentPickerController *_documentPickerController;
int _idleCounter;
......@@ -125,7 +127,7 @@
[self.dropboxTableViewController updateViewAfterSessionChange];
return YES;
}
[[BoxSDK sharedSDK].OAuth2Session performAuthorizationCodeGrantWithReceivedURL:url];
if (_playlistViewController && url != nil) {
APLog(@"%@ requested %@ to be opened", sourceApplication, url);
......@@ -258,6 +260,14 @@
return _oneDriveTableViewController;
}
- (VLCBoxTableViewController *)boxTableViewController
{
if (_boxTableViewController == nil)
_boxTableViewController = [[VLCBoxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
return _boxTableViewController;
}
- (VLCDownloadViewController *)downloadViewController
{
if (_downloadViewController == nil) {
......
/*****************************************************************************
* VLCBoxConstants.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#define kVLCBoxClientID @"nrjwriavk0mf8j6bhra56tyn58d5i7ci"
#warning Box app secret missing, login will fail
#define kVLCBoxClientSecret @""
#define kVLCBoxRedirectURL @"boxsdk-nrjwriavk0mf8j6bhra56tyn58d5i7ci://boxsdkoauth2redirect"
#define kVLCBoxService @"kVLCBoxService"
#define kVLCBoxAccount @"kVLCBoxAccount"
/*****************************************************************************
* VLCBoxController.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <BoxSDK/BoxSDK.h>
#import "VLCBoxConstants.h"
@protocol VLCBoxController <NSObject>
@required
- (void)mediaListUpdated;
@optional
- (void)operationWithProgressInformationStarted;
- (void)currentProgressInformation:(CGFloat)progress;
- (void)updateRemainingTime:(NSString *)time;
- (void)operationWithProgressInformationStopped;
- (void)numberOfFilesWaitingToBeDownloadedChanged;
@end
@interface VLCBoxController : NSObject
@property (nonatomic, weak) id<VLCBoxController> delegate;
@property (nonatomic, readonly) NSArray *currentListFiles;
@property (nonatomic, readwrite) BOOL isAuthorized;
+ (VLCBoxController *)sharedInstance;
- (void)startSession;
- (void)stopSession;
- (void)logout;
- (void)requestDirectoryListingWithFolderId:(NSString *)folderId;
- (BOOL)hasMoreFiles;
- (void)streamFile:(BoxFile *)file;
- (void)downloadFileToDocumentFolder:(BoxFile *)file;
@end
/*****************************************************************************
* VLCBoxController.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCBoxController.h"
#import "NSString+SupportedMedia.h"
#import "VLCAppDelegate.h"
#import <SSKeychain/SSKeychain.h>
@interface VLCBoxController ()
{
BoxCollection *_fileList;
BoxAPIJSONOperation *_operation;
NSArray *_currentFileList;
NSMutableArray *_listOfBoxFilesToDownload;
BOOL _downloadInProgress;
NSNumber *_maxOffset;
NSNumber *_offset;
NSString *_folderId;
CGFloat _averageSpeed;
NSTimeInterval _startDL;
NSTimeInterval _lastStatsUpdate;
}
@end
@implementation VLCBoxController
#pragma mark - session handling
+ (VLCBoxController *)sharedInstance
{
static VLCBoxController *sharedInstance = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [self new];
});
return sharedInstance;
}
- (void)startSession
{
[BoxSDK sharedSDK].OAuth2Session.clientID = kVLCBoxClientID;
[BoxSDK sharedSDK].OAuth2Session.clientSecret = kVLCBoxClientSecret;
NSString *token = [SSKeychain passwordForService:kVLCBoxService account:kVLCBoxAccount];
if (token != nil) {
[BoxSDK sharedSDK].OAuth2Session.refreshToken = token;
}
}
- (void)stopSession
{
[_operation cancel];
_offset = 0;
_currentFileList = nil;
}
- (void)logout
{
[SSKeychain deletePasswordForService:kVLCBoxService account:kVLCBoxAccount];
[[BoxSDK sharedSDK].OAuth2Session logout];
[self stopSession];
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
[self.delegate mediaListUpdated];
}
- (BOOL)isAuthorized
{
return [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
}
- (void)showAlert:(NSString *)title message:(NSString *)message
{
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle: title
message: message
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
}
#pragma mark - file management
- (void)requestDirectoryListingWithFolderId:(NSString *)folderId
{
//we entered a different folder so discard all current files
if (![folderId isEqualToString:_folderId])
_currentFileList = nil;
[self listFilesWithID:folderId];
}
- (BOOL)hasMoreFiles
{
return _offset < _maxOffset;
}
- (void)downloadFileToDocumentFolder:(BoxItem *)file
{
if ([file.type isEqualToString:BoxAPIItemTypeFolder]) return;
if (!_listOfBoxFilesToDownload)
_listOfBoxFilesToDownload = [NSMutableArray new];
[_listOfBoxFilesToDownload addObject:file];
if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
[self.delegate numberOfFilesWaitingToBeDownloadedChanged];
[self _triggerNextDownload];
}
- (void)listFilesWithID:(NSString *)folderId
{
_fileList = nil;
_folderId = folderId;
if (_folderId == nil || [_folderId isEqualToString:@""]) {
_folderId = BoxAPIFolderIDRoot;
}
BoxCollectionBlock success = ^(BoxCollection *collection)
{
_fileList = collection;
[self _listOfGoodFilesAndFolders];
};
BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
{
NSLog(@"there was an error getting the files but we don't show an error. this request is used to check if we need to refresh the token");
};
[_operation cancel];
_operation = [[BoxSDK sharedSDK].foldersManager folderItemsWithID:_folderId requestBuilder:nil success:success failure:failure];
}
- (void)streamFile:(BoxFile *)file
{
// VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
// NSString *token = [BoxSDK sharedSDK].OAuth2Session.accessToken;
// NSString *downloadString = [@"https://api.box.com/2.0/files/"stringByAppendingString:[NSString stringWithFormat:@"%@&access_token=%@",file.modelID, token]];
// [appDelegate openMovieFromURL:[NSURL URLWithString:downloadString]];
}
- (void)_triggerNextDownload
{
if (_listOfBoxFilesToDownload.count > 0 && !_downloadInProgress) {
[self _reallyDownloadFileToDocumentFolder:_listOfBoxFilesToDownload[0]];
[_listOfBoxFilesToDownload removeObjectAtIndex:0];
if ([self.delegate respondsToSelector:@selector(numberOfFilesWaitingToBeDownloadedChanged)])
[self.delegate numberOfFilesWaitingToBeDownloadedChanged];
}
}
- (void)_reallyDownloadFileToDocumentFolder:(BoxFile *)file
{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [searchPaths[0] stringByAppendingFormat:@"/%@", file.name];
[self loadFile:file intoPath:filePath];
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)])
[self.delegate operationWithProgressInformationStarted];
_downloadInProgress = YES;
}
- (BOOL)_supportedFileExtension:(NSString *)filename
{
if ([filename isSupportedMediaFormat] || [filename isSupportedAudioMediaFormat] || [filename isSupportedSubtitleFormat])
return YES;
return NO;
}
//just pick out Directories and suported formats.
//if the resulting list contains less than 10 items try to get more
- (void)_listOfGoodFilesAndFolders
{
NSMutableArray *listOfGoodFilesAndFolders = [NSMutableArray new];
_maxOffset = _fileList.totalCount;
_offset = [NSNumber numberWithInteger:_fileList.numberOfEntries];
for (int i = 0; i < _fileList.numberOfEntries; i++)
{
BoxModel *boxFile = [_fileList modelAtIndex:i];
BOOL isDirectory = [boxFile.type isEqualToString:BoxAPIItemTypeFolder];
BOOL supportedFile = NO;
if (!isDirectory) {
BoxFile * file = (BoxFile *)boxFile;
supportedFile = [self _supportedFileExtension:[NSString stringWithFormat:@".%@",file.name.lastPathComponent]];
}
if (isDirectory || supportedFile)
[listOfGoodFilesAndFolders addObject:boxFile];
}
_currentFileList = [_currentFileList count] ? [_currentFileList arrayByAddingObjectsFromArray:listOfGoodFilesAndFolders] : [NSArray arrayWithArray:listOfGoodFilesAndFolders];
if ([_currentFileList count] <= 10 && [self hasMoreFiles]) {
[self listFilesWithID:_folderId];
return;
}
APLog(@"found filtered metadata for %lu files", (unsigned long)_currentFileList.count);
if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
[self.delegate mediaListUpdated];
}
- (void)loadFile:(BoxFile *)file intoPath:(NSString*)destinationPath
{
NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:destinationPath append:NO];
_startDL = [NSDate timeIntervalSinceReferenceDate];
BoxDownloadSuccessBlock successBlock = ^(NSString *downloadedFileID, long long expectedContentLength)
{
[self downloadSuccessful];
};
BoxDownloadFailureBlock failureBlock = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error)
{
[self showAlert:NSLocalizedString(@"BOX_ERROR_DOWNLOADING_FILE_TITLE",nil) message:NSLocalizedString(@"BOX_ERROR_DOWNLOADING_FILE",nil)];
[self downloadFailedWithError:error];
};
BoxAPIDataProgressBlock progressBlock = ^(long long expectedTotalBytes, unsigned long long bytesReceived)
{
if ((_lastStatsUpdate > 0 && ([NSDate timeIntervalSinceReferenceDate] - _lastStatsUpdate > .5)) || _lastStatsUpdate <= 0) {
[self calculateRemainingTime:(CGFloat)bytesReceived expectedDownloadSize:(CGFloat)expectedTotalBytes];
_lastStatsUpdate = [NSDate timeIntervalSinceReferenceDate];
}
CGFloat progress = (CGFloat)bytesReceived / (CGFloat)expectedTotalBytes;
if ([self.delegate respondsToSelector:@selector(currentProgressInformation:)])
[self.delegate currentProgressInformation:progress];
};
[[BoxSDK sharedSDK].filesManager downloadFileWithID:file.modelID outputStream:outputStream requestBuilder:nil success:successBlock failure:failureBlock progress:progressBlock];
}
- (void)calculateRemainingTime:(CGFloat)receivedDataSize expectedDownloadSize:(CGFloat)expectedDownloadSize
{
CGFloat lastSpeed = receivedDataSize / ([NSDate timeIntervalSinceReferenceDate] - _startDL);
CGFloat smoothingFactor = 0.005;
_averageSpeed = isnan(_averageSpeed) ? lastSpeed : smoothingFactor * lastSpeed + (1 - smoothingFactor) * _averageSpeed;
CGFloat remainingInSeconds = (expectedDownloadSize - receivedDataSize) / _averageSpeed;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:remainingInSeconds];
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"HH:mm:ss"];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSString *remainingTime = [formatter stringFromDate:date];
if ([self.delegate respondsToSelector:@selector(updateRemainingTime:)])
[self.delegate updateRemainingTime:remainingTime];
}
- (void)downloadSuccessful
{
/* update library now that we got a file */
APLog(@"BoxFile download was successful");
VLCAppDelegate *appDelegate = (VLCAppDelegate *) [UIApplication sharedApplication].delegate;
[appDelegate performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
[self.delegate operationWithProgressInformationStopped];
_downloadInProgress = NO;
[self _triggerNextDownload];
}
- (void)downloadFailedWithError:(NSError*)error
{
APLog(@"BoxFile download failed with error %li", (long)error.code);
if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
[self.delegate operationWithProgressInformationStopped];
_downloadInProgress = NO;
[self _triggerNextDownload];
}
#pragma mark - VLC internal communication and delegate
- (NSArray *)currentListFiles
{
return _currentFileList;
}
- (NSInteger)numberOfFilesWaitingToBeDownloaded
{
if (_listOfBoxFilesToDownload)
return _listOfBoxFilesToDownload.count;
return 0;
}
@end
/*****************************************************************************
* VLCBoxTableViewController.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2013 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCCloudStorageTableViewController.h"
@interface VLCBoxTableViewController : VLCCloudStorageTableViewController
@end
/*****************************************************************************
* VLCBoxTableViewController.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCBoxTableViewController.h"
#import "VLCCloudStorageTableViewCell.h"
#import "VLCBoxController.h"
#import "VLCAppDelegate.h"
#import "VLCProgressView.h"
#import "UIBarButtonItem+Theme.h"
#import <SSKeychain/SSKeychain.h>
@interface VLCBoxTableViewController () <VLCCloudStorageTableViewCell, VLCBoxController, BoxAuthorizationViewControllerDelegate>
{
BoxFile *_selectedFile;
NSString *_currentFolderId;
UIBarButtonItem *_backButton;
UIBarButtonItem *_backToMenuButton;
UIBarButtonItem *_numberOfFilesBarButtonItem;
UIBarButtonItem *_progressBarButtonItem;
VLCProgressView *_progressView;
UIActivityIndicatorView *_activityIndicator;
BOOL _authorizationInProgress;
VLCBoxController *_boxController;
}
@end
@implementation VLCBoxTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFormSheet;
_boxController = [VLCBoxController sharedInstance];
_boxController.delegate = self;
[_boxController startSession];
_authorizationInProgress = NO;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BoxWhite"]];
self.navigationItem.titleView.contentMode = UIViewContentModeScaleAspectFit;
_backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack:)];
_backToMenuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(goBack:)];
self.navigationItem.leftBarButtonItem = _backToMenuButton;
self.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
_numberOfFilesBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), 0] style:UIBarButtonItemStylePlain target:nil action:nil];
[_numberOfFilesBarButtonItem setTitleTextAttributes:@{ UITextAttributeFont : [UIFont systemFontOfSize:11.] } forState:UIControlStateNormal];
_progressView = [VLCProgressView new];
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
[self.cloudStorageLogo setImage:[UIImage imageNamed:@"BoxWhite"]];
if (!SYSTEM_RUNS_IOS7_OR_LATER) {
self.flatLoginButton.hidden = YES;
[self.loginButton setTitle:NSLocalizedString(@"DROPBOX_LOGIN", nil) forState:UIControlStateNormal];
} else {
self.loginButton.hidden = YES;
[self.flatLoginButton setTitle:NSLocalizedString(@"DROPBOX_LOGIN", nil) forState:UIControlStateNormal];
}
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"sudHeaderBg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[self _showProgressInToolbar:NO];
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicator.hidesWhenStopped = YES;
_activityIndicator.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_activityIndicator];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_activityIndicator attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
// Handle logged in
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxApiTokenDidRefresh)
name:BoxOAuth2SessionDidRefreshTokensNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxApiTokenDidRefresh)
name:BoxOAuth2SessionDidBecomeAuthenticatedNotification
object:[BoxSDK sharedSDK].OAuth2Session];
// Handle logout
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxDidGetLoggedOut)
name:BoxOAuth2SessionDidReceiveAuthenticationErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxDidGetLoggedOut)
name:BoxOAuth2SessionDidReceiveRefreshErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxAPIAuthenticationDidFail)
name:BoxOAuth2SessionDidReceiveAuthenticationErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boxAPIInitiateLogin)
name:BoxOAuth2SessionDidReceiveRefreshErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
}
- (UIViewController *)createAuthController
{
NSURL *authorizationURL = [[BoxSDK sharedSDK].OAuth2Session authorizeURL];
BoxAuthorizationViewController *authorizationController = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:authorizationURL redirectURI:kVLCBoxRedirectURL];
authorizationController.delegate = self;
return authorizationController;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
//reload if we didn't come back from streaming
_currentFolderId = @"";
if([_boxController.currentListFiles count] == 0)
[self _requestInformationForCurrentFolderId];
[self.cloudStorageLogo sizeToFit];
self.cloudStorageLogo.center = self.view.center;
}
- (void)viewWillDisappear:(BOOL)animated
{
self.navigationController.toolbarHidden = YES;
if ((VLCAppDelegate*)[UIApplication sharedApplication].delegate.window.rootViewController.presentedViewController == nil) {
[_boxController stopSession];
[self.tableView reloadData];
}
[super viewWillDisappear:animated];
}
- (void)_showProgressInToolbar:(BOOL)value
{
if (!value)
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _numberOfFilesBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
else {
_progressView.progressBar.progress = 0.;
[self setToolbarItems:@[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], _progressBarButtonItem, [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]] animated:YES];
}
}
- (void)_requestInformationForCurrentFolderId
{
[_activityIndicator startAnimating];
[_boxController requestDirectoryListingWithFolderId:_currentFolderId];
self.navigationItem.leftBarButtonItem = ![_currentFolderId isEqualToString:@""] ? _backButton : _backToMenuButton;
}
- (IBAction)goBack:(id)sender
{
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];
}