VLCDetailInterfaceController.m 4.2 KB

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