VLCLocalNetworkListCell.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*****************************************************************************
  2. * VLCLocalNetworkListCell.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 "VLCLocalNetworkListCell.h"
  14. #import "VLCStatusLabel.h"
  15. @implementation VLCLocalNetworkListCell
  16. + (VLCLocalNetworkListCell *)cellWithReuseIdentifier:(NSString *)ident
  17. {
  18. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCLocalNetworkListCell" owner:nil options:nil];
  19. NSAssert([nibContentArray count] == 1, @"meh");
  20. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCLocalNetworkListCell class]], @"meh meh");
  21. VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[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. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  31. self.titleLabel.highlightedTextColor = [UIColor blackColor];
  32. self.folderTitleLabel.highlightedTextColor = [UIColor blackColor];
  33. self.subtitleLabel.highlightedTextColor = [UIColor blackColor];
  34. self.statusLabel.highlightedTextColor = [UIColor blackColor];
  35. }
  36. }
  37. - (void)setIsDirectory:(BOOL)isDirectory
  38. {
  39. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirectory;
  40. self.folderTitleLabel.hidden = !isDirectory;
  41. _isDirectory = isDirectory;
  42. }
  43. - (void)setTitle:(NSString *)title
  44. {
  45. BOOL isDir = self.isDirectory;
  46. self.folderTitleLabel.text = self.titleLabel.text = title;
  47. self.titleLabel.hidden = self.subtitleLabel.hidden = isDir;
  48. self.folderTitleLabel.hidden = !isDir;
  49. _title = title;
  50. }
  51. - (void)setSubtitle:(NSString *)subtitle
  52. {
  53. self.subtitleLabel.text = subtitle;
  54. }
  55. - (void)setIcon:(UIImage *)icon
  56. {
  57. self.thumbnailView.image = icon;
  58. }
  59. - (void)setIconURL:(NSURL *)iconURL
  60. {
  61. _iconURL = iconURL;
  62. [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
  63. }
  64. - (void)_updateIconFromURL
  65. {
  66. NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
  67. UIImage* image = [[UIImage alloc] initWithData:imageData];
  68. [self setIcon:image];
  69. }
  70. - (void)setIsDownloadable:(BOOL)isDownloadable
  71. {
  72. self.downloadButton.hidden = !isDownloadable;
  73. }
  74. - (void)triggerDownload:(id)sender
  75. {
  76. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  77. [self.delegate triggerDownloadForCell:self];
  78. }
  79. + (CGFloat)heightOfCell
  80. {
  81. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  82. return 80.;
  83. return 68.;
  84. }
  85. @end