VLCDropboxTableViewCell.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // VLCDropboxTableViewCell.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 24.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCDropboxTableViewCell.h"
  9. @implementation VLCDropboxTableViewCell
  10. + (VLCDropboxTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  11. {
  12. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCDropboxTableViewCell" owner:nil options:nil];
  13. NSAssert([nibContentArray count] == 1, @"meh");
  14. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCDropboxTableViewCell class]], @"meh meh");
  15. VLCDropboxTableViewCell *cell = (VLCDropboxTableViewCell *)[nibContentArray lastObject];
  16. CGRect frame = [cell frame];
  17. UIView *background = [[UIView alloc] initWithFrame:frame];
  18. background.backgroundColor = [UIColor colorWithWhite:.05 alpha:1.];
  19. cell.backgroundView = background;
  20. UIView *highlightedBackground = [[UIView alloc] initWithFrame:frame];
  21. highlightedBackground.backgroundColor = [UIColor colorWithWhite:.2 alpha:1.];
  22. cell.selectedBackgroundView = highlightedBackground;
  23. return cell;
  24. }
  25. - (void)setFileMetadata:(DBMetadata *)fileMetadata
  26. {
  27. if (fileMetadata != _fileMetadata)
  28. _fileMetadata = fileMetadata;
  29. [self _updatedDisplayedInformation];
  30. }
  31. - (void)_updatedDisplayedInformation
  32. {
  33. if (self.fileMetadata.isDirectory) {
  34. self.folderTitleLabel.text = self.fileMetadata.filename;
  35. self.titleLabel.text = @"";
  36. self.subtitleLabel.text = @"";
  37. } else {
  38. self.titleLabel.text = self.fileMetadata.filename;
  39. self.subtitleLabel.text = (self.fileMetadata.totalBytes > 0) ? self.fileMetadata.humanReadableSize : @"";
  40. self.folderTitleLabel.text = @"";
  41. }
  42. NSString *iconName = self.fileMetadata.icon;
  43. if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"])
  44. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  45. else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
  46. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  47. else if ([iconName isEqualToString:@"page_white_film"])
  48. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  49. else
  50. APLog(@"missing icon for type '%@'", self.fileMetadata.icon);
  51. [self setNeedsDisplay];
  52. }
  53. + (CGFloat)heightOfCell
  54. {
  55. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  56. return 80.;
  57. return 48.;
  58. }
  59. @end