/***************************************************************************** * VLCCloudStorageTableViewController.m * VLC for iOS ***************************************************************************** * Copyright (c) 2013 VideoLAN. All rights reserved. * $Id$ * * Authors: Felix Paul Kühne * Fabio Ritrovato * Carola Nitz * * Refer to the COPYING file of the official project for license. *****************************************************************************/ #import "VLCCloudStorageTableViewController.h" #import "VLCProgressView.h" @interface VLCCloudStorageTableViewController() { VLCProgressView *_progressView; UIBarButtonItem *_progressBarButtonItem; UIBarButtonItem *_logoutButton; } @end @implementation VLCCloudStorageTableViewController - (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 { [self _showProgressInToolbar:NO]; } #pragma mark - UITableViewDataSources - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.controller.currentListFiles.count; } #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor]; } - (void)goBack { if (((![self.currentPath isEqualToString:@""] && ![self.currentPath isEqualToString:@"/"]) && [self.currentPath length] > 0) && [self.controller isAuthorized]){ self.currentPath = [self.currentPath stringByDeletingLastPathComponent]; [self _requestInformationForCurrentPath]; } else [self.navigationController popViewControllerAnimated:YES]; } - (void)_showLoginPanel { self.loginToCloudStorageView.frame = self.tableView.frame; self.navigationItem.rightBarButtonItem = nil; [self.view addSubview:self.loginToCloudStorageView]; } - (void)updateViewAfterSessionChange { self.navigationItem.rightBarButtonItem = _logoutButton; if(_authorizationInProgress) { if (self.loginToCloudStorageView.superview) { [self.loginToCloudStorageView removeFromSuperview]; } return; } if (![self.controller isAuthorized]) { [self _showLoginPanel]; return; } //reload if we didn't come back from streaming self.currentPath = @""; if([self.controller.currentListFiles count] == 0) [self _requestInformationForCurrentPath]; } - (void)logout { [self.controller logout]; [self updateViewAfterSessionChange]; } - (IBAction)loginAction:(id)sender { } @end