VLCRemoteBrowsingTVCell+CloudStorage.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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
  45. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  46. }
  47. }
  48. - (void)_updateBoxRepresentation:(BoxItem *)boxFile
  49. {
  50. if (boxFile != nil) {
  51. BOOL isDirectory = [boxFile.type isEqualToString:@"folder"];
  52. if (isDirectory) {
  53. self.isDirectory = YES;
  54. self.thumbnailImage = [UIImage imageNamed:@"folder"];
  55. } else {
  56. self.isDirectory = NO;
  57. self.subtitle = (boxFile.size > 0) ? [NSByteCountFormatter stringFromByteCount:[boxFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  58. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  59. }
  60. self.title = boxFile.name;
  61. }
  62. }
  63. - (void)_updateOneDriveRepresentation:(VLCOneDriveObject *)oneDriveFile
  64. {
  65. if (oneDriveFile != nil) {
  66. if (oneDriveFile.isFolder) {
  67. self.isDirectory = YES;
  68. self.thumbnailImage = [UIImage imageNamed:@"folder"];
  69. } else {
  70. self.isDirectory = NO;
  71. NSMutableString *subtitle = [[NSMutableString alloc] init];
  72. self.thumbnailImage = [UIImage imageNamed:@"blank"];
  73. if (oneDriveFile.isVideo) {
  74. NSString *thumbnailURLString = oneDriveFile.thumbnailURL;
  75. if (thumbnailURLString) {
  76. [self setThumbnailURL:[NSURL URLWithString:thumbnailURLString]];
  77. }
  78. }
  79. if (oneDriveFile.size > 0) {
  80. [subtitle appendString:[NSByteCountFormatter stringFromByteCount:[oneDriveFile.size longLongValue] countStyle:NSByteCountFormatterCountStyleFile]];
  81. if (oneDriveFile.duration > 0) {
  82. VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
  83. [subtitle appendFormat:@" — %@", [time verboseStringValue]];
  84. }
  85. } else if (oneDriveFile.duration > 0) {
  86. VLCTime *time = [VLCTime timeWithNumber:oneDriveFile.duration];
  87. [subtitle appendString:[time verboseStringValue]];
  88. }
  89. self.subtitle = subtitle;
  90. }
  91. self.title = oneDriveFile.name;
  92. }
  93. }
  94. @end