VLCRemoteBrowsingTVCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  8. * Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCRemoteBrowsingTVCell.h"
  13. #import "VLCMDFBrowsingArtworkProvider.h"
  14. NSString *const VLCRemoteBrowsingTVCellIdentifier = @"VLCRemoteBrowsingTVCell";
  15. @interface VLCRemoteBrowsingTVCell ()
  16. {
  17. VLCMDFBrowsingArtworkProvider *_artworkProvider;
  18. }
  19. @property (nonatomic) IBOutlet NSLayoutConstraint *aspectRationConstraint;
  20. @property (nonatomic) NSLayoutConstraint *titleThumbnailConstraint;
  21. @end
  22. @implementation VLCRemoteBrowsingTVCell
  23. @synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory, couldBeAudioOnlyMedia = _couldBeAudioOnlyMedia;
  24. - (void)awakeFromNib
  25. {
  26. [super awakeFromNib];
  27. _artworkProvider = [[VLCMDFBrowsingArtworkProvider alloc] init];
  28. _artworkProvider.artworkReceiver = self;
  29. _titleThumbnailConstraint = [self.titleLabel.topAnchor constraintEqualToAnchor:self.thumbnailImageView.bottomAnchor constant:15];
  30. [self.contentView addConstraint:_titleThumbnailConstraint];
  31. [self prepareForReuse];
  32. }
  33. - (void)prepareForReuse
  34. {
  35. [super prepareForReuse];
  36. [_artworkProvider reset];
  37. [self.thumbnailImageView cancelLoading];
  38. self.title = nil;
  39. self.subtitle = nil;
  40. self.downloadArtwork = NO;
  41. }
  42. - (void)setCouldBeAudioOnlyMedia:(BOOL)couldBeAudioOnlyMedia
  43. {
  44. _artworkProvider.searchForAudioMetadata = _couldBeAudioOnlyMedia;
  45. if (_couldBeAudioOnlyMedia != couldBeAudioOnlyMedia) {
  46. [_artworkProvider reset];
  47. }
  48. _couldBeAudioOnlyMedia = couldBeAudioOnlyMedia;
  49. }
  50. - (void)setThumbnailURL:(NSURL *)thumbnailURL
  51. {
  52. _thumbnailURL = thumbnailURL;
  53. if (_thumbnailURL) {
  54. [self.thumbnailImageView setImageWithURL:thumbnailURL];
  55. } else {
  56. NSString *searchString = self.title;
  57. if (searchString != nil && !_isDirectory && _downloadArtwork) {
  58. [_artworkProvider searchForArtworkForVideoRelatedString:searchString];
  59. }
  60. }
  61. }
  62. - (void)setThumbnailImage:(UIImage *)thumbnailImage
  63. {
  64. [self.thumbnailImageView setImage:thumbnailImage];
  65. }
  66. -(UIImage *)thumbnailImage
  67. {
  68. return self.thumbnailImageView.image;
  69. }
  70. - (void)setTitle:(NSString *)title
  71. {
  72. self.titleLabel.text = title;
  73. if (title != nil && !_isDirectory && _downloadArtwork) {
  74. [_artworkProvider searchForArtworkForVideoRelatedString:title];
  75. }
  76. }
  77. - (NSString *)title
  78. {
  79. return self.titleLabel.text;
  80. }
  81. - (void)setSubtitle:(NSString *)subtitle
  82. {
  83. self.subtitleLabel.text = subtitle;
  84. }
  85. - (NSString *)subtitle
  86. {
  87. return self.subtitleLabel.text;
  88. }
  89. - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
  90. {
  91. [coordinator addCoordinatedAnimations:^{
  92. CGAffineTransform transform = context.nextFocusedView != self ? CGAffineTransformIdentity : CGAffineTransformMakeScale(1.1, 1.1);
  93. self.titleLabel.transform = transform;
  94. self.subtitleLabel.transform = transform;
  95. } completion:nil];
  96. }
  97. @end