VLCPlaylistTableViewCell.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 _updatedDisplayedInformation];
  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 _updatedDisplayedInformation];
  46. }
  47. - (void)_updatedDisplayedInformation
  48. {
  49. self.titleLabel.text = self.mediaObject.title;
  50. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %i MB", [VLCTime timeWithNumber:[self.mediaObject duration]], (int)([self.mediaObject fileSizeInBytes] / 1e6)];
  51. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  52. self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;
  53. self.progressIndicator.hidden = ((self.progressIndicator.progress < .1f) || (self.progressIndicator.progress > .95f)) ? YES : NO;
  54. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  55. [self setNeedsDisplay];
  56. }
  57. + (CGFloat)heightOfCell
  58. {
  59. return 80.;
  60. }
  61. @end