VLCRemoteBrowsingTVCell+CloudStorage.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*****************************************************************************
  2. * VLCRemoteBrowsingTVCell+CloudStorage.m
  3. * VLC for tvOS
  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 "VLCRemoteBrowsingTVCell+CloudStorage.h"
  14. @implementation VLCRemoteBrowsingTVCell (CloudStorage)
  15. - (void)setDropboxFile:(DBMetadata *)dropboxFile
  16. {
  17. [self performSelectorOnMainThread:@selector(_updateDropboxRepresentation:)
  18. withObject:dropboxFile waitUntilDone:NO];
  19. }
  20. - (void)setBoxFile:(BoxItem *)boxFile
  21. {
  22. [self performSelectorOnMainThread:@selector(_updateBoxRepresentation:)
  23. withObject:boxFile waitUntilDone:NO];
  24. }
  25. - (void)setOneDriveFile:(VLCOneDriveObject *)oneDriveFile
  26. {
  27. [self performSelectorOnMainThread:@selector(_updateOneDriveRepresentation:)
  28. withObject:oneDriveFile waitUntilDone:NO];
  29. }
  30. - (void)_updateDropboxRepresentation:(DBMetadata *)dropboxFile
  31. {
  32. if (dropboxFile != nil) {
  33. if (dropboxFile.isDirectory) {
  34. self.isDirectory = YES;
  35. self.title = dropboxFile.filename;
  36. } else {
  37. self.isDirectory = NO;
  38. self.subtitle = (dropboxFile.totalBytes > 0) ? dropboxFile.humanReadableSize : @"";
  39. }
  40. self.title = dropboxFile.filename;
  41. NSString *iconName = dropboxFile.icon;
  42. if ([iconName isEqualToString:@"folder_user"] || [iconName isEqualToString:@"folder"] || [iconName isEqualToString:@"folder_public"] || [iconName isEqualToString:@"folder_photos"] || [iconName isEqualToString:@"package"]) {
  43. self.thumbnailImage = [UIImage imageNamed:@"folder"];
  44. } else if ([iconName isEqualToString:@"page_white"] || [iconName isEqualToString:@"page_white_text"])
  45. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  46. else if ([iconName isEqualToString:@"page_white_film"])
  47. self.thumbnailImage = [UIImage imageNamed:@"movie"];
  48. else if ([iconName isEqualToString:@"page_white_sound"])
  49. self.thumbnailImage = [UIImage imageNamed:@"audio"];
  50. else {
  51. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  52. APLog(@"missing icon for type '%@'", dropboxFile.icon);
  53. }
  54. }
  55. }
  56. - (void)_updateBoxRepresentation:(BoxItem *)boxFile
  57. {
  58. if (boxFile != nil) {
  59. BOOL isDirectory = [boxFile.type isEqualToString:@"folder"];
  60. if (isDirectory) {
  61. self.isDirectory = YES;
  62. self.thumbnailImage = [UIImage imageNamed:@"folder"];
  63. } else {
  64. self.isDirectory = NO;
  65. self.subtitle = (boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  66. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  67. }
  68. self.title = boxFile.name;
  69. }
  70. }
  71. - (void)_updateOneDriveRepresentation:(VLCOneDriveObject *)oneDriveFile
  72. {
  73. if (oneDriveFile != nil) {
  74. if (oneDriveFile.isFolder) {
  75. self.isDirectory = YES;
  76. self.thumbnailImage = [UIImage imageNamed:@"folder"];
  77. } else {
  78. self.isDirectory = NO;
  79. NSMutableString *subtitle = [[NSMutableString alloc] init];
  80. if (oneDriveFile.isAudio)
  81. self.thumbnailImage = [UIImage imageNamed:@"audio"];
  82. else if (oneDriveFile.isVideo) {
  83. self.thumbnailImage = [UIImage imageNamed:@"movie"];
  84. NSString *thumbnailURLString = oneDriveFile.thumbnailURL;
  85. if (thumbnailURLString) {
  86. [self setThumbnailURL:[NSURL URLWithString:thumbnailURLString]];
  87. }
  88. } else
  89. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  90. if (oneDriveFile.size > 0) {
  91. [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
  92. if (oneDriveFile.duration > 0) {
  93. VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
  94. [subtitle appendFormat:@" — %@", [time verboseStringValue]];
  95. }
  96. } else if (oneDriveFile.duration > 0) {
  97. VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
  98. [subtitle appendString:[time verboseStringValue]];
  99. }
  100. self.subtitle = subtitle;
  101. }
  102. self.title = oneDriveFile.name;
  103. }
  104. }
  105. @end