Commit e4864f01 authored by Carola Nitz's avatar Carola Nitz

cloud services: remove duplication

parent 53bb4c60
...@@ -11,33 +11,14 @@ ...@@ -11,33 +11,14 @@
*****************************************************************************/ *****************************************************************************/
#import <BoxSDK/BoxSDK.h> #import <BoxSDK/BoxSDK.h>
#import "VLCCloudStorageController.h"
#import "VLCBoxConstants.h" #import "VLCBoxConstants.h"
@protocol VLCBoxController <NSObject> @interface VLCBoxController : VLCCloudStorageController
@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)stopSession;
- (void)logout;
- (void)requestDirectoryListingWithFolderId:(NSString *)folderId;
- (BOOL)hasMoreFiles;
- (void)streamFile:(BoxFile *)file; - (void)streamFile:(BoxFile *)file;
- (void)downloadFileToDocumentFolder:(BoxFile *)file; - (void)downloadFileToDocumentFolder:(BoxFile *)file;
- (BOOL)hasMoreFiles;
@end @end
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#pragma mark - session handling #pragma mark - session handling
+ (VLCBoxController *)sharedInstance + (VLCCloudStorageController *)sharedInstance
{ {
static VLCBoxController *sharedInstance = nil; static VLCBoxController *sharedInstance = nil;
static dispatch_once_t pred; static dispatch_once_t pred;
...@@ -95,12 +95,12 @@ ...@@ -95,12 +95,12 @@
} }
#pragma mark - file management #pragma mark - file management
- (void)requestDirectoryListingWithFolderId:(NSString *)folderId - (void)requestDirectoryListingAtPath:(NSString *)path
{ {
//we entered a different folder so discard all current files //we entered a different folder so discard all current files
if (![folderId isEqualToString:_folderId]) if (![path isEqualToString:_folderId])
_currentFileList = nil; _currentFileList = nil;
[self listFilesWithID:folderId]; [self listFilesWithID:path];
} }
- (BOOL)hasMoreFiles - (BOOL)hasMoreFiles
......
...@@ -11,28 +11,13 @@ ...@@ -11,28 +11,13 @@
*****************************************************************************/ *****************************************************************************/
#import "VLCBoxTableViewController.h" #import "VLCBoxTableViewController.h"
#import "VLCCloudStorageTableViewCell.h"
#import "VLCBoxController.h" #import "VLCBoxController.h"
#import "VLCAppDelegate.h" #import "VLCAppDelegate.h"
#import "VLCProgressView.h"
#import "UIBarButtonItem+Theme.h"
#import <SSKeychain/SSKeychain.h> #import <SSKeychain/SSKeychain.h>
@interface VLCBoxTableViewController () <VLCCloudStorageTableViewCell, VLCBoxController, BoxAuthorizationViewControllerDelegate> @interface VLCBoxTableViewController () <VLCCloudStorageTableViewCell, BoxAuthorizationViewControllerDelegate>
{ {
BoxFile *_selectedFile; BoxFile *_selectedFile;
NSString *_currentFolderId;
UIBarButtonItem *_numberOfFilesBarButtonItem;
UIBarButtonItem *_logoutButton;
UIBarButtonItem *_progressBarButtonItem;
VLCProgressView *_progressView;
UIActivityIndicatorView *_activityIndicator;
BOOL _authorizationInProgress;
VLCBoxController *_boxController; VLCBoxController *_boxController;
} }
...@@ -43,54 +28,16 @@ ...@@ -43,54 +28,16 @@
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFormSheet;
_boxController = [VLCBoxController sharedInstance]; _boxController = (VLCBoxController *)[VLCBoxController sharedInstance];
_boxController.delegate = self;
[_boxController startSession]; [_boxController startSession];
self.controller = _boxController;
_authorizationInProgress = NO; self.controller.delegate = self;
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BoxWhite"]]; self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"BoxWhite"]];
self.navigationItem.titleView.contentMode = UIViewContentModeScaleAspectFit;
UIBarButtonItem *backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack:)];
self.navigationItem.leftBarButtonItem = backButton;
_logoutButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_LOGOUT", "") style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
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"]]; [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]];
[self.cloudStorageLogo sizeToFit]; [self.cloudStorageLogo sizeToFit];
self.cloudStorageLogo.center = self.view.center; self.cloudStorageLogo.center = self.view.center;
...@@ -135,58 +82,24 @@ ...@@ -135,58 +82,24 @@
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
_currentFolderId = @"";
if([_boxController.currentListFiles count] == 0)
[self _requestInformationForCurrentFolderId];
[super viewWillAppear:animated]; [super viewWillAppear:animated];
self.currentPath = @"";
if([_boxController.currentListFiles count] == 0)
[self _requestInformationForCurrentPath];
} }
- (void)viewWillDisappear:(BOOL)animated - (void)viewWillDisappear:(BOOL)animated
{ {
self.navigationController.toolbarHidden = YES; [super viewWillDisappear:animated];
if ((VLCAppDelegate*)[UIApplication sharedApplication].delegate.window.rootViewController.presentedViewController == nil) { if ((VLCAppDelegate*)[UIApplication sharedApplication].delegate.window.rootViewController.presentedViewController == nil) {
[_boxController stopSession]; [_boxController stopSession];
[self.tableView reloadData]; [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];
}
- (IBAction)goBack:(id)sender
{
if (![_currentFolderId isEqualToString:@""] && [_currentFolderId length] > 0) {
_currentFolderId = [_currentFolderId stringByDeletingLastPathComponent];
[self _requestInformationForCurrentFolderId];
} else
[self.navigationController popViewControllerAnimated:YES];
} }
#pragma mark - Table view data source #pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (VLCCloudStorageTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return _boxController.currentListFiles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
static NSString *CellIdentifier = @"BoxCell"; static NSString *CellIdentifier = @"BoxCell";
...@@ -202,11 +115,6 @@ ...@@ -202,11 +115,6 @@
#pragma mark - Table view delegate #pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ {
_selectedFile = _boxController.currentListFiles[indexPath.row]; _selectedFile = _boxController.currentListFiles[indexPath.row];
...@@ -215,10 +123,10 @@ ...@@ -215,10 +123,10 @@
[_boxController downloadFileToDocumentFolder:_selectedFile]; [_boxController downloadFileToDocumentFolder:_selectedFile];
} else { } else {
/* dive into subdirectory */ /* dive into subdirectory */
if (![_currentFolderId isEqualToString:@""]) if (![self.currentPath isEqualToString:@""])
_currentFolderId = [_currentFolderId stringByAppendingString:@"/"]; self.currentPath = [self.currentPath stringByAppendingString:@"/"];
_currentFolderId = [_currentFolderId stringByAppendingString:_selectedFile.modelID]; self.currentPath = [self.currentPath stringByAppendingString:_selectedFile.modelID];
[self _requestInformationForCurrentFolderId]; [self _requestInformationForCurrentPath];
} }
[self.tableView deselectRowAtIndexPath:indexPath animated:NO]; [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
} }
...@@ -232,17 +140,6 @@ ...@@ -232,17 +140,6 @@
[alert show]; [alert show];
} }
- (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 (_boxController.hasMoreFiles && !_activityIndicator.isAnimating) {
[self _requestInformationForCurrentFolderId];
}
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ {
...@@ -253,40 +150,6 @@ ...@@ -253,40 +150,6 @@
#pragma mark - box controller delegate #pragma mark - box controller delegate
- (void)mediaListUpdated
{
[_activityIndicator stopAnimating];
[self.tableView reloadData];
NSUInteger count = _boxController.currentListFiles.count;
if (count == 0)
_numberOfFilesBarButtonItem.title = NSLocalizedString(@"NO_FILES", nil);
else if (count != 1)
_numberOfFilesBarButtonItem.title = [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
else
_numberOfFilesBarButtonItem.title = NSLocalizedString(@"ONE_FILE", nil);
}
- (void)operationWithProgressInformationStarted
{
[self _showProgressInToolbar:YES];
}
- (void)updateRemainingTime:(NSString *)time
{
[_progressView updateTime:time];
}
- (void)currentProgressInformation:(CGFloat)progress {
[_progressView.progressBar setProgress:progress animated:YES];
}
- (void)operationWithProgressInformationStopped
{
[self _showProgressInToolbar:NO];
}
#pragma mark - BoxAuthorizationViewControllerDelegate #pragma mark - BoxAuthorizationViewControllerDelegate
- (BOOL)authorizationViewController:(BoxAuthorizationViewController *)authorizationViewController shouldLoadReceivedOAuth2RedirectRequest:(NSURLRequest *)request - (BOOL)authorizationViewController:(BoxAuthorizationViewController *)authorizationViewController shouldLoadReceivedOAuth2RedirectRequest:(NSURLRequest *)request
...@@ -315,9 +178,9 @@ ...@@ -315,9 +178,9 @@
{ {
NSString *token = [BoxSDK sharedSDK].OAuth2Session.refreshToken; NSString *token = [BoxSDK sharedSDK].OAuth2Session.refreshToken;
[SSKeychain setPassword:token forService:kVLCBoxService account:kVLCBoxAccount]; [SSKeychain setPassword:token forService:kVLCBoxService account:kVLCBoxAccount];
_authorizationInProgress = YES; self.authorizationInProgress = YES;
[self updateViewAfterSessionChange]; [self updateViewAfterSessionChange];
_authorizationInProgress = NO; self.authorizationInProgress = NO;
} }
- (void)boxAPIAuthenticationDidFail - (void)boxAPIAuthenticationDidFail
...@@ -335,48 +198,27 @@ ...@@ -335,48 +198,27 @@
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
- (void)updateViewAfterSessionChange - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{ {
self.navigationItem.rightBarButtonItem = _logoutButton; NSInteger currentOffset = scrollView.contentOffset.y;
if(_authorizationInProgress) { NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (self.loginToCloudStorageView.superview) {
[self.loginToCloudStorageView removeFromSuperview]; if (maximumOffset - currentOffset <= - self.tableView.rowHeight) {
if (_boxController.hasMoreFiles && !self.activityIndicator.isAnimating) {
[self _requestInformationForCurrentPath];
} }
return;
}
if (![_boxController isAuthorized]) {
[self _showLoginPanel];
return;
} }
//reload if we didn't come back from streaming
_currentFolderId = @"";
if([_boxController.currentListFiles count] == 0)
[self _requestInformationForCurrentFolderId];
} }
#pragma mark - login dialog #pragma mark - login dialog
- (void)_showLoginPanel
{
self.loginToCloudStorageView.frame = self.tableView.frame;
self.navigationItem.rightBarButtonItem = nil;
[self.view addSubview:self.loginToCloudStorageView];
}
- (IBAction)loginAction:(id)sender - (IBAction)loginAction:(id)sender
{ {
if (![_boxController isAuthorized]) { if (![_boxController isAuthorized]) {
_authorizationInProgress = YES; self.authorizationInProgress = YES;
[self.navigationController pushViewController:[self createAuthController] animated:YES]; [self.navigationController pushViewController:[self createAuthController] animated:YES];
} else { } else {
[_boxController logout]; [_boxController logout];
} }
} }
- (void)logout
{
[_boxController logout];
[self updateViewAfterSessionChange];
}
@end @end
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
self.oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil]; self.oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
self.documentPickerController = [VLCDocumentPickerController new]; self.documentPickerController = [VLCDocumentPickerController new];
} }
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
......
//
// VLCCloudStorageController.h
// VLC for iOS
//
// Created by Carola Nitz on 31/12/14.
// Copyright (c) 2014 VideoLAN. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol VLCCloudStorageDelegate <NSObject>
@required
- (void)mediaListUpdated;
@optional
- (void)operationWithProgressInformationStarted;
- (void)currentProgressInformation:(CGFloat)progress;
- (void)updateRemainingTime:(NSString *)time;
- (void)operationWithProgressInformationStopped;
- (void)numberOfFilesWaitingToBeDownloadedChanged;
- (void)sessionWasUpdated;
@end
@interface VLCCloudStorageController : NSObject
@property (nonatomic, weak) id<VLCCloudStorageDelegate> delegate;
@property (nonatomic, readwrite) BOOL isAuthorized;
@property (nonatomic, readonly) NSArray *currentListFiles;
+ (VLCCloudStorageController *)sharedInstance;
- (void)startSession;
- (void)logout;
- (void)requestDirectoryListingAtPath:(NSString *)path;
@end
//
// VLCCloudStorageController.m
// VLC for iOS
//
// Created by Carola Nitz on 31/12/14.
// Copyright (c) 2014 VideoLAN. All rights reserved.
//
#import "VLCCloudStorageController.h"
@implementation VLCCloudStorageController
@end
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
* Refer to the COPYING file of the official project for license. * Refer to the COPYING file of the official project for license.
*****************************************************************************/ *****************************************************************************/
#import "VLCCloudStorageTableViewCell.h"
#import "VLCCloudStorageController.h"
@interface VLCCloudStorageTableViewController : UIViewController @interface VLCCloudStorageTableViewController : UIViewController
@property (nonatomic, strong) IBOutlet UITableView *tableView; @property (nonatomic, strong) IBOutlet UITableView *tableView;
...@@ -20,8 +23,17 @@ ...@@ -20,8 +23,17 @@
@property (nonatomic, strong) IBOutlet UIButton *flatLoginButton; @property (nonatomic, strong) IBOutlet UIButton *flatLoginButton;
@property (nonatomic, strong) IBOutlet UIImageView *cloudStorageLogo; @property (nonatomic, strong) IBOutlet UIImageView *cloudStorageLogo;
@property (nonatomic, strong) UIBarButtonItem *numberOfFilesBarButtonItem;
@property (nonatomic, strong) VLCCloudStorageController *controller;
@property (nonatomic, strong) NSString *currentPath;
@property (nonatomic) BOOL authorizationInProgress;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicator;
- (IBAction)loginAction:(id)sender; - (IBAction)loginAction:(id)sender;
- (void)_requestInformationForCurrentPath;
- (void)_showLoginPanel;
- (void)updateViewAfterSessionChange; - (void)updateViewAfterSessionChange;
- (void)goBack;
@end @end
\ No newline at end of file
...@@ -13,15 +13,190 @@ ...@@ -13,15 +13,190 @@
*****************************************************************************/ *****************************************************************************/
#import "VLCCloudStorageTableViewController.h" #import "VLCCloudStorageTableViewController.h"
#import "UIBarButtonItem+Theme.h"
#import "VLCProgressView.h"
@interface VLCCloudStorageTableViewController() <VLCCloudStorageDelegate>
{
VLCProgressView *_progressView;
UIBarButtonItem *_progressBarButtonItem;
UIBarButtonItem *_logoutButton;
}
@end
@implementation VLCCloudStorageTableViewController @implementation VLCCloudStorageTableViewController
- (IBAction)loginAction:(id)sender - (void)viewDidLoad
{
[super viewDidLoad];
_authorizationInProgress = NO;
self.modalPresentationStyle = UIModalPresentationFormSheet;
self.navigationItem.titleView.contentMode = UIViewContentModeScaleAspectFit;
UIBarButtonItem *backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack)];
self.navigationItem.leftBarButtonItem = backButton;
_logoutButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_LOGOUT", "") style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];
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.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
_progressView = [VLCProgressView new];
_progressBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_progressView];
_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];
_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]];
[self _showProgressInToolbar:NO];
}
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"bottomBlackBar"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{ {
self.navigationController.toolbarHidden = YES;
[super viewWillDisappear:animated];
}
- (void)_requestInformationForCurrentPath
{
[_activityIndicator startAnimating];
[self.controller requestDirectoryListingAtPath:self.currentPath];
}
- (void)mediaListUpdated
{
[_activityIndicator stopAnimating];
[self.tableView reloadData];
NSUInteger count = self.controller.currentListFiles.count;
if (count == 0)
self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"NO_FILES", nil);
else if (count != 1)
self.numberOfFilesBarButtonItem.title = [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
else
self.numberOfFilesBarButtonItem.title = NSLocalizedString(@"ONE_FILE", nil);
}
- (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)operationWithProgressInformationStarted
{
[self _showProgressInToolbar:YES];
}
- (void)updateRemainingTime:(NSString *)time
{
[_progressView updateTime:time];
}
- (void)currentProgressInformation:(CGFloat)progress
{
[_progressView.progressBar setProgress:progress animated:YES];
}
- (void)operationWithProgressInformationStopped