VLCCloudStorageCollectionViewCell.m 4.9 KB

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