VLCDropboxCollectionViewController.m 3.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*****************************************************************************
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 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.
 *****************************************************************************/
11 12 13 14 15 16

#import "VLCDropboxCollectionViewController.h"
#import "VLCDropboxController.h"
#import "UIDevice+VLC.h"
#import "DBKeychain.h"
#import "VLCRemoteBrowsingTVCell.h"
17
#import "VLCRemoteBrowsingTVCell+CloudStorage.h"
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

@interface VLCDropboxCollectionViewController () <VLCCloudStorageDelegate>
{
    VLCDropboxController *_dropboxController;
    DBMetadata *_selectedFile;
    NSArray *_mediaList;
}
@end

@implementation VLCDropboxCollectionViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    _dropboxController = [VLCDropboxController sharedInstance];
    self.controller = _dropboxController;
    self.controller.delegate = self;

    self.title = @"Dropbox";
}

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

    self.controller = [VLCDropboxController sharedInstance];
    self.controller.delegate = self;

51 52 53 54
    if (self.currentPath != nil) {
        NSString *lastPathComponent = self.currentPath.lastPathComponent;
        self.title = lastPathComponent.length > 0 ? lastPathComponent : @"Dropbox";
    }
55 56 57 58 59 60 61 62 63 64 65 66

    [self updateViewAfterSessionChange];
}

- (void)mediaListUpdated
{
    _mediaList = [self.controller.currentListFiles copy];
    [self.collectionView reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
67
    VLCRemoteBrowsingTVCell *cell = (VLCRemoteBrowsingTVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:VLCRemoteBrowsingTVCellIdentifier forIndexPath:indexPath];
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    NSUInteger index = indexPath.row;
    if (_mediaList) {
        if (index < _mediaList.count) {
            cell.dropboxFile = _mediaList[index];
        }
    }

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    _selectedFile = _mediaList[indexPath.row];
    if (!_selectedFile.isDirectory)
        [_dropboxController streamFile:_selectedFile currentNavigationController:self.navigationController];
    else {
        /* dive into subdirectory */
        NSString *futurePath = [self.currentPath stringByAppendingFormat:@"/%@", _selectedFile.filename];
        [_dropboxController reset];
        VLCDropboxCollectionViewController *targetViewController = [[VLCDropboxCollectionViewController alloc] initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
        targetViewController.currentPath = futurePath;
        [self.navigationController pushViewController:targetViewController animated:YES];
    }
    _selectedFile = nil;
}

@end