VLCPlaylistTableViewCell.m 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // VLCPlaylistTableViewCell.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 01.04.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCPlaylistTableViewCell.h"
  11. @implementation VLCPlaylistTableViewCell
  12. + (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  13. {
  14. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
  15. NSAssert([nibContentArray count] == 1, @"meh");
  16. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
  17. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
  18. return cell;
  19. }
  20. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  21. {
  22. [self _updatedDisplayedInformationForKeyPath:keyPath];
  23. }
  24. - (void)setMediaObject:(MLFile *)mediaObject
  25. {
  26. if (_mediaObject != mediaObject) {
  27. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  28. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  29. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  30. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  31. [_mediaObject removeObserver:self forKeyPath:@"title"];
  32. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  33. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  34. [_mediaObject didHide];
  35. _mediaObject = mediaObject;
  36. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  37. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  38. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  39. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  40. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  41. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  42. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  43. [_mediaObject willDisplay];
  44. }
  45. [self _updatedDisplayedInformationForKeyPath:NULL];
  46. }
  47. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  48. {
  49. [super setEditing:editing animated:animated];
  50. [self _updatedDisplayedInformationForKeyPath:@"editing"];
  51. }
  52. - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
  53. {
  54. self.titleLabel.text = self.mediaObject.title;
  55. if (self.isEditing)
  56. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %i MB", [VLCTime timeWithNumber:[self.mediaObject duration]], (int)([self.mediaObject fileSizeInBytes] / 1e6)];
  57. else {
  58. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[self.mediaObject duration]]];
  59. if (self.mediaObject.videoTrack)
  60. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", [[self.mediaObject videoTrack] valueForKey:@"width"], [[self.mediaObject videoTrack] valueForKey:@"height"]];
  61. }
  62. if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath)
  63. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  64. self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;
  65. self.progressIndicator.hidden = ((self.progressIndicator.progress < .1f) || (self.progressIndicator.progress > .95f)) ? YES : NO;
  66. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  67. [self setNeedsDisplay];
  68. }
  69. + (CGFloat)heightOfCell
  70. {
  71. return 80.;
  72. }
  73. @end