VLCLocalNetworkListCell.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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)setTitleLabelCentered:(BOOL)titleLabelCentered
  38. {
  39. self.titleLabel.hidden = self.subtitleLabel.hidden = titleLabelCentered;
  40. self.folderTitleLabel.hidden = !titleLabelCentered;
  41. _titleLabelCentered = titleLabelCentered;
  42. }
  43. - (void)setIsDirectory:(BOOL)isDirectory
  44. {
  45. self.titleLabelCentered = isDirectory;
  46. _isDirectory = isDirectory;
  47. }
  48. - (void)setTitle:(NSString *)title
  49. {
  50. BOOL isDirOrCentered = self.isDirectory || [self isTitleLabelCentered];
  51. self.folderTitleLabel.text = self.titleLabel.text = title;
  52. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirOrCentered;
  53. self.folderTitleLabel.hidden = !isDirOrCentered;
  54. _title = title;
  55. }
  56. - (void)setSubtitle:(NSString *)subtitle
  57. {
  58. self.subtitleLabel.text = subtitle;
  59. }
  60. - (void)setIcon:(UIImage *)icon
  61. {
  62. self.thumbnailView.image = icon;
  63. }
  64. - (void)setIconURL:(NSURL *)iconURL
  65. {
  66. _iconURL = iconURL;
  67. [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
  68. }
  69. - (void)_updateIconFromURL
  70. {
  71. NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
  72. UIImage* image = [[UIImage alloc] initWithData:imageData];
  73. [self setIcon:image];
  74. }
  75. - (void)setIsDownloadable:(BOOL)isDownloadable
  76. {
  77. self.downloadButton.hidden = !isDownloadable;
  78. }
  79. - (void)triggerDownload:(id)sender
  80. {
  81. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  82. [self.delegate triggerDownloadForCell:self];
  83. }
  84. + (CGFloat)heightOfCell
  85. {
  86. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  87. return 80.;
  88. return 68.;
  89. }
  90. @end