VLCCloudStorageTableViewCell.m 8.97 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCCloudStorageTableViewCell.m
 * VLC for iOS
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9 10 11 12
 * $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.
 *****************************************************************************/
13 14

#import "VLCCloudStorageTableViewCell.h"
15
#import "VLCNetworkImageView.h"
16 17 18 19 20 21 22 23 24 25

@implementation VLCCloudStorageTableViewCell

+ (VLCCloudStorageTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
{
    NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCCloudStorageTableViewCell" owner:nil options:nil];
    NSAssert([nibContentArray count] == 1, @"meh");
    NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCCloudStorageTableViewCell class]], @"meh meh");
    VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[nibContentArray lastObject];

26 27 28 29
    cell.titleLabel.hidden = YES;
    cell.subtitleLabel.hidden = YES;
    cell.folderTitleLabel.hidden = YES;

30 31 32
    return cell;
}

33
- (void)setDropboxFile:(DBFILESMetadata *)dropboxFile
34
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
35 36
    if (dropboxFile != _dropboxFile)
        _dropboxFile = dropboxFile;
37

38 39
    [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
                           withObject:nil waitUntilDone:NO];
40 41
}

42
#if TARGET_OS_IOS
43 44 45 46 47
- (void)setDriveFile:(GTLDriveFile *)driveFile
{
    if (driveFile != _driveFile)
        _driveFile = driveFile;

48 49
    [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
                           withObject:nil waitUntilDone:NO];
50
}
Felix Paul Kühne's avatar
Felix Paul Kühne committed
51
#endif
52

Carola Nitz's avatar
Carola Nitz committed
53 54 55 56 57
- (void)setBoxFile:(BoxItem *)boxFile
{
    if (boxFile != _boxFile)
        _boxFile = boxFile;

58 59
    [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
                           withObject:nil waitUntilDone:NO];
Carola Nitz's avatar
Carola Nitz committed
60 61
}

62 63 64 65 66
- (void)setOneDriveFile:(VLCOneDriveObject *)oneDriveFile
{
    if (oneDriveFile != _oneDriveFile)
        _oneDriveFile = oneDriveFile;

67 68
    [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
                           withObject:nil waitUntilDone:NO];
69 70
}

71 72
- (void)_updatedDisplayedInformation
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
73
    if (_dropboxFile != nil) {
74 75
        if ([_dropboxFile isKindOfClass:[DBFILESFolderMetadata class]]) {
            self.folderTitleLabel.text = self.dropboxFile.name;
76 77
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
78 79 80 81
            self.downloadButton.hidden = YES;
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else if ([_dropboxFile isKindOfClass:[DBFILESFileMetadata class]]) {
            DBFILESFileMetadata *file = (DBFILESFileMetadata *)_dropboxFile;
Carola Nitz's avatar
Carola Nitz committed
82
            self.titleLabel.text = file.name;
83
            self.subtitleLabel.text = (file.size.integerValue > 0) ? [NSByteCountFormatter stringFromByteCount:file.size.longLongValue countStyle:NSByteCountFormatterCountStyleFile] : @"";
84 85
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
86
            self.downloadButton.hidden = NO;
Carola Nitz's avatar
Carola Nitz committed
87 88
            self.thumbnailView.image = [UIImage imageNamed:@"blank"];
        }
89 90 91
    }
#if TARGET_OS_IOS
    else if(_driveFile != nil){
92 93
        BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
        if (isDirectory) {
94
            self.folderTitleLabel.text = self.driveFile.name;
95 96
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
97
        } else {
98
            NSString *title = self.driveFile.name;
99
            self.titleLabel.text = title;
100
            self.subtitleLabel.text = (self.driveFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
101 102
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
103 104 105 106

            if (_driveFile.thumbnailLink != nil) {
                [self.thumbnailView setImageWithURL:[NSURL URLWithString:_driveFile.thumbnailLink]];
            }
107
        }
108
        NSString *iconName = self.driveFile.iconLink;
109
        if (isDirectory) {
110 111
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
112
            self.thumbnailView.image = [UIImage imageNamed:@"audio"];
113 114 115 116 117 118
        } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
            self.thumbnailView.image = [UIImage imageNamed:@"movie"];
        } else {
            self.thumbnailView.image = [UIImage imageNamed:@"blank"];
            APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
        }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
119 120 121
    }
#endif
    else if(_boxFile != nil) {
Carola Nitz's avatar
Carola Nitz committed
122 123 124 125 126 127
        BOOL isDirectory = [self.boxFile.type isEqualToString:@"folder"];
        if (isDirectory) {
            self.folderTitleLabel.text = self.boxFile.name;
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
        } else {
128 129
            NSString *title = self.boxFile.name;
            self.titleLabel.text = title;
Carola Nitz's avatar
Carola Nitz committed
130 131 132
            self.subtitleLabel.text = (self.boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
133
            self.downloadButton.hidden = NO;
Carola Nitz's avatar
Carola Nitz committed
134 135 136 137 138
        }
        //TODO: correct thumbnails
//        if (_boxFile.modelID != nil) {
//            //this request needs a token in the header to work
//            NSString *thumbnailURLString = [NSString stringWithFormat:@"https://api.box.com/2.0/files/%@/thumbnail.png?min_height=32&min_width=32&max_height=64&max_width=64", _boxFile.modelID];
139
//            [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
Carola Nitz's avatar
Carola Nitz committed
140 141 142 143 144 145 146 147
//        }
        //TODO:correct icons
        if (isDirectory) {
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else {
            self.thumbnailView.image = [UIImage imageNamed:@"blank"];
            APLog(@"missing icon for type '%@'", self.boxFile);
        }
Felix Paul Kühne's avatar
Felix Paul Kühne committed
148
    } else if(_oneDriveFile != nil) {
149
        if (_oneDriveFile.isFolder) {
150
            self.downloadButton.hidden = YES;
151 152 153 154 155
            self.folderTitleLabel.text = self.oneDriveFile.name;
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else {
156
            self.downloadButton.hidden = NO;
157 158
            NSString *title = self.oneDriveFile.name;
            self.titleLabel.text = title;
159
            NSMutableString *subtitle = [[NSMutableString alloc] init];
160 161 162 163 164 165

            if (self.oneDriveFile.isAudio)
                self.thumbnailView.image = [UIImage imageNamed:@"audio"];
            else if (self.oneDriveFile.isVideo) {
                self.thumbnailView.image = [UIImage imageNamed:@"movie"];
                NSString *thumbnailURLString = _oneDriveFile.thumbnailURL;
166
                if ([thumbnailURLString isKindOfClass:[NSString class]]) {
167 168 169 170 171
                    [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
                }
            } else
                self.thumbnailView.image = [UIImage imageNamed:@"blank"];

172 173 174 175 176 177 178 179 180 181 182
            if (self.oneDriveFile.size > 0) {
                [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[self.oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
                if (self.oneDriveFile.duration > 0) {
                    VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
                    [subtitle appendFormat:@" — %@", [time verboseStringValue]];
                }
            } else if (self.oneDriveFile.duration > 0) {
                VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
                [subtitle appendString:[time verboseStringValue]];
            }
            self.subtitleLabel.text = subtitle;
183 184 185
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
        }
186
    }
187

188 189 190 191 192 193 194 195 196 197 198
    [self setNeedsDisplay];
}

- (IBAction)triggerDownload:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
        [self.delegate triggerDownloadForCell:self];
}

+ (CGFloat)heightOfCell
{
199
#if TARGET_OS_IOS
200 201 202 203
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        return 80.;

    return 48.;
204 205 206
#else
    return 107.;
#endif
207 208
}

209 210 211 212 213
- (void)setIsDownloadable:(BOOL)isDownloadable
{
    self.downloadButton.hidden = !isDownloadable;
}

214
@end