VLCPlaylistTableViewCell.m 3.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
//  VLCPlaylistTableViewCell.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 01.04.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//

#import "VLCPlaylistTableViewCell.h"

@implementation VLCPlaylistTableViewCell

+ (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
{
    NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
    NSAssert([nibContentArray count] == 1, @"meh");
    NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
Felix Paul Kühne's avatar
Felix Paul Kühne committed
18
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
19
20
21
22
23
24
25
26
27
28
29
    CGRect frame = [cell frame];
    UIView *background = [[UIView alloc] initWithFrame:frame];
    background.backgroundColor = [UIColor colorWithWhite:.05 alpha:1.];
    cell.backgroundView = background;
    UIView *highlightedBackground = [[UIView alloc] initWithFrame:frame];
    highlightedBackground.backgroundColor = [UIColor colorWithWhite:.2 alpha:1.];
    cell.selectedBackgroundView = highlightedBackground;

    return cell;
}

30
31
32
33
34
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    [self _updatedDisplayedInformation];
}

35
36
37
38
39
40
41
42
43
- (void)setMediaObject:(MLFile *)mediaObject
{
    if (_mediaObject != mediaObject) {
        [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
        [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
        [_mediaObject removeObserver:self forKeyPath:@"duration"];
        [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
        [_mediaObject removeObserver:self forKeyPath:@"title"];
        [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
44
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
45
46
47
48
49
50
51
52
53
54
        [_mediaObject didHide];

        _mediaObject = mediaObject;

        [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
55
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
56
57
58
59
60
61
62
63
64
        [_mediaObject willDisplay];
    }

    [self _updatedDisplayedInformation];
}

- (void)_updatedDisplayedInformation
{
    self.titleLabel.text = self.mediaObject.title;
65
    self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 1e6];
66
67
68
69
70
71
    self.thumbnailView.image = self.mediaObject.computedThumbnail;
    self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;

    if (self.progressIndicator.progress < 0.1f)
        self.progressIndicator.hidden = YES;

72
73
    self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;

74
75
76
    [self setNeedsDisplay];
}

77
78
79
80
81
82
+ (CGFloat)heightOfCell
{
    return 80.;
}

@end