VLCNetworkListCell.m 4.5 KB

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