VLCCloudStorageTableViewCell.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // VLCCloudStorageTableViewCell.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 24.05.13.
  6. // Modified by Carola Nitz on 07.11.13
  7. // Copyright (c) 2013 VideoLAN. All rights reserved.
  8. //
  9. // Refer to the COPYING file of the official project for license.
  10. //
  11. #import "VLCCloudStorageTableViewCell.h"
  12. @implementation VLCCloudStorageTableViewCell
  13. + (VLCCloudStorageTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  14. {
  15. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCCloudStorageTableViewCell" owner:nil options:nil];
  16. NSAssert([nibContentArray count] == 1, @"meh");
  17. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCCloudStorageTableViewCell class]], @"meh meh");
  18. VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[nibContentArray lastObject];
  19. return cell;
  20. }
  21. - (void)setFileMetadata:(DBMetadata *)fileMetadata
  22. {
  23. if (fileMetadata != _fileMetadata)
  24. _fileMetadata = fileMetadata;
  25. [self _updatedDisplayedInformation];
  26. }
  27. - (void)setDriveFile:(GTLDriveFile *)driveFile
  28. {
  29. if (driveFile != _driveFile)
  30. _driveFile = driveFile;
  31. [self _updatedDisplayedInformation];
  32. }
  33. - (void)_updatedDisplayedInformation
  34. {
  35. if (_fileMetadata != nil) {
  36. if (self.fileMetadata.isDirectory) {
  37. self.folderTitleLabel.text = self.fileMetadata.filename;
  38. self.titleLabel.text = @"";
  39. self.subtitleLabel.text = @"";
  40. } else {
  41. self.titleLabel.text = self.fileMetadata.filename;
  42. self.subtitleLabel.text = (self.fileMetadata.totalBytes > 0) ? self.fileMetadata.humanReadableSize : @"";
  43. self.folderTitleLabel.text = @"";
  44. }
  45. NSString *iconName = self.fileMetadata.icon;
  46. if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
  47. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  48. self.downloadButton.hidden = YES;
  49. } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
  50. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  51. else if ([iconName isEqualToString:@"page_white_film"])
  52. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  53. else
  54. APLog(@"missing icon for type '%@'", self.fileMetadata.icon);
  55. } else if(_driveFile != nil){
  56. BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
  57. if (isDirectory) {
  58. self.folderTitleLabel.text = self.driveFile.title;
  59. self.titleLabel.text = @"";
  60. self.subtitleLabel.text = @"";
  61. } else {
  62. self.titleLabel.text = self.driveFile.title;
  63. self.subtitleLabel.text = (self.driveFile.fileSize > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.fileSize longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  64. self.folderTitleLabel.text = @"";
  65. }
  66. NSString *iconName = self.driveFile.iconLink;
  67. if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_shared_collection_list.png"] || [iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_collection_list.png"]) {
  68. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  69. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
  70. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  71. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
  72. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  73. } else {
  74. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  75. APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
  76. }
  77. }
  78. self.downloadButton.hidden = NO;
  79. [self setNeedsDisplay];
  80. }
  81. - (IBAction)triggerDownload:(id)sender
  82. {
  83. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  84. [self.delegate triggerDownloadForCell:self];
  85. }
  86. + (CGFloat)heightOfCell
  87. {
  88. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  89. return 80.;
  90. return 48.;
  91. }
  92. @end