VLCCloudStorageTableViewCell.m 9.53 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;
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
33
- (void)setDropboxFile:(DBMetadata *)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 74 75
    if (_dropboxFile != nil) {
        if (self.dropboxFile.isDirectory) {
            self.folderTitleLabel.text = self.dropboxFile.filename;
76 77
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
78
        } else {
79 80
            NSString *title = self.dropboxFile.filename;
            self.titleLabel.text = title;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
81
            self.subtitleLabel.text = (self.dropboxFile.totalBytes > 0) ? self.dropboxFile.humanReadableSize : @"";
82 83
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
84 85
        }

Felix Paul Kühne's avatar
Felix Paul Kühne committed
86
        NSString *iconName = self.dropboxFile.icon;
87 88 89 90 91 92 93
        if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
            self.downloadButton.hidden = YES;
        } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
            self.thumbnailView.image = [UIImage imageNamed:@"blank"];
        else if ([iconName isEqualToString:@"page_white_film"])
            self.thumbnailView.image = [UIImage imageNamed:@"movie"];
94 95
        else if ([iconName isEqualToString:@"page_white_sound"])
            self.thumbnailView.image = [UIImage imageNamed:@"audio"];
Carola Nitz's avatar
Carola Nitz committed
96 97
        else {
            self.thumbnailView.image = [UIImage imageNamed:@"blank"];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
98
            APLog(@"missing icon for type '%@'", self.dropboxFile.icon);
Carola Nitz's avatar
Carola Nitz committed
99
        }
100 101 102
    }
#if TARGET_OS_IOS
    else if(_driveFile != nil){
103 104 105
        BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
        if (isDirectory) {
            self.folderTitleLabel.text = self.driveFile.title;
106 107
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
108
        } else {
109 110
            NSString *title = self.driveFile.title;
            self.titleLabel.text = title;
111
            self.subtitleLabel.text = (self.driveFile.fileSize > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.fileSize longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
112 113
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
114 115 116 117

            if (_driveFile.thumbnailLink != nil) {
                [self.thumbnailView setImageWithURL:[NSURL URLWithString:_driveFile.thumbnailLink]];
            }
118
        }
119
        NSString *iconName = self.driveFile.iconLink;
120
        if (isDirectory) {
121 122
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
123
            self.thumbnailView.image = [UIImage imageNamed:@"audio"];
124 125 126 127 128 129
        } 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
130 131 132
    }
#endif
    else if(_boxFile != nil) {
Carola Nitz's avatar
Carola Nitz committed
133 134 135 136 137 138
        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 {
139 140
            NSString *title = self.boxFile.name;
            self.titleLabel.text = title;
Carola Nitz's avatar
Carola Nitz committed
141 142 143
            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;
144
            self.downloadButton.hidden = NO;
Carola Nitz's avatar
Carola Nitz committed
145 146 147 148 149
        }
        //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];
150
//            [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
Carola Nitz's avatar
Carola Nitz committed
151 152 153 154 155 156 157 158
//        }
        //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
159
    } else if(_oneDriveFile != nil) {
160
        if (_oneDriveFile.isFolder) {
161
            self.downloadButton.hidden = YES;
162 163 164 165 166
            self.folderTitleLabel.text = self.oneDriveFile.name;
            self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
            self.folderTitleLabel.hidden = NO;
            self.thumbnailView.image = [UIImage imageNamed:@"folder"];
        } else {
167
            self.downloadButton.hidden = NO;
168 169
            NSString *title = self.oneDriveFile.name;
            self.titleLabel.text = title;
170
            NSMutableString *subtitle = [[NSMutableString alloc] init];
171 172 173 174 175 176 177 178 179 180 181 182

            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;
                if (thumbnailURLString) {
                    [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
                }
            } else
                self.thumbnailView.image = [UIImage imageNamed:@"blank"];

183 184 185 186 187 188 189 190 191 192 193
            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;
194 195 196
            self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
            self.folderTitleLabel.hidden = YES;
        }
197
    }
198

199 200 201 202 203 204 205 206 207 208 209
    [self setNeedsDisplay];
}

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

+ (CGFloat)heightOfCell
{
210
#if TARGET_OS_IOS
211 212 213 214
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        return 80.;

    return 48.;
215 216 217
#else
    return 107.;
#endif
218 219
}

220 221 222 223 224
- (void)setIsDownloadable:(BOOL)isDownloadable
{
    self.downloadButton.hidden = !isDownloadable;
}

225
@end