VLCOneDriveTableViewController.m 4.46 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * VLCOneDriveTableViewController.m
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2014 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

#import "VLCOneDriveTableViewController.h"
#import "VLCOneDriveController.h"
#import "UIBarButtonItem+Theme.h"
#import "VLCCloudStorageTableViewCell.h"
#import "VLCAppDelegate.h"
#import "VLCOneDriveController.h"

@interface VLCOneDriveTableViewController () <UITableViewDataSource, UITableViewDelegate>
{
    UIBarButtonItem *_backButton;
23
    UIBarButtonItem *_logoutButton;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
24 25 26 27 28 29 30 31 32 33 34 35 36

    UIActivityIndicatorView *_activityIndicator;

    VLCOneDriveController *_oneDriveController;
}
@end

@implementation VLCOneDriveTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _oneDriveController = [VLCOneDriveController sharedInstance];
37
    _oneDriveController.delegate = self;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
38 39 40 41 42 43

    self.modalPresentationStyle = UIModalPresentationFormSheet;

    self.navigationItem.title = @"OneDrive";

    _backButton = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(goBack:)];
44
    self.navigationItem.leftBarButtonItem = _backButton;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
45

46 47
    _logoutButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_LOGOUT", "") style:UIBarButtonItemStyleBordered target:self action:@selector(logout)];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    self.tableView.rowHeight = [VLCCloudStorageTableViewCell heightOfCell];
    self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
    self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];

    self.cloudStorageLogo = nil;
    if (!SYSTEM_RUNS_IOS7_OR_LATER) {
        self.flatLoginButton.hidden = YES;
        [self.loginButton setTitle:NSLocalizedString(@"ONEDRIVE_LOGIN", nil) forState:UIControlStateNormal];
    } else {
        self.loginButton.hidden = YES;
        [self.flatLoginButton setTitle:NSLocalizedString(@"ONEDRIVE_LOGIN", nil) 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]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // FIXME: we should update the listing...
75
    [self _showLoginDialog];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
76 77 78 79 80 81 82 83 84

    [self.cloudStorageLogo sizeToFit];
    self.cloudStorageLogo.center = self.view.center;
}

#pragma mark - generic interface interaction

- (IBAction)goBack:(id)sender
{
85 86
    //FIXME: handle case for being in a folder
    [self.navigationController popViewControllerAnimated:YES];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
87 88
}

89 90 91 92 93 94 95 96 97 98 99 100
#pragma mark - table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114
#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
{
}

#pragma mark - login dialog
115 116 117 118 119 120 121

- (void)logout
{
    [_oneDriveController logout];
    [self updateViewAfterSessionChange];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
122 123 124
- (void)_showLoginDialog
{
    self.loginToCloudStorageView.frame = self.tableView.frame;
125
    self.navigationItem.rightBarButtonItem = nil;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
126 127 128 129 130
    [self.view addSubview:self.loginToCloudStorageView];
}

- (void)loginAction:(id)sender
{
131 132 133 134
    if (![_oneDriveController activeSession])
        [_oneDriveController login];
    else
        [_oneDriveController logout];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
135 136 137
}

@end