VLCCloudStorageTableViewCell.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. @interface VLCCloudStorageTableViewCell ()
  15. {
  16. NSURL *_iconURL;
  17. }
  18. @end
  19. @implementation VLCCloudStorageTableViewCell
  20. + (VLCCloudStorageTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  21. {
  22. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCCloudStorageTableViewCell" owner:nil options:nil];
  23. NSAssert([nibContentArray count] == 1, @"meh");
  24. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCCloudStorageTableViewCell class]], @"meh meh");
  25. VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[nibContentArray lastObject];
  26. return cell;
  27. }
  28. - (void)setFileMetadata:(DBMetadata *)fileMetadata
  29. {
  30. if (fileMetadata != _fileMetadata)
  31. _fileMetadata = fileMetadata;
  32. [self _updatedDisplayedInformation];
  33. }
  34. - (void)setDriveFile:(GTLDriveFile *)driveFile
  35. {
  36. if (driveFile != _driveFile)
  37. _driveFile = driveFile;
  38. [self _updatedDisplayedInformation];
  39. }
  40. - (void)setBoxFile:(BoxItem *)boxFile
  41. {
  42. if (boxFile != _boxFile)
  43. _boxFile = boxFile;
  44. [self _updatedDisplayedInformation];
  45. }
  46. - (void)_updatedDisplayedInformation
  47. {
  48. if (_fileMetadata != nil) {
  49. if (self.fileMetadata.isDirectory) {
  50. self.folderTitleLabel.text = self.fileMetadata.filename;
  51. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  52. self.folderTitleLabel.hidden = NO;
  53. } else {
  54. self.titleLabel.text = self.fileMetadata.filename;
  55. self.subtitleLabel.text = (self.fileMetadata.totalBytes > 0) ? self.fileMetadata.humanReadableSize : @"";
  56. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  57. self.folderTitleLabel.hidden = YES;
  58. }
  59. NSString *iconName = self.fileMetadata.icon;
  60. if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
  61. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  62. self.downloadButton.hidden = YES;
  63. } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
  64. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  65. else if ([iconName isEqualToString:@"page_white_film"])
  66. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  67. else if ([iconName isEqualToString:@"page_white_sound"])
  68. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  69. else {
  70. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  71. APLog(@"missing icon for type '%@'", self.fileMetadata.icon);
  72. }
  73. } else if(_driveFile != nil){
  74. BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
  75. if (isDirectory) {
  76. self.folderTitleLabel.text = self.driveFile.title;
  77. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  78. self.folderTitleLabel.hidden = NO;
  79. } else {
  80. self.titleLabel.text = self.driveFile.title;
  81. self.subtitleLabel.text = (self.driveFile.fileSize > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.fileSize longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  82. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  83. self.folderTitleLabel.hidden = YES;
  84. }
  85. if (_driveFile.thumbnailLink != nil) {
  86. _iconURL = [NSURL URLWithString:_driveFile.thumbnailLink];
  87. [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
  88. }
  89. NSString *iconName = self.driveFile.iconLink;
  90. 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"]) {
  91. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  92. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
  93. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  94. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
  95. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  96. } else {
  97. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  98. APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
  99. }
  100. } else if(_boxFile != nil) {
  101. BOOL isDirectory = [self.boxFile.type isEqualToString:@"folder"];
  102. if (isDirectory) {
  103. self.folderTitleLabel.text = self.boxFile.name;
  104. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  105. self.folderTitleLabel.hidden = NO;
  106. } else {
  107. self.titleLabel.text = self.boxFile.name;
  108. self.subtitleLabel.text = (self.boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  109. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  110. self.folderTitleLabel.hidden = YES;
  111. }
  112. //TODO: correct thumbnails
  113. // if (_boxFile.modelID != nil) {
  114. // //this request needs a token in the header to work
  115. // NSString *thumbnailURLString = [NSString stringWithFormat:@"https://api.box.com/2.0/files/%@/thumbnail.png?min_height=32&min_width=32&max_height=64&max_width=64", _boxFile.modelID];
  116. // _iconURL = [NSURL URLWithString:thumbnailURLString];
  117. // [self performSelectorInBackground:@selector(_updateIconFromURL) withObject:@""];
  118. // }
  119. //TODO:correct icons
  120. if (isDirectory) {
  121. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  122. } else {
  123. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  124. APLog(@"missing icon for type '%@'", self.boxFile);
  125. }
  126. }
  127. //we don't have streaming for box yet
  128. self.downloadButton.hidden = _boxFile != nil;
  129. [self setNeedsDisplay];
  130. }
  131. - (void)_updateIconFromURL
  132. {
  133. NSData* imageData = [[NSData alloc]initWithContentsOfURL:_iconURL];
  134. UIImage* image = [[UIImage alloc] initWithData:imageData];
  135. if (image != nil) {
  136. self.thumbnailView.image = image;
  137. }
  138. }
  139. - (IBAction)triggerDownload:(id)sender
  140. {
  141. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  142. [self.delegate triggerDownloadForCell:self];
  143. }
  144. + (CGFloat)heightOfCell
  145. {
  146. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  147. return 80.;
  148. return 48.;
  149. }
  150. @end