VLCDetailInterfaceController.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*****************************************************************************
  2. * VLCDetailInterfaceController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCDetailInterfaceController.h"
  13. #import "VLCTime.h"
  14. #import "VLCThumbnailsCache.h"
  15. #import "WKInterfaceObject+VLCProgress.h"
  16. #import "VLCWatchMessage.h"
  17. @interface VLCDetailInterfaceController ()
  18. @property (nonatomic, weak) NSManagedObject *managedObject;
  19. @end
  20. @implementation VLCDetailInterfaceController
  21. - (void)awakeWithContext:(id)context {
  22. [super awakeWithContext:context];
  23. self.title = NSLocalizedString(@"DETAIL", nil);
  24. self.playNowButton.accessibilityLabel = NSLocalizedString(@"PLAY_NOW", nil);
  25. self.titleLabel.accessibilityLabel = NSLocalizedString(@"TITLE", nil);
  26. self.durationLabel.accessibilityLabel = NSLocalizedString(@"DURATION", nil);
  27. [self addNowPlayingMenu];
  28. [self configureWithFile:context];
  29. }
  30. - (void)updateData {
  31. [super updateData];
  32. NSManagedObject *managedObject = self.managedObject;
  33. [managedObject.managedObjectContext refreshObject:managedObject mergeChanges:NO];
  34. [self configureWithFile:managedObject];
  35. }
  36. - (void)configureWithFile:(NSManagedObject *)managedObject {
  37. self.managedObject = managedObject;
  38. NSString *title = nil;
  39. NSString *durationString = nil;
  40. float playbackProgress = 0.0;
  41. if ([managedObject isKindOfClass:[MLShowEpisode class]]) {
  42. title = ((MLShowEpisode *)managedObject).name;
  43. } else if ([managedObject isKindOfClass:[MLFile class]]) {
  44. MLFile *file = (MLFile *)managedObject;
  45. durationString = [VLCTime timeWithNumber:file.duration].stringValue;
  46. playbackProgress = file.lastPosition.floatValue;
  47. title = ((MLFile *)file).title;
  48. } else if ([managedObject isKindOfClass:[MLAlbumTrack class]]) {
  49. title = ((MLAlbumTrack *)managedObject).title;
  50. } else {
  51. NSAssert(NO, @"check what filetype we try to show here and add it above");
  52. }
  53. BOOL playEnabled = managedObject != nil;
  54. self.playNowButton.enabled = playEnabled;
  55. self.mediaTitle = title;
  56. self.mediaDuration = durationString;
  57. self.playbackProgress = playbackProgress;
  58. /* do not block the main thread */
  59. [self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];
  60. }
  61. - (void)loadThumbnailForManagedObject:(NSManagedObject *)managedObject
  62. {
  63. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:managedObject];
  64. if (thumbnail) {
  65. [self.group performSelectorOnMainThread:@selector(setBackgroundImage:) withObject:thumbnail waitUntilDone:NO];
  66. }
  67. }
  68. - (IBAction)playNow {
  69. id payload = self.managedObject.objectID.URIRepresentation.absoluteString;
  70. NSDictionary *dict = [VLCWatchMessage messageDictionaryForName:@"playFile"
  71. payload:payload];
  72. [self updateUserActivity:@"org.videolan.vlc-ios.playing" userInfo:@{@"playingmedia":self.managedObject.objectID.URIRepresentation} webpageURL:nil];
  73. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  74. [self showNowPlaying:nil];
  75. }];
  76. }
  77. - (void)setMediaTitle:(NSString *)mediaTitle {
  78. if (![_mediaTitle isEqualToString:mediaTitle]) {
  79. _mediaTitle = [mediaTitle copy];
  80. self.titleLabel.text = mediaTitle;
  81. self.titleLabel.accessibilityValue = mediaTitle;
  82. self.titleLabel.hidden = mediaTitle.length == 0;
  83. }
  84. }
  85. - (void)setMediaDuration:(NSString *)mediaDuration {
  86. if (![_mediaDuration isEqualToString:mediaDuration]) {
  87. _mediaDuration = [mediaDuration copy];
  88. self.durationLabel.text = mediaDuration;
  89. self.durationLabel.hidden = mediaDuration.length == 0;
  90. self.durationLabel.accessibilityValue = mediaDuration;
  91. }
  92. }
  93. - (void)setPlaybackProgress:(CGFloat)playbackProgress {
  94. if (_playbackProgress != playbackProgress) {
  95. _playbackProgress = playbackProgress;
  96. [self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
  97. }
  98. }
  99. @end