VLCCloudStorageTableViewCell.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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:(DBFILESMetadata *)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:(GTLRDrive_File *)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 ([_dropboxFile isKindOfClass:[DBFILESFolderMetadata class]]) {
  61. self.folderTitleLabel.text = self.dropboxFile.name;
  62. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  63. self.folderTitleLabel.hidden = NO;
  64. self.downloadButton.hidden = YES;
  65. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  66. } else if ([_dropboxFile isKindOfClass:[DBFILESFileMetadata class]]) {
  67. DBFILESFileMetadata *file = (DBFILESFileMetadata *)_dropboxFile;
  68. self.titleLabel.text = file.name;
  69. self.subtitleLabel.text = (file.size.integerValue > 0) ? [NSByteCountFormatter stringFromByteCount:file.size.longLongValue countStyle:NSByteCountFormatterCountStyleFile] : @"";
  70. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  71. self.folderTitleLabel.hidden = YES;
  72. self.downloadButton.hidden = NO;
  73. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  74. }
  75. }
  76. #if TARGET_OS_IOS
  77. else if(_driveFile != nil){
  78. BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
  79. if (isDirectory) {
  80. self.folderTitleLabel.text = self.driveFile.name;
  81. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  82. self.folderTitleLabel.hidden = NO;
  83. } else {
  84. NSString *title = self.driveFile.name;
  85. self.titleLabel.text = title;
  86. self.subtitleLabel.text = (self.driveFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  87. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  88. self.folderTitleLabel.hidden = YES;
  89. if (_driveFile.thumbnailLink != nil) {
  90. [self.thumbnailView setImageWithURL:[NSURL URLWithString:_driveFile.thumbnailLink]];
  91. }
  92. }
  93. NSString *iconName = self.driveFile.iconLink;
  94. if (isDirectory) {
  95. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  96. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
  97. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  98. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
  99. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  100. } else {
  101. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  102. APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
  103. }
  104. }
  105. #endif
  106. else if(_boxFile != nil) {
  107. BOOL isDirectory = [self.boxFile.type isEqualToString:@"folder"];
  108. if (isDirectory) {
  109. self.folderTitleLabel.text = self.boxFile.name;
  110. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  111. self.folderTitleLabel.hidden = NO;
  112. } else {
  113. NSString *title = self.boxFile.name;
  114. self.titleLabel.text = title;
  115. self.subtitleLabel.text = (self.boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[self.boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  116. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  117. self.folderTitleLabel.hidden = YES;
  118. self.downloadButton.hidden = NO;
  119. }
  120. //TODO: correct thumbnails
  121. // if (_boxFile.modelID != nil) {
  122. // //this request needs a token in the header to work
  123. // 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];
  124. // [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
  125. // }
  126. //TODO:correct icons
  127. if (isDirectory) {
  128. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  129. } else {
  130. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  131. APLog(@"missing icon for type '%@'", self.boxFile);
  132. }
  133. } else if(_oneDriveFile != nil) {
  134. if (_oneDriveFile.isFolder) {
  135. self.downloadButton.hidden = YES;
  136. self.folderTitleLabel.text = self.oneDriveFile.name;
  137. self.titleLabel.hidden = self.subtitleLabel.hidden = YES;
  138. self.folderTitleLabel.hidden = NO;
  139. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  140. } else {
  141. self.downloadButton.hidden = NO;
  142. NSString *title = self.oneDriveFile.name;
  143. self.titleLabel.text = title;
  144. NSMutableString *subtitle = [[NSMutableString alloc] init];
  145. if (self.oneDriveFile.isAudio)
  146. self.thumbnailView.image = [UIImage imageNamed:@"audio"];
  147. else if (self.oneDriveFile.isVideo) {
  148. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  149. NSString *thumbnailURLString = _oneDriveFile.thumbnailURL;
  150. if ([thumbnailURLString isKindOfClass:[NSString class]]) {
  151. [self.thumbnailView setImageWithURL:[NSURL URLWithString:thumbnailURLString]];
  152. }
  153. } else
  154. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  155. if (self.oneDriveFile.size > 0) {
  156. [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[self.oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
  157. if (self.oneDriveFile.duration > 0) {
  158. VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
  159. [subtitle appendFormat:@" — %@", [time verboseStringValue]];
  160. }
  161. } else if (self.oneDriveFile.duration > 0) {
  162. VLCTime *time = [VLCTime timeWithNumber:self.oneDriveFile.duration];
  163. [subtitle appendString:[time verboseStringValue]];
  164. }
  165. self.subtitleLabel.text = subtitle;
  166. self.titleLabel.hidden = self.subtitleLabel.hidden = NO;
  167. self.folderTitleLabel.hidden = YES;
  168. }
  169. }
  170. [self setNeedsDisplay];
  171. }
  172. - (IBAction)triggerDownload:(id)sender
  173. {
  174. if ([self.delegate respondsToSelector:@selector(triggerDownloadForCell:)])
  175. [self.delegate triggerDownloadForCell:self];
  176. }
  177. + (CGFloat)heightOfCell
  178. {
  179. #if TARGET_OS_IOS
  180. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  181. return 80.;
  182. return 48.;
  183. #else
  184. return 107.;
  185. #endif
  186. }
  187. - (void)setIsDownloadable:(BOOL)isDownloadable
  188. {
  189. self.downloadButton.hidden = !isDownloadable;
  190. }
  191. @end