VLCRemoteBrowsingTVCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. @end
  21. @implementation VLCRemoteBrowsingTVCell
  22. @synthesize thumbnailURL = _thumbnailURL, isDirectory = _isDirectory, couldBeAudioOnlyMedia = _couldBeAudioOnlyMedia;
  23. - (void)awakeFromNib
  24. {
  25. [super awakeFromNib];
  26. _artworkProvider = [[VLCMDFBrowsingArtworkProvider alloc] init];
  27. _artworkProvider.artworkReceiver = self;
  28. UILayoutGuide *focusedFrameGuide = self.thumbnailImageView.focusedFrameGuide;
  29. NSLayoutConstraint *constraint = [self.titleLabel.topAnchor constraintEqualToAnchor:focusedFrameGuide.bottomAnchor constant:15];
  30. [self.contentView addConstraint:constraint];
  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. }
  41. - (void)setCouldBeAudioOnlyMedia:(BOOL)couldBeAudioOnlyMedia
  42. {
  43. _artworkProvider.searchForAudioMetadata = _couldBeAudioOnlyMedia;
  44. if (_couldBeAudioOnlyMedia != couldBeAudioOnlyMedia) {
  45. [_artworkProvider reset];
  46. }
  47. _couldBeAudioOnlyMedia = couldBeAudioOnlyMedia;
  48. }
  49. - (void)setThumbnailURL:(NSURL *)thumbnailURL
  50. {
  51. _thumbnailURL = thumbnailURL;
  52. if (_thumbnailURL) {
  53. [self.thumbnailImageView setImageWithURL:thumbnailURL];
  54. } else {
  55. NSString *searchString = self.title;
  56. if (searchString != nil && !_isDirectory) {
  57. [_artworkProvider searchForArtworkForVideoRelatedString:searchString];
  58. }
  59. }
  60. }
  61. - (void)setThumbnailImage:(UIImage *)thumbnailImage
  62. {
  63. [self.thumbnailImageView setImage:thumbnailImage];
  64. }
  65. -(UIImage *)thumbnailImage
  66. {
  67. return self.thumbnailImageView.image;
  68. }
  69. - (void)setTitle:(NSString *)title
  70. {
  71. self.titleLabel.text = title;
  72. if (title != nil && !_isDirectory) {
  73. [_artworkProvider searchForArtworkForVideoRelatedString:title];
  74. }
  75. }
  76. - (NSString *)title
  77. {
  78. return self.titleLabel.text;
  79. }
  80. - (void)setSubtitle:(NSString *)subtitle
  81. {
  82. self.subtitleLabel.text = subtitle;
  83. }
  84. - (NSString *)subtitle
  85. {
  86. return self.subtitleLabel.text;
  87. }
  88. - (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
  89. {
  90. [coordinator addCoordinatedAnimations:^{
  91. CGAffineTransform transform = context.nextFocusedView != self ? CGAffineTransformIdentity : CGAffineTransformMakeScale(1.1, 1.1);
  92. self.titleLabel.transform = transform;
  93. self.subtitleLabel.transform = transform;
  94. } completion:nil];
  95. }
  96. @end