VLCPlaylistGridView.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #import "VLCPlaylistViewController.h"
  11. @interface VLCPlaylistGridView (Hack)
  12. @property (nonatomic, retain) NSString *reuseIdentifier;
  13. @end
  14. @implementation VLCPlaylistGridView
  15. + (CGSize)preferredSize
  16. {
  17. return CGSizeMake(288, 220);
  18. }
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. _contentView = self;
  22. self.backgroundColor = [UIColor blackColor];
  23. self.reuseIdentifier = @"AQPlaylistCell";
  24. }
  25. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  26. {
  27. [super setEditing:editing animated:animated];
  28. self.removeMediaButton.hidden = !editing;
  29. }
  30. - (void)prepareForReuse
  31. {
  32. [super prepareForReuse];
  33. self.removeMediaButton.hidden = YES;
  34. }
  35. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  36. {
  37. [self _updatedDisplayedInformation];
  38. }
  39. - (void)setMediaObject:(MLFile *)mediaObject
  40. {
  41. if (_mediaObject != mediaObject) {
  42. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  43. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  44. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  45. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  46. [_mediaObject removeObserver:self forKeyPath:@"title"];
  47. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  48. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  49. [_mediaObject didHide];
  50. _mediaObject = mediaObject;
  51. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  52. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  53. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  54. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  55. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  56. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  57. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  58. [_mediaObject willDisplay];
  59. }
  60. [self _updatedDisplayedInformation];
  61. }
  62. - (void)_updatedDisplayedInformation
  63. {
  64. self.titleLabel.text = self.mediaObject.title;
  65. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %.2f MB", [VLCTime timeWithNumber:[self.mediaObject duration]], [self.mediaObject fileSizeInBytes] / 2e6];
  66. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  67. self.progressView.progress = self.mediaObject.lastPosition.floatValue;
  68. if (self.progressView.progress < 0.1f)
  69. self.progressView.hidden = YES;
  70. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  71. [self setNeedsDisplay];
  72. }
  73. - (IBAction)removeMedia:(id)sender
  74. {
  75. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  76. [appDelegate.playlistViewController removeMediaObject:self.mediaObject];
  77. }
  78. @end