VLCNetworkListCell.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. @implementation VLCNetworkListCell
  16. + (VLCNetworkListCell *)cellWithReuseIdentifier:(NSString *)ident
  17. {
  18. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCNetworkListCell" owner:nil options:nil];
  19. NSAssert([nibContentArray count] == 1, @"meh");
  20. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCNetworkListCell class]], @"meh meh");
  21. VLCNetworkListCell *cell = (VLCNetworkListCell *)[nibContentArray lastObject];
  22. return cell;
  23. }
  24. - (void)awakeFromNib
  25. {
  26. self.titleLabel.text = @"";
  27. self.subtitleLabel.text = @"";
  28. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
  29. self.downloadButton.hidden = YES;
  30. self.titleLabel.highlightedTextColor = [UIColor blackColor];
  31. self.folderTitleLabel.highlightedTextColor = [UIColor blackColor];
  32. self.subtitleLabel.highlightedTextColor = [UIColor blackColor];
  33. self.statusLabel.highlightedTextColor = [UIColor blackColor];
  34. [super awakeFromNib];
  35. }
  36. - (void)setTitleLabelCentered:(BOOL)titleLabelCentered
  37. {
  38. self.titleLabel.hidden = self.subtitleLabel.hidden = titleLabelCentered;
  39. self.folderTitleLabel.hidden = !titleLabelCentered;
  40. _titleLabelCentered = titleLabelCentered;
  41. }
  42. - (void)setIsDirectory:(BOOL)isDirectory
  43. {
  44. self.titleLabelCentered = isDirectory;
  45. _isDirectory = isDirectory;
  46. }
  47. - (void)setTitle:(NSString *)title
  48. {
  49. BOOL isDirOrCentered = self.isDirectory || [self isTitleLabelCentered];
  50. self.folderTitleLabel.text = self.titleLabel.text = title;
  51. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirOrCentered;
  52. self.folderTitleLabel.hidden = !isDirOrCentered;
  53. _title = title;
  54. }
  55. - (void)setSubtitle:(NSString *)subtitle
  56. {
  57. self.subtitleLabel.text = subtitle;
  58. }
  59. - (void)setIcon:(UIImage *)icon
  60. {
  61. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFit;
  62. self.thumbnailView.image = icon;
  63. }
  64. - (void)setIconURL:(NSURL *)iconURL
  65. {
  66. _iconURL = iconURL;
  67. [self.thumbnailView setImageWithURL:iconURL];
  68. }
  69. - (void)setIsDownloadable:(BOOL)isDownloadable
  70. {
  71. self.downloadButton.hidden = !isDownloadable;
  72. }
  73. - (void)triggerDownload:(id)sender
  74. {
  75. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  76. [self.delegate triggerDownloadForCell:self];
  77. }
  78. - (void)prepareForReuse {
  79. [super prepareForReuse];
  80. [self.thumbnailView cancelLoading];
  81. self.isDownloadable = NO;
  82. self.subtitle = nil;
  83. self.title = nil;
  84. }
  85. + (CGFloat)heightOfCell
  86. {
  87. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  88. return 80.;
  89. return 68.;
  90. }
  91. @end
  92. @implementation VLCNetworkListCell (CellConfigurator)
  93. @dynamic couldBeAudioOnlyMedia;
  94. - (void)setThumbnailImage:(UIImage *)thumbnailImage {
  95. self.icon = thumbnailImage;
  96. }
  97. - (UIImage *)thumbnailImage {
  98. return self.icon;
  99. }
  100. - (void)setThumbnailURL:(NSURL *)thumbnailURL {
  101. self.iconURL = thumbnailURL;
  102. }
  103. - (NSURL *)thumbnailURL {
  104. return self.iconURL;
  105. }
  106. @end