VLCCloudServicesTableViewController.m 8.58 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCCloudServicesTableViewController.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2014-2015 VideoLAN. All rights reserved.
6 7 8
 * $Id$
 *
 * Authors: Carola Nitz <nitz.carola # googlemail.com>
9
 *          Felix Paul Kühne <fkuehne # videolan.org>
10 11 12 13 14 15 16 17
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

#import "VLCCloudServicesTableViewController.h"
#import "VLCDropboxTableViewController.h"
#import "VLCGoogleDriveTableViewController.h"
#import "VLCBoxTableViewController.h"
18
#import "VLCBoxController.h"
19
#import "VLCOneDriveTableViewController.h"
20
#import "VLCOneDriveController.h"
21 22 23 24
#import "VLCDocumentPickerController.h"
#import "VLCCloudServiceCell.h"

#import "VLCGoogleDriveController.h"
25
#import "VLC-Swift.h"
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

@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"];
43 44
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange) name:kVLCThemeDidChangeNotification object:nil];
    [self themeDidChange];
45 46 47

    self.dropboxTableViewController = [[VLCDropboxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
    self.googleDriveTableViewController = [[VLCGoogleDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
48
    [[VLCBoxController sharedInstance] startSession];
49 50 51 52
    self.boxTableViewController = [[VLCBoxTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
    self.oneDriveTableViewController = [[VLCOneDriveTableViewController alloc] initWithNibName:@"VLCCloudStorageTableViewController" bundle:nil];
    self.documentPickerController = [VLCDocumentPickerController new];
}
53

54 55 56 57 58 59 60 61 62
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"CLOUD_SERVICES", @"");
    }
    return self;
}

63 64 65 66
- (void)themeDidChange
{
    self.tableView.separatorColor = PresentationTheme.current.colors.background;
    self.tableView.backgroundColor = PresentationTheme.current.colors.background;
67
    [self setNeedsStatusBarAppearanceUpdate];
68 69
}

70 71
- (void)viewWillAppear:(BOOL)animated
{
72
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationSessionsChanged:) name:VLCOneDriveControllerSessionUpdated object:nil];
73 74 75 76
    [self.tableView reloadData];
    [super viewWillAppear:animated];
}

77 78 79 80 81
- (void)authenticationSessionsChanged:(NSNotification *)notification
{
    [self.tableView reloadData];
}

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
- (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;
}

101 102 103 104 105
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return PresentationTheme.current.colors.statusBarStyle;
}

106 107 108 109 110
- (UIImage *)cellImage
{
    return [UIImage imageNamed:@"iCloudIcon"];
}

111 112 113 114
#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
115
    return 5;
116 117 118 119
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
120 121 122 123
    cell.backgroundColor = (indexPath.row % 2 == 0)? PresentationTheme.current.colors.cellBackgroundA: PresentationTheme.current.colors.cellBackgroundB;
    [cell setSeparatorInset:UIEdgeInsetsZero];
    [cell setPreservesSuperviewLayoutMargins:NO];
    [cell setLayoutMargins:UIEdgeInsetsZero];
124 125 126 127 128
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    VLCCloudServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CloudServiceCell" forIndexPath:indexPath];
129 130
    cell.cloudTitle.textColor = cell.cloudInformation.textColor = cell.lonesomeCloudTitle.textColor = PresentationTheme.current.colors.cellTextColor;
    cell.icon.tintColor = PresentationTheme.current.colors.cellTextColor;
131 132 133
    switch (indexPath.row) {
        case 0: {
            //Dropbox
134
            BOOL isAuthorized = [[VLCDropboxController sharedInstance] isAuthorized];
135 136 137
            cell.icon.image = [UIImage imageNamed:@"Dropbox"];
            cell.cloudTitle.text = @"Dropbox";
            cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
138
            cell.lonesomeCloudTitle.text = @"";
139 140 141 142 143 144 145 146
            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", "");
147
            cell.lonesomeCloudTitle.text = @"";
148 149 150 151 152 153 154 155
            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", "");
156
            cell.lonesomeCloudTitle.text = @"";
157 158 159 160
            break;
        }
        case 3: {
            //OneDrive
161
            BOOL isAuthorized = [[VLCOneDriveController sharedInstance] isAuthorized];
162
            cell.icon.image = [UIImage imageNamed:@"OneDrive"];
163
            cell.cloudTitle.text = @"OneDrive";
164
            cell.cloudInformation.text = isAuthorized ? NSLocalizedString(@"LOGGED_IN", "") : NSLocalizedString(@"LOGIN", "");
165
            cell.lonesomeCloudTitle.text = @"";
166 167 168 169
            break;
        }
        case 4:
            //Cloud Drives
170 171 172
            cell.icon.image = [UIImage imageNamed:@"iCloud"];
            cell.lonesomeCloudTitle.text = NSLocalizedString(@"CLOUD_SERVICES", nil);
            cell.cloudTitle.text = cell.cloudInformation.text = @"";
173 174 175 176
            break;
        default:
            break;
    }
177

178 179 180 181 182 183 184 185 186 187
    return cell;
}

#pragma mark - Table view delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 66.0;
}

188 189 190
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    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;
208 209 210 211 212 213
        case 4:
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                [self.documentPickerController showDocumentMenuViewController:[(VLCCloudServiceCell *)[self.tableView cellForRowAtIndexPath:indexPath] icon]];
            else
                [self.documentPickerController showDocumentMenuViewController:nil];
            break;
214 215 216 217 218 219
        default:
            break;
    }
}

@end