VLCNetworkListCell.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*****************************************************************************
  2. * VLCNetworkListCell.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Pierre SAGASPE <pierre.sagaspe # me.com>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "VLCNetworkListCell.h"
  14. #import "VLCStatusLabel.h"
  15. #import "VLC-Swift.h"
  16. @implementation VLCNetworkListCell
  17. + (VLCNetworkListCell *)cellWithReuseIdentifier:(NSString *)ident
  18. {
  19. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCNetworkListCell" owner:nil options:nil];
  20. NSAssert([nibContentArray count] == 1, @"meh");
  21. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCNetworkListCell class]], @"meh meh");
  22. VLCNetworkListCell *cell = (VLCNetworkListCell *)[nibContentArray lastObject];
  23. return cell;
  24. }
  25. - (void)awakeFromNib
  26. {
  27. self.titleLabel.text = @"";
  28. self.subtitleLabel.text = @"";
  29. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
  30. self.downloadButton.hidden = YES;
  31. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChange)
  32. name:kVLCThemeDidChangeNotification object:nil];
  33. [super awakeFromNib];
  34. }
  35. - (void)themeDidChange
  36. {
  37. self.titleLabel.textColor = PresentationTheme.current.colors.cellTextColor;
  38. self.titleLabel.backgroundColor = PresentationTheme.current.colors.background;
  39. self.subtitleLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor;
  40. self.subtitleLabel.backgroundColor = PresentationTheme.current.colors.background;
  41. self.backgroundColor = PresentationTheme.current.colors.background;
  42. }
  43. - (void)setTitleLabelCentered:(BOOL)titleLabelCentered
  44. {
  45. self.titleLabel.hidden = self.subtitleLabel.hidden = titleLabelCentered;
  46. self.folderTitleLabel.hidden = !titleLabelCentered;
  47. _titleLabelCentered = titleLabelCentered;
  48. }
  49. - (void)setIsDirectory:(BOOL)isDirectory
  50. {
  51. self.titleLabelCentered = isDirectory;
  52. _isDirectory = isDirectory;
  53. }
  54. - (void)setTitle:(NSString *)title
  55. {
  56. BOOL isDirOrCentered = self.isDirectory || [self isTitleLabelCentered];
  57. self.folderTitleLabel.text = self.titleLabel.text = title;
  58. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirOrCentered;
  59. self.folderTitleLabel.hidden = !isDirOrCentered;
  60. _title = title;
  61. }
  62. - (void)setSubtitle:(NSString *)subtitle
  63. {
  64. self.subtitleLabel.text = subtitle;
  65. }
  66. - (void)setIcon:(UIImage *)icon
  67. {
  68. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
  69. self.thumbnailView.image = icon;
  70. }
  71. - (void)setIconURL:(NSURL *)iconURL
  72. {
  73. _iconURL = iconURL;
  74. [self.thumbnailView setImageWithURL:iconURL];
  75. }
  76. - (void)setIsDownloadable:(BOOL)isDownloadable
  77. {
  78. self.downloadButton.hidden = !isDownloadable;
  79. }
  80. - (void)triggerDownload:(id)sender
  81. {
  82. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  83. [self.delegate triggerDownloadForCell:self];
  84. }
  85. - (void)prepareForReuse {
  86. [super prepareForReuse];
  87. [self.thumbnailView cancelLoading];
  88. self.isDownloadable = NO;
  89. self.subtitle = nil;
  90. self.title = nil;
  91. }
  92. + (CGFloat)heightOfCell
  93. {
  94. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  95. return 80.;
  96. return 68.;
  97. }
  98. @end
  99. @implementation VLCNetworkListCell (CellConfigurator)
  100. @dynamic couldBeAudioOnlyMedia;
  101. - (void)setThumbnailImage:(UIImage *)thumbnailImage {
  102. self.icon = thumbnailImage;
  103. }
  104. - (UIImage *)thumbnailImage {
  105. return self.icon;
  106. }
  107. - (void)setThumbnailURL:(NSURL *)thumbnailURL {
  108. self.iconURL = thumbnailURL;
  109. }
  110. - (NSURL *)thumbnailURL {
  111. return self.iconURL;
  112. }
  113. @end