VLCPlaylistGridView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "AQGridView.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] / 1e6];
  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. /* ask user if s/he really wants to delete the media file */
  76. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DELETE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"DELETE_FILE_LONG", @""), self.mediaObject.title] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_DELETE", @""), nil];
  77. [alert show];
  78. }
  79. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  80. {
  81. if (buttonIndex == 1) {
  82. NSUInteger cellIndex = [self.gridView indexForCell:self];
  83. [self.gridView.delegate gridView:self.gridView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndex:cellIndex];
  84. }
  85. }
  86. @end