VLCRemoteBrowsingTVCell+CloudStorage.m 4.78 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 18 19

- (void)setDropboxFile:(DBMetadata *)dropboxFile
{
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
}

36
- (void)_updateDropboxRepresentation:(DBMetadata *)dropboxFile
37
{
38 39
    if (dropboxFile != nil) {
        if (dropboxFile.isDirectory) {
40
            self.isDirectory = YES;
41
            self.title = dropboxFile.filename;
42 43
        } else {
            self.isDirectory = NO;
44
            self.subtitle = (dropboxFile.totalBytes > 0) ? dropboxFile.humanReadableSize : @"";
45 46

        }
47
        self.title = dropboxFile.filename;
48

49
        NSString *iconName = dropboxFile.icon;
50 51 52 53 54 55 56 57 58 59
        if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
        } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
            self.thumbnailImage = [UIImage imageNamed:@"blank"];
        else if ([iconName isEqualToString:@"page_white_film"])
            self.thumbnailImage = [UIImage imageNamed:@"movie"];
        else if ([iconName isEqualToString:@"page_white_sound"])
            self.thumbnailImage = [UIImage imageNamed:@"audio"];
        else {
            self.thumbnailImage = [UIImage imageNamed:@"blank"];
60
            APLog(@"missing icon for type '%@'", dropboxFile.icon);
61 62
        }
    }
63 64 65 66 67 68 69

}

- (void)_updateBoxRepresentation:(BoxItem *)boxFile
{
    if (boxFile != nil) {
        BOOL isDirectory = [boxFile.type isEqualToString:@"folder"];
70 71 72 73 74
        if (isDirectory) {
            self.isDirectory = YES;
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
        } else {
            self.isDirectory = NO;
75
            self.subtitle = (boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
76 77
            self.thumbnailImage = [UIImage imageNamed:@"blank"];
        }
78 79 80 81 82 83 84 85
        self.title = boxFile.name;
    }
}

- (void)_updateOneDriveRepresentation:(VLCOneDriveObject *)oneDriveFile
{
    if (oneDriveFile != nil) {
        if (oneDriveFile.isFolder) {
86 87 88 89 90 91 92
            self.isDirectory = YES;
            self.thumbnailImage = [UIImage imageNamed:@"folder"];
        } else {
            self.isDirectory = NO;

            NSMutableString *subtitle = [[NSMutableString alloc] init];

93
            if (oneDriveFile.isAudio)
94
                self.thumbnailImage = [UIImage imageNamed:@"audio"];
95
            else if (oneDriveFile.isVideo) {
96
                self.thumbnailImage = [UIImage imageNamed:@"movie"];
97
                NSString *thumbnailURLString = oneDriveFile.thumbnailURL;
98 99 100 101 102 103
                if (thumbnailURLString) {
                    [self setThumbnailURL:[NSURL URLWithString:thumbnailURLString]];
                }
            } else
                self.thumbnailImage = [UIImage imageNamed:@"blank"];

104 105 106 107
            if (oneDriveFile.size > 0) {
                [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
                if (oneDriveFile.duration > 0) {
                    VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
108 109
                    [subtitle appendFormat:@" — %@", [time verboseStringValue]];
                }
110 111
            } else if (oneDriveFile.duration > 0) {
                VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
112 113 114 115
                [subtitle appendString:[time verboseStringValue]];
            }
            self.subtitle = subtitle;
        }
116
        self.title = oneDriveFile.name;
117 118 119 120
    }
}

@end