VLCNetworkListCell.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. }
  35. - (void)setTitleLabelCentered:(BOOL)titleLabelCentered
  36. {
  37. self.titleLabel.hidden = self.subtitleLabel.hidden = titleLabelCentered;
  38. self.folderTitleLabel.hidden = !titleLabelCentered;
  39. _titleLabelCentered = titleLabelCentered;
  40. }
  41. - (void)setIsDirectory:(BOOL)isDirectory
  42. {
  43. self.titleLabelCentered = isDirectory;
  44. _isDirectory = isDirectory;
  45. }
  46. - (void)setTitle:(NSString *)title
  47. {
  48. BOOL isDirOrCentered = self.isDirectory || [self isTitleLabelCentered];
  49. self.folderTitleLabel.text = self.titleLabel.text = title;
  50. self.titleLabel.hidden = self.subtitleLabel.hidden = isDirOrCentered;
  51. self.folderTitleLabel.hidden = !isDirOrCentered;
  52. _title = title;
  53. }
  54. - (void)setSubtitle:(NSString *)subtitle
  55. {
  56. self.subtitleLabel.text = subtitle;
  57. }
  58. - (void)setIcon:(UIImage *)icon
  59. {
  60. self.thumbnailView.image = icon;
  61. }
  62. - (void)setIconURL:(NSURL *)iconURL
  63. {
  64. _iconURL = iconURL;
  65. [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
  66. }
  67. - (void)_updateIconFromURL
  68. {
  69. NSData* imageData = [[NSData alloc]initWithContentsOfURL:self.iconURL];
  70. if (!imageData)
  71. return;
  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