VLCPlaylistGridView.m 3.15 KB
Newer Older
1 2 3 4 5 6 7 8 9
//
//  VLCGridViewCell.m
//  AspenProject
//
//  Created by Felix Paul Kühne on 11.04.13.
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//

#import "VLCPlaylistGridView.h"
10
#import "VLCAppDelegate.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
11
#import "AQGridView.h"
12 13

@interface VLCPlaylistGridView (Hack)
14
@property (nonatomic, retain) NSString *reuseIdentifier;
15 16 17 18
@end

@implementation VLCPlaylistGridView

19 20 21 22 23
+ (CGSize)preferredSize
{
    return CGSizeMake(288, 220);
}

24 25 26 27 28 29 30 31 32 33 34 35 36 37
- (void)awakeFromNib {
    [super awakeFromNib];
    _contentView = self;
    self.backgroundColor = [UIColor blackColor];
    self.reuseIdentifier = @"AQPlaylistCell";
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    self.removeMediaButton.hidden = !editing;
}

- (void)prepareForReuse
38
{
39 40
    [super prepareForReuse];
    self.removeMediaButton.hidden = YES;
41 42
}

43 44 45
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    [self _updatedDisplayedInformation];
46 47
}

48
- (void)setMediaObject:(MLFile *)mediaObject
49
{
50 51 52 53 54 55 56
    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"];
57
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
58 59 60
        [_mediaObject didHide];

        _mediaObject = mediaObject;
61

62 63 64 65 66 67
        [_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];
68
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
69 70 71 72 73 74 75 76 77 78 79 80
        [_mediaObject willDisplay];
    }

    [self _updatedDisplayedInformation];
}

- (void)_updatedDisplayedInformation
{
    self.titleLabel.text = self.mediaObject.title;
    self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 2e6];
    self.thumbnailView.image = self.mediaObject.computedThumbnail;
    self.progressView.progress = self.mediaObject.lastPosition.floatValue;
81

82 83
    if (self.progressView.progress < 0.1f)
        self.progressView.hidden = YES;
84

85 86
    self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;

87
    [self setNeedsDisplay];
88 89
}

90
- (IBAction)removeMedia:(id)sender
91
{
92 93
    NSUInteger cellIndex = [self.gridView indexForCell:self];
    [self.gridView.delegate gridView:self.gridView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndex:cellIndex];
94 95 96
}

@end