123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- /*****************************************************************************
- * VLCCloudServicesTableViewController.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 "VLCCloudServicesTableViewController.h"
- #import "VLCDropboxTableViewController.h"
- #import "VLCGoogleDriveTableViewController.h"
- #import "VLCBoxTableViewController.h"
- #import "VLCBoxController.h"
- #import "VLCOneDriveTableViewController.h"
- #import "VLCOneDriveController.h"
- #import "VLCDocumentPickerController.h"
- #import "VLCCloudServiceCell.h"
- #import "VLCGoogleDriveController.h"
- #import "VLC-Swift.h"
- @interface VLCCloudServicesTableViewController ()
- @property (nonatomic) VLCDropboxTableViewController *dropboxTableViewController;
- @property (nonatomic) VLCGoogleDriveTableViewController *googleDriveTableViewController;
- @property (nonatomic) VLCBoxTableViewController *boxTableViewController;
- @property (nonatomic) VLCOneDriveTableViewController *oneDriveTableViewController;
- @property (nonatomic) VLCDocumentPickerController *documentPickerController;
- @end
- @implementation VLCCloudServicesTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.tableView registerNib:[UINib nibWithNibName:@"VLCCloudServiceCell" bundle:nil] forCellReuseIdentifier:@"CloudServiceCell"];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
- [self themeDidChange];
- self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
- self.googleDriveTableViewController = [[VLCGoogleDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
- [[VLCBoxController sharedInstance] startSession];
- self.boxTableViewController = [[VLCBoxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
- self.oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
- self.documentPickerController = [VLCDocumentPickerController new];
- }
- - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- self.title = NSLocalizedString(@"CLOUD_SERVICES", @"");
- }
- return self;
- }
- - (void)themeDidChange
- {
- self.tableView.separatorColor = PresentationTheme.current.colors.background;
- self.tableView.backgroundColor = PresentationTheme.current.colors.background;
- [self setNeedsStatusBarAppearanceUpdate];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
- [self.tableView reloadData];
- [super viewWillAppear:animated];
- }
- - (void)authenticationSessionsChanged:(NSNotification *)notification
- {
- [self.tableView reloadData];
- }
- - (NSString *)detailText
- {
- int services = [self numberOfAuthorizedServices];
- if (services == 1) {
- return NSLocalizedString(@"LOGGED_IN_SERVICE", nil);
- } else {
- return [NSString stringWithFormat:NSLocalizedString(@"LOGGED_IN_SERVICES", ""), services];
- }
- }
- - (int)numberOfAuthorizedServices
- {
- int i = [[VLCDropboxController sharedInstance] isAuthorized] ? 1 : 0;
- i += [[VLCGoogleDriveController sharedInstance] isAuthorized] ? 1 : 0;
- i += [[BoxSDK sharedSDK].OAuth2Session isAuthorized] ? 1 : 0;
- i += [[VLCOneDriveController sharedInstance] isAuthorized] ? 1 : 0;
- return i;
- }
- - (UIStatusBarStyle)preferredStatusBarStyle
- {
- return PresentationTheme.current.colors.statusBarStyle;
- }
- - (UIImage *)cellImage
- {
- return [UIImage imageNamed:@"iCloudIcon"];
- }
- #pragma mark - Table view data source
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return 5;
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- cell.backgroundColor = (indexPath.row % 2 == 0)? PresentationTheme.current.colors.cellBackgroundA: PresentationTheme.current.colors.cellBackgroundB;
- [cell setSeparatorInset:UIEdgeInsetsZero];
- [cell setPreservesSuperviewLayoutMargins:NO];
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
- cell.cloudTitle.textColor = cell.cloudInformation.textColor = cell.lonesomeCloudTitle.textColor = PresentationTheme.current.colors.cellTextColor;
- cell.icon.tintColor = PresentationTheme.current.colors.cellTextColor;
- switch (indexPath.row) {
- case 0: {
- //Dropbox
- BOOL isAuthorized = [[VLCDropboxController sharedInstance] isAuthorized];
- cell.icon.image = [UIImage imageNamed:@"Dropbox"];
- cell.cloudTitle.text = @"Dropbox";
- cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
- cell.lonesomeCloudTitle.text = @"";
- break;
- }
- case 1: {
- //GoogleDrive
- BOOL isAuthorized = [[VLCGoogleDriveController sharedInstance] isAuthorized];
- cell.icon.image = [UIImage imageNamed:@"Drive"];
- cell.cloudTitle.text = @"Google Drive";
- cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
- cell.lonesomeCloudTitle.text = @"";
- break;
- }
- case 2: {
- //Box
- BOOL isAuthorized = [[BoxSDK sharedSDK].OAuth2Session isAuthorized];
- cell.icon.image = [UIImage imageNamed:@"Box"];
- cell.cloudTitle.text = @"Box";
- cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
- cell.lonesomeCloudTitle.text = @"";
- break;
- }
- case 3: {
- //OneDrive
- BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
- cell.icon.image = [UIImage imageNamed:@"OneDrive"];
- cell.cloudTitle.text = @"OneDrive";
- cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
- cell.lonesomeCloudTitle.text = @"";
- break;
- }
- case 4:
- //Cloud Drives
- cell.icon.image = [UIImage imageNamed:@"iCloud"];
- cell.lonesomeCloudTitle.text = NSLocalizedString(@"CLOUD_SERVICES", nil);
- cell.cloudTitle.text = cell.cloudInformation.text = @"";
- break;
- default:
- break;
- }
- return cell;
- }
- #pragma mark - Table view delegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 66.0;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- switch (indexPath.row) {
- case 0:
- //dropBox
- [self.navigationController pushViewController:self.dropboxTableViewController animated:YES];
- break;
- case 1:
- //GoogleDrive
- [self.navigationController pushViewController:self.googleDriveTableViewController animated:YES];
- break;
- case 2:
- //Box
- [self.navigationController pushViewController:self.boxTableViewController animated:YES];
- break;
- case 3:
- //OneDrive
- [self.navigationController pushViewController:self.oneDriveTableViewController animated:YES];
- break;
- case 4:
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [self.documentPickerController showDocumentMenuViewController:[(VLCCloudServiceCell *)[self.tableView cellForRowAtIndexPath:indexPath] icon]];
- else
- [self.documentPickerController showDocumentMenuViewController:nil];
- break;
- default:
- break;
- }
- }
- @end
|