123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- /*****************************************************************************
- * VLCOneDriveTableViewController.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2014-2015 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 "VLCCloudStorageTableViewCell.h"
- #import "VLCPlaybackController.h"
- #import "VLCProgressView.h"
- #import "UIDevice+VLC.h"
- @interface VLCOneDriveTableViewController () <VLCCloudStorageDelegate>
- {
- VLCOneDriveController *_oneDriveController;
- VLCOneDriveObject *_selectedFile;
- }
- @end
- @implementation VLCOneDriveTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- _oneDriveController = (VLCOneDriveController *)[VLCOneDriveController sharedInstance];
- self.controller = _oneDriveController;
- self.controller.delegate = self;
- self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"OneDriveWhite"]];
- #if TARGET_OS_IOS
- [self.cloudStorageLogo setImage:[UIImage imageNamed:@"OneDriveWhite"]];
- [self.cloudStorageLogo sizeToFit];
- self.cloudStorageLogo.center = self.view.center;
- #endif
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [self updateViewAfterSessionChange];
- self.authorizationInProgress = NO;
- }
- #pragma mark - generic interface interaction
- - (void)goBack
- {
- if ((_oneDriveController.rootFolder != _oneDriveController.currentFolder) && [_oneDriveController isAuthorized]) {
- if ([_oneDriveController.rootFolder.name isEqualToString:_oneDriveController.currentFolder.parent.name]) {
- _oneDriveController.currentFolder = nil;
- self.title = _oneDriveController.rootFolder.name;
- } else {
- _oneDriveController.currentFolder = _oneDriveController.currentFolder.parent;
- self.title = _oneDriveController.currentFolder.name;
- }
- [self.activityIndicator startAnimating];
- [_oneDriveController loadCurrentFolder];
- } else
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark - table view data source
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"OneDriveCell";
- VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier];
- NSArray *items = _oneDriveController.currentFolder.items;
- if (indexPath.row < items.count) {
- cell.oneDriveFile = _oneDriveController.currentFolder.items[indexPath.row];
- cell.delegate = self;
- }
- return cell;
- }
- #pragma mark - table view delegate
- - (void)mediaListUpdated
- {
- [self.tableView reloadData];
- [self.activityIndicator stopAnimating];
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSArray *folderItems = _oneDriveController.currentFolder.items;
- NSInteger row = indexPath.row;
- if (row >= folderItems.count)
- return;
- VLCOneDriveObject *selectedObject = folderItems[row];
- if (selectedObject.isFolder) {
- /* dive into sub folder */
- [self.activityIndicator startAnimating];
- _oneDriveController.currentFolder = selectedObject;
- [_oneDriveController loadCurrentFolder];
- self.title = selectedObject.name;
- } else {
- /* stream file */
- NSURL *url = [NSURL URLWithString:selectedObject.downloadPath];
- VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
- [vpc playURL:url successCallback:nil errorCallback:nil];
- }
- [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
- }
- #pragma mark - login dialog
- - (void)loginAction:(id)sender
- {
- if (![_oneDriveController isAuthorized]) {
- self.authorizationInProgress = YES;
- [_oneDriveController loginWithViewController:self];
- } else
- [_oneDriveController logout];
- }
- #pragma mark - onedrive controller delegation
- - (void)sessionWasUpdated
- {
- [self updateViewAfterSessionChange];
- }
- #pragma mark - cell delegation
- #if TARGET_OS_IOS
- - (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
- {
- NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
- _selectedFile = _oneDriveController.currentFolder.items[indexPath.row];
- if (_selectedFile.size.longLongValue < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
- /* selected item is a proper file, ask the user if s/he wants to download it */
- VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", nil)
- message:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
- delegate:self
- cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
- otherButtonTitles:NSLocalizedString(@"BUTTON_DOWNLOAD", nil), nil];
- [alert show];
- } else {
- VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
- message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), _selectedFile.name, [[UIDevice currentDevice] model]]
- delegate:self
- cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 1)
- [_oneDriveController downloadObject:_selectedFile];
- _selectedFile = nil;
- }
- #endif
- @end
|