VLCRemoteBrowsingTVCell+CloudStorage.m 4.0 KB

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