VLCPlaylistGridView.m 3.8 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. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCPlaylistGridView.h"
  11. #import "VLCAppDelegate.h"
  12. #import "AQGridView.h"
  13. @interface VLCPlaylistGridView (Hack)
  14. @property (nonatomic, retain) NSString *reuseIdentifier;
  15. @end
  16. @implementation VLCPlaylistGridView
  17. + (CGSize)preferredSize
  18. {
  19. return CGSizeMake(288, 220);
  20. }
  21. - (void)awakeFromNib {
  22. [super awakeFromNib];
  23. _contentView = self;
  24. self.backgroundColor = [UIColor clearColor];
  25. self.reuseIdentifier = @"AQPlaylistCell";
  26. }
  27. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  28. {
  29. [super setEditing:editing animated:animated];
  30. self.removeMediaButton.hidden = !editing;
  31. }
  32. - (void)prepareForReuse
  33. {
  34. [super prepareForReuse];
  35. self.removeMediaButton.hidden = YES;
  36. }
  37. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  38. {
  39. [self _updatedDisplayedInformation];
  40. }
  41. - (void)setMediaObject:(MLFile *)mediaObject
  42. {
  43. if (_mediaObject != mediaObject) {
  44. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  45. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  46. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  47. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  48. [_mediaObject removeObserver:self forKeyPath:@"title"];
  49. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  50. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  51. [_mediaObject didHide];
  52. _mediaObject = mediaObject;
  53. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  54. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  55. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  56. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  57. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  58. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  59. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  60. [_mediaObject willDisplay];
  61. }
  62. [self _updatedDisplayedInformation];
  63. }
  64. - (void)_updatedDisplayedInformation
  65. {
  66. self.titleLabel.text = self.mediaObject.title;
  67. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %i MB", [VLCTime timeWithNumber:[self.mediaObject duration]], (int)([self.mediaObject fileSizeInBytes] / 1e6)];
  68. self.thumbnailView.image = self.mediaObject.computedThumbnail;
  69. self.progressView.progress = self.mediaObject.lastPosition.floatValue;
  70. self.progressView.hidden = (self.progressView.progress < 0.1f) ? YES : NO;
  71. self.mediaIsUnreadView.hidden = !self.mediaObject.unread.intValue;
  72. [self setNeedsDisplay];
  73. }
  74. - (IBAction)removeMedia:(id)sender
  75. {
  76. /* ask user if s/he really wants to delete the media file */
  77. 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];
  78. [alert show];
  79. }
  80. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  81. {
  82. if (buttonIndex == 1) {
  83. NSUInteger cellIndex = [self.gridView indexForCell:self];
  84. [self.gridView.delegate gridView:self.gridView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndex:cellIndex];
  85. }
  86. }
  87. @end