VLCCloudStorageTableViewCell.m 9.0 KB

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