VLCRemoteBrowsingTVCell.m 3.42 KB
Newer Older
Tobias's avatar
Tobias committed
1 2 3 4 5 6 7
/*****************************************************************************
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2015 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Tobias Conradi <videolan # tobias-conradi.de>
8
 *          Felix Paul Kühne <fkuehne # videolan.org>
Tobias's avatar
Tobias committed
9 10 11 12
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

13
#import "VLCRemoteBrowsingTVCell.h"
14
#import "VLCMDFBrowsingArtworkProvider.h"
Tobias's avatar
Tobias committed
15

16
NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
Tobias's avatar
Tobias committed
17

18
@interface VLCRemoteBrowsingTVCell ()
19
{
20
    VLCMDFBrowsingArtworkProvider *_artworkProvider;
21
}
22
@property (nonatomic) IBOutlet NSLayoutConstraint *aspectRationConstraint;
23
@property (nonatomic) NSLayoutConstraint *titleThumbnailConstraint;
24

25 26
@end

27
@implementation VLCRemoteBrowsingTVCell
28

29
@synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory, couldBeAudioOnlyMedia = _couldBeAudioOnlyMedia;
30 31 32 33

- (void)awakeFromNib
{
    [super awakeFromNib];
34 35
    _artworkProvider = [[VLCMDFBrowsingArtworkProvider alloc] init];
    _artworkProvider.artworkReceiver = self;
36 37
    _titleThumbnailConstraint = [self.titleLabel.topAnchor constraintEqualToAnchor:self.thumbnailImageView.bottomAnchor constant:15];
    [self.contentView addConstraint:_titleThumbnailConstraint];
38 39

    [self prepareForReuse];
40 41 42 43 44
}

- (void)prepareForReuse
{
    [super prepareForReuse];
45
    [_artworkProvider reset];
46 47 48
    [self.thumbnailImageView cancelLoading];
    self.title = nil;
    self.subtitle = nil;
49
    self.downloadArtwork = NO;
50 51
}

52 53 54 55 56 57 58 59 60
- (void)setCouldBeAudioOnlyMedia:(BOOL)couldBeAudioOnlyMedia
{
    _artworkProvider.searchForAudioMetadata = _couldBeAudioOnlyMedia;
    if (_couldBeAudioOnlyMedia != couldBeAudioOnlyMedia) {
        [_artworkProvider reset];
    }
    _couldBeAudioOnlyMedia = couldBeAudioOnlyMedia;
}

61 62
- (void)setThumbnailURL:(NSURL *)thumbnailURL
{
63
    _thumbnailURL = thumbnailURL;
64 65 66 67
    if (_thumbnailURL) {
        [self.thumbnailImageView setImageWithURL:thumbnailURL];
    } else {
        NSString *searchString = self.title;
68
        if (searchString != nil && !_isDirectory && _downloadArtwork) {
69
            [_artworkProvider searchForArtworkForVideoRelatedString:searchString];
70 71
        }
    }
72
}
73 74 75

- (void)setThumbnailImage:(UIImage *)thumbnailImage
{
76 77
    [self.thumbnailImageView setImage:thumbnailImage];
}
78 79 80

-(UIImage *)thumbnailImage
{
81 82
    return self.thumbnailImageView.image;
}
83 84 85

- (void)setTitle:(NSString *)title
{
86
    self.titleLabel.text = title;
87
    if (title != nil && !_isDirectory && _downloadArtwork) {
88
        [_artworkProvider searchForArtworkForVideoRelatedString:title];
89
    }
90
}
91 92 93

- (NSString *)title
{
94 95
    return self.titleLabel.text;
}
96 97 98

- (void)setSubtitle:(NSString *)subtitle
{
99 100
    self.subtitleLabel.text = subtitle;
}
101 102 103

- (NSString *)subtitle
{
104 105 106
    return self.subtitleLabel.text;
}

107 108 109 110 111 112
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
    [coordinator addCoordinatedAnimations:^{
        CGAffineTransform transform = context.nextFocusedView != self ? CGAffineTransformIdentity : CGAffineTransformMakeScale(1.1, 1.1);
        self.titleLabel.transform = transform;
        self.subtitleLabel.transform = transform;
113
        self.titleThumbnailConstraint.constant = context.nextFocusedView != self ? 15 : 40;
114 115 116
    } completion:nil];
}

117
@end