VLCCloudStorageTableViewCell.m 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*****************************************************************************
  2. * VLCCloudStorageTableViewCell.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 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. #import "VLCNetworkImageView.h"
  15. @implementation VLCCloudStorageTableViewCell
  16. + (VLCCloudStorageTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  17. {
  18. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCCloudStorageTableViewCell" owner:nil options:nil];
  19. NSAssert([nibContentArray count] == 1, @"meh");
  20. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCCloudStorageTableViewCell class]], @"meh meh");
  21. VLCCloudStorageTableViewCell *cell = (VLCCloudStorageTableViewCell *)[nibContentArray lastObject];
  22. cell.titleLabel.hidden = YES;
  23. cell.subtitleLabel.hidden = YES;
  24. cell.folderTitleLabel.hidden = YES;
  25. return cell;
  26. }
  27. - (void)setDropboxFile:(DBMetadata *)dropboxFile
  28. {
  29. if (dropboxFile != _dropboxFile)
  30. _dropboxFile = dropboxFile;
  31. [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
  32. withObject:nil waitUntilDone:NO];
  33. }
  34. #if TARGET_OS_IOS
  35. - (void)setDriveFile:(GTLDriveFile *)driveFile
  36. {
  37. if (driveFile != _driveFile)
  38. _driveFile = driveFile;
  39. [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
  40. withObject:nil waitUntilDone:NO];
  41. }
  42. #endif
  43. - (void)setBoxFile:(BoxItem *)boxFile
  44. {
  45. if (boxFile != _boxFile)
  46. _boxFile = boxFile;
  47. [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
  48. withObject:nil waitUntilDone:NO];
  49. }
  50. - (void)setOneDriveFile:(VLCOneDriveObject *)oneDriveFile
  51. {
  52. if (oneDriveFile != _oneDriveFile)
  53. _oneDriveFile = oneDriveFile;
  54. [self performSelectorOnMainThread:@selector(_updatedDisplayedInformation)
  55. withObject:nil waitUntilDone:NO];
  56. }
  57. - (void)_updatedDisplayedInformation
  58. {
  59. if (_dropboxFile != nil) {
  60. if (self.dropboxFile.isDirectory) {
  61. self.folderTitleLabel.text = self.dropboxFile.filename;
  62. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  63. self.folderTitleLabel.hidden = NO;
  64. } else {
  65. NSString *title = self.dropboxFile.filename;
  66. self.titleLabel.text = title;
  67. self.subtitleLabel.text = (self.dropboxFile.totalBytes > 0) ? self.dropboxFile.humanReadableSize : @"";
  68. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  69. self.folderTitleLabel.hidden = YES;
  70. }
  71. NSString *iconName = self.dropboxFile.icon;
  72. if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
  73. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  74. self.downloadButton.hidden = YES;
  75. } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
  76. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  77. else if ([iconName isEqualToString:@"page_white_film"])
  78. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  79. else if ([iconName isEqualToString:@"page_white_sound"])
  80. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  81. else {
  82. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  83. APLog(@"missing icon for type '%@'", self.dropboxFile.icon);
  84. }
  85. }
  86. #if TARGET_OS_IOS
  87. else if(_driveFile != nil){
  88. BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
  89. if (isDirectory) {
  90. self.folderTitleLabel.text = self.driveFile.name;
  91. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  92. self.folderTitleLabel.hidden = NO;
  93. } else {
  94. NSString *title = self.driveFile.name;
  95. self.titleLabel.text = title;
  96. self.subtitleLabel.text = (self.driveFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  97. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  98. self.folderTitleLabel.hidden = YES;
  99. if (_driveFile.thumbnailLink != nil) {
  100. [self.thumbnailView setImageWithURL:[NSURL URLWithString:_driveFile.thumbnailLink]];
  101. }
  102. }
  103. NSString *iconName = self.driveFile.iconLink;
  104. if (isDirectory) {
  105. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  106. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
  107. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  108. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
  109. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  110. } else {
  111. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  112. APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
  113. }
  114. }
  115. #endif
  116. else if(_boxFile != nil) {
  117. BOOL isDirectory = [self.boxFile.type isEqualToString:@"folder"];
  118. if (isDirectory) {
  119. self.folderTitleLabel.text = self.boxFile.name;
  120. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  121. self.folderTitleLabel.hidden = NO;
  122. } else {
  123. NSString *title = self.boxFile.name;
  124. self.titleLabel.text = title;
  125. self.subtitleLabel.text = (self.boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  126. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  127. self.folderTitleLabel.hidden = YES;
  128. self.downloadButton.hidden = NO;
  129. }
  130. //TODO: correct thumbnails
  131. // if (_boxFile.modelID != nil) {
  132. // //this request needs a token in the header to work
  133. // 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];
  134. // [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
  135. // }
  136. //TODO:correct icons
  137. if (isDirectory) {
  138. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  139. } else {
  140. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  141. APLog(@"missing icon for type '%@'", self.boxFile);
  142. }
  143. } else if(_oneDriveFile != nil) {
  144. if (_oneDriveFile.isFolder) {
  145. self.downloadButton.hidden = YES;
  146. self.folderTitleLabel.text = self.oneDriveFile.name;
  147. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  148. self.folderTitleLabel.hidden = NO;
  149. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  150. } else {
  151. self.downloadButton.hidden = NO;
  152. NSString *title = self.oneDriveFile.name;
  153. self.titleLabel.text = title;
  154. NSMutableString *subtitle = [[NSMutableString alloc] init];
  155. if (self.oneDriveFile.isAudio)
  156. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  157. else if (self.oneDriveFile.isVideo) {
  158. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  159. NSString *thumbnailURLString = _oneDriveFile.thumbnailURL;
  160. if ([thumbnailURLString isKindOfClass:[NSString class]]) {
  161. [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
  162. }
  163. } else
  164. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  165. if (self.oneDriveFile.size > 0) {
  166. [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[self.oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
  167. if (self.oneDriveFile.duration > 0) {
  168. VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
  169. [subtitle appendFormat:@" — %@", [time verboseStringValue]];
  170. }
  171. } else if (self.oneDriveFile.duration > 0) {
  172. VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
  173. [subtitle appendString:[time verboseStringValue]];
  174. }
  175. self.subtitleLabel.text = subtitle;
  176. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  177. self.folderTitleLabel.hidden = YES;
  178. }
  179. }
  180. [self setNeedsDisplay];
  181. }
  182. - (IBAction)triggerDownload:(id)sender
  183. {
  184. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  185. [self.delegate triggerDownloadForCell:self];
  186. }
  187. + (CGFloat)heightOfCell
  188. {
  189. #if TARGET_OS_IOS
  190. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  191. return 80.;
  192. return 48.;
  193. #else
  194. return 107.;
  195. #endif
  196. }
  197. - (void)setIsDownloadable:(BOOL)isDownloadable
  198. {
  199. self.downloadButton.hidden = !isDownloadable;
  200. }
  201. @end