VLCPlaylistTableViewCell.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #import "VLCPlaylistTableViewCell.h"
  9. @implementation VLCPlaylistTableViewCell
  10. + (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  11. {
  12. NSArray *nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
  13. NSAssert([nibContentArray count] == 1, @"meh");
  14. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
  15. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
  16. return cell;
  17. }
  18. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  19. {
  20. [self _updatedDisplayedInformation];
  21. }
  22. - (void)setMediaObject:(MLFile *)mediaObject
  23. {
  24. if (_mediaObject != mediaObject) {
  25. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  26. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  27. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  28. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  29. [_mediaObject removeObserver:self forKeyPath:@"title"];
  30. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  31. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  32. [_mediaObject didHide];
  33. _mediaObject = mediaObject;
  34. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  35. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  36. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  37. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  38. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  39. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  40. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  41. [_mediaObject willDisplay];
  42. }
  43. [self _updatedDisplayedInformation];
  44. }
  45. - (void)_updatedDisplayedInformation
  46. {
  47. self.titleLabel.text = self.mediaObject.title;
  48. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %i MB", [VLCTime timeWithNumber:[self.mediaObject duration]], (int)([self.mediaObject fileSizeInBytes] / 1e6)];
  49. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  50. self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;
  51. self.progressIndicator.hidden = (self.progressIndicator.progress < 0.1f) ? YES : NO;
  52. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  53. [self setNeedsDisplay];
  54. }
  55. + (CGFloat)heightOfCell
  56. {
  57. return 80.;
  58. }
  59. @end