VLCGoogleDriveTableViewCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*****************************************************************************
  2. * VLCGoogleDriveTableViewCell.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 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 "VLCGoogleDriveTableViewCell.h"
  14. @implementation VLCGoogleDriveTableViewCell
  15. + (VLCGoogleDriveTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  16. {
  17. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCGoogleDriveTableViewCell" owner:nil options:nil];
  18. NSAssert([nibContentArray count] == 1, @"meh");
  19. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCGoogleDriveTableViewCell class]], @"meh meh");
  20. VLCGoogleDriveTableViewCell *cell = (VLCGoogleDriveTableViewCell *)[nibContentArray lastObject];
  21. return cell;
  22. }
  23. - (void)setDriveFile:(GTLDriveFile *)driveFile
  24. {
  25. if (driveFile != _driveFile)
  26. _driveFile = driveFile;
  27. [self _updatedDisplayedInformation];
  28. }
  29. - (void)_updatedDisplayedInformation
  30. {
  31. BOOL isDirectory = [self.driveFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"];
  32. if (isDirectory) {
  33. self.folderTitleLabel.text = self.driveFile.title;
  34. self.titleLabel.text = @"";
  35. self.subtitleLabel.text = @"";
  36. } else {
  37. self.titleLabel.text = self.driveFile.title;
  38. self.subtitleLabel.text = (self.driveFile.fileSize > 0) ? [NSByteCountFormatter stringFromByteCount:[self.driveFile.fileSize longLongValue] countStyle:NSByteCountFormatterCountStyleFile]: @"";
  39. self.folderTitleLabel.text = @"";
  40. }
  41. NSString *iconName = self.driveFile.iconLink;
  42. if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_shared_collection_list.png"] || [iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_collection_list.png"]) {
  43. self.thumbnailView.image = [UIImage imageNamed:@"folder"];
  44. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_10_audio_list.png"]) {
  45. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  46. } else if ([iconName isEqualToString:@"https://ssl.gstatic.com/docs/doclist/images/icon_11_video_list.png"]) {
  47. self.thumbnailView.image = [UIImage imageNamed:@"movie"];
  48. } else {
  49. self.thumbnailView.image = [UIImage imageNamed:@"blank"];
  50. APLog(@"missing icon for type '%@'", self.driveFile.iconLink);
  51. }
  52. [self setNeedsDisplay];
  53. }
  54. + (CGFloat)heightOfCell
  55. {
  56. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  57. return 80.;
  58. return 48.;
  59. }
  60. @end