VLCPlaylistGridView.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // VLCGridViewCell.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 11.04.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCPlaylistGridView.h"
  9. #import "VLCAppDelegate.h"
  10. @interface VLCPlaylistGridView (Hack)
  11. @property (nonatomic, retain) NSString *reuseIdentifier;
  12. @end
  13. @implementation VLCPlaylistGridView
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. _contentView = self;
  17. self.backgroundColor = [UIColor blackColor];
  18. self.reuseIdentifier = @"AQPlaylistCell";
  19. }
  20. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  21. {
  22. [super setEditing:editing animated:animated];
  23. self.removeMediaButton.hidden = !editing;
  24. }
  25. - (void)prepareForReuse
  26. {
  27. [super prepareForReuse];
  28. self.removeMediaButton.hidden = YES;
  29. }
  30. + (CGSize)preferredSize
  31. {
  32. return CGSizeMake(384, 243);
  33. }
  34. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  35. {
  36. [self _updatedDisplayedInformation];
  37. }
  38. - (void)setMediaObject:(MLFile *)mediaObject
  39. {
  40. if (_mediaObject != mediaObject) {
  41. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  42. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  43. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  44. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  45. [_mediaObject removeObserver:self forKeyPath:@"title"];
  46. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  47. [_mediaObject didHide];
  48. _mediaObject = mediaObject;
  49. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  50. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  51. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  52. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  53. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  54. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  55. [_mediaObject willDisplay];
  56. }
  57. [self _updatedDisplayedInformation];
  58. }
  59. - (void)_updatedDisplayedInformation
  60. {
  61. self.titleLabel.text = self.mediaObject.title;
  62. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 2e6];
  63. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  64. self.progressView.progress = self.mediaObject.lastPosition.floatValue;
  65. if (self.progressView.progress < 0.1f)
  66. self.progressView.hidden = YES;
  67. [self setNeedsDisplay];
  68. }
  69. - (IBAction)removeMedia:(id)sender
  70. {
  71. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  72. [appDelegate.playlistViewController removeMediaObject:self.mediaObject];
  73. }
  74. @end