VLCRemoteBrowsingTVCell+CloudStorage.m 3.95 KB
Newer Older
1
/*****************************************************************************
2
 * VLCRemoteBrowsingTVCell+CloudStorage.m
3 4 5 6 7 8 9 10 11 12 13
 * VLC for tvOS
 *****************************************************************************
 * Copyright (c) 2013-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.
 *****************************************************************************/

14
#import "VLCRemoteBrowsingTVCell+CloudStorage.h"
15

16
@implementation VLCRemoteBrowsingTVCell (CloudStorage)
17

Soomin Lee's avatar
Soomin Lee committed
18
- (void)setDropboxFile:(DBFILESMetadata *)dropboxFile
19
{
20 21
    [self performSelectorOnMainThread:@selector(_updateDropboxRepresentation:)
                           withObject:dropboxFile waitUntilDone:NO];
22 23 24 25
}

- (void)setBoxFile:(BoxItem *)boxFile
{
26 27
    [self performSelectorOnMainThread:@selector(_updateBoxRepresentation:)
                           withObject:boxFile waitUntilDone:NO];
28 29 30 31
}

- (void)setOneDriveFile:(VLCOneDriveObject *)oneDriveFile
{
32 33
    [self performSelectorOnMainThread:@selector(_updateOneDriveRepresentation:)
                           withObject:oneDriveFile waitUntilDone:NO];
34 35
}

Soomin Lee's avatar
Soomin Lee committed
36
- (void)_updateDropboxRepresentation:(DBFILESMetadata *)dropboxFile
37
{
38
    if (dropboxFile != nil) {
Soomin Lee's avatar
Soomin Lee committed
39
        if ([dropboxFile isKindOfClass: [DBFILESFolderMetadata class]]) {
40
            self.isDirectory = YES;
Soomin Lee's avatar
Soomin Lee committed
41
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
42
        } else {
Soomin Lee's avatar
Soomin Lee committed
43
            DBFILESFileMetadata *file = (DBFILESFileMetadata *)dropboxFile;
44

Soomin Lee's avatar
Soomin Lee committed
45 46
            self.isDirectory = NO;
            self.subtitle = (file.size.integerValue > 0) ? [NSByteCountFormatter stringFromByteCount:file.size.longLongValue countStyle:NSByteCountFormatterCountStyleFile] : @"";
47
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
Soomin Lee's avatar
Soomin Lee committed
48 49
        }
        self.title = dropboxFile.name;
50
    }
51 52 53 54 55 56
}

- (void)_updateBoxRepresentation:(BoxItem *)boxFile
{
    if (boxFile != nil) {
        BOOL isDirectory = [boxFile.type isEqualToString:@"folder"];
57 58 59 60 61
        if (isDirectory) {
            self.isDirectory = YES;
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
        } else {
            self.isDirectory = NO;
62
            self.subtitle = (boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
63 64
            self.thumbnailImage = [UIImage imageNamed:@"blank"];
        }
65 66 67 68 69 70 71 72
        self.title = boxFile.name;
    }
}

- (void)_updateOneDriveRepresentation:(VLCOneDriveObject *)oneDriveFile
{
    if (oneDriveFile != nil) {
        if (oneDriveFile.isFolder) {
73 74 75 76 77 78
            self.isDirectory = YES;
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
        } else {
            self.isDirectory = NO;

            NSMutableString *subtitle = [[NSMutableString alloc] init];
79
            self.thumbnailImage = [UIImage imageNamed:@"blank"];
80

81
            if (oneDriveFile.isVideo) {
82
                NSString *thumbnailURLString = oneDriveFile.thumbnailURL;
83 84 85
                if (thumbnailURLString) {
                    [self setThumbnailURL:[NSURL URLWithString:thumbnailURLString]];
                }
86
            }
87

88 89 90 91
            if (oneDriveFile.size > 0) {
                [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
                if (oneDriveFile.duration > 0) {
                    VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
92 93
                    [subtitle appendFormat:@" — %@", [time verboseStringValue]];
                }
94 95
            } else if (oneDriveFile.duration > 0) {
                VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
96 97 98 99
                [subtitle appendString:[time verboseStringValue]];
            }
            self.subtitle = subtitle;
        }
100
        self.title = oneDriveFile.name;
101 102 103 104
    }
}

@end