VLCPlaylistGridView.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. + (CGSize)preferredSize
  15. {
  16. return CGSizeMake(288, 220);
  17. }
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. _contentView = self;
  21. self.backgroundColor = [UIColor blackColor];
  22. self.reuseIdentifier = @"AQPlaylistCell";
  23. }
  24. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  25. {
  26. [super setEditing:editing animated:animated];
  27. self.removeMediaButton.hidden = !editing;
  28. }
  29. - (void)prepareForReuse
  30. {
  31. [super prepareForReuse];
  32. self.removeMediaButton.hidden = YES;
  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 removeObserver:self forKeyPath:@"unread"];
  48. [_mediaObject didHide];
  49. _mediaObject = mediaObject;
  50. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  51. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  52. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  53. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  54. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  55. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  56. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  57. [_mediaObject willDisplay];
  58. }
  59. [self _updatedDisplayedInformation];
  60. }
  61. - (void)_updatedDisplayedInformation
  62. {
  63. self.titleLabel.text = self.mediaObject.title;
  64. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 2e6];
  65. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  66. self.progressView.progress = self.mediaObject.lastPosition.floatValue;
  67. if (self.progressView.progress < 0.1f)
  68. self.progressView.hidden = YES;
  69. [self setNeedsDisplay];
  70. }
  71. - (IBAction)removeMedia:(id)sender
  72. {
  73. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  74. [appDelegate.playlistViewController removeMediaObject:self.mediaObject];
  75. }
  76. @end