VLCCloudStorageTableViewCell.m 4.6 KB

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