VLCPlaylistTableViewCell.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. CGRect frame = [cell frame];
  17. UIView *background = [[UIView alloc] initWithFrame:frame];
  18. background.backgroundColor = [UIColor colorWithWhite:.05 alpha:1.];
  19. cell.backgroundView = background;
  20. UIView *highlightedBackground = [[UIView alloc] initWithFrame:frame];
  21. highlightedBackground.backgroundColor = [UIColor colorWithWhite:.2 alpha:1.];
  22. cell.selectedBackgroundView = highlightedBackground;
  23. return cell;
  24. }
  25. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  26. {
  27. [self _updatedDisplayedInformation];
  28. }
  29. - (void)setMediaObject:(MLFile *)mediaObject
  30. {
  31. if (_mediaObject != mediaObject) {
  32. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  33. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  34. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  35. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  36. [_mediaObject removeObserver:self forKeyPath:@"title"];
  37. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  38. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  39. [_mediaObject didHide];
  40. _mediaObject = mediaObject;
  41. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  42. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  43. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  44. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  45. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  46. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  47. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  48. [_mediaObject willDisplay];
  49. }
  50. [self _updatedDisplayedInformation];
  51. }
  52. - (void)_updatedDisplayedInformation
  53. {
  54. self.titleLabel.text = self.mediaObject.title;
  55. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 2e6];
  56. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  57. self.progressIndicator.progress = self.mediaObject.lastPosition.floatValue;
  58. if (self.progressIndicator.progress < 0.1f)
  59. self.progressIndicator.hidden = YES;
  60. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  61. [self setNeedsDisplay];
  62. }
  63. + (CGFloat)heightOfCell
  64. {
  65. return 80.;
  66. }
  67. @end