VLCNetworkListCell.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // If a tableViewCell is highlighted, one needs to manualy set the opaque property
  34. if (@available(iOS 13.0, *)) {
  35. self.opaque = NO;
  36. }
  37. [self themeDidChange];
  38. [super awakeFromNib];
  39. }
  40. - (void)themeDidChange
  41. {
  42. self.titleLabel.textColor = PresentationTheme.current.colors.cellTextColor;
  43. self.subtitleLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor;
  44. self.folderTitleLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor;
  45. UIColor *backgroundColor = PresentationTheme.current.colors.background;
  46. if (@available(iOS 13.0, *)) {
  47. backgroundColor = UIColor.clearColor;
  48. }
  49. self.backgroundColor = backgroundColor;
  50. self.titleLabel.backgroundColor = backgroundColor;
  51. self.folderTitleLabel.backgroundColor = backgroundColor;
  52. self.subtitleLabel.backgroundColor = backgroundColor;
  53. }
  54. - (void)setTitleLabelCentered:(BOOL)titleLabelCentered
  55. {
  56. self.titleLabel.hidden = self.subtitleLabel.hidden = titleLabelCentered;
  57. self.folderTitleLabel.hidden = !titleLabelCentered;
  58. _titleLabelCentered = titleLabelCentered;
  59. }
  60. - (void)setIsDirectory:(BOOL)isDirectory
  61. {
  62. self.titleLabelCentered = isDirectory;
  63. _isDirectory = isDirectory;
  64. }
  65. - (void)setTitle:(NSString *)title
  66. {
  67. BOOL isDirOrCentered = self.isDirectory || [self isTitleLabelCentered];
  68. self.folderTitleLabel.text = self.titleLabel.text = title;
  69. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirOrCentered;
  70. self.folderTitleLabel.hidden = !isDirOrCentered;
  71. _title = title;
  72. }
  73. - (void)setSubtitle:(NSString *)subtitle
  74. {
  75. self.subtitleLabel.text = subtitle;
  76. }
  77. - (void)setIcon:(UIImage *)icon
  78. {
  79. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
  80. self.thumbnailView.image = icon;
  81. }
  82. - (void)setIconURL:(NSURL *)iconURL
  83. {
  84. _iconURL = iconURL;
  85. [self.thumbnailView setImageWithURL:iconURL];
  86. }
  87. - (void)setIsDownloadable:(BOOL)isDownloadable
  88. {
  89. self.downloadButton.hidden = !isDownloadable;
  90. }
  91. - (void)triggerDownload:(id)sender
  92. {
  93. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  94. [self.delegate triggerDownloadForCell:self];
  95. }
  96. - (void)prepareForReuse {
  97. [super prepareForReuse];
  98. [self.thumbnailView cancelLoading];
  99. self.isDownloadable = NO;
  100. self.subtitle = nil;
  101. self.title = nil;
  102. }
  103. + (CGFloat)heightOfCell
  104. {
  105. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  106. return 80.;
  107. return 68.;
  108. }
  109. @end
  110. @implementation VLCNetworkListCell (CellConfigurator)
  111. @dynamic couldBeAudioOnlyMedia;
  112. - (void)setThumbnailImage:(UIImage *)thumbnailImage {
  113. self.icon = thumbnailImage;
  114. }
  115. - (UIImage *)thumbnailImage {
  116. return self.icon;
  117. }
  118. - (void)setThumbnailURL:(NSURL *)thumbnailURL {
  119. self.iconURL = thumbnailURL;
  120. }
  121. - (NSURL *)thumbnailURL {
  122. return self.iconURL;
  123. }
  124. @end