VLCDetailInterfaceController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. @interface VLCDetailInterfaceController ()
  18. @property (nonatomic, weak) NSManagedObject *managedObject;
  19. @end
  20. @implementation VLCDetailInterfaceController
  21. - (instancetype)init
  22. {
  23. self = [super init];
  24. if (self) {
  25. [self setTitle:NSLocalizedString(@"DETAIL", nil)];
  26. }
  27. return self;
  28. }
  29. - (void)awakeWithContext:(id)context {
  30. [super awakeWithContext:context];
  31. [self addNowPlayingMenu];
  32. [self configureWithFile:context];
  33. }
  34. - (void)willActivate {
  35. [self setTitle:NSLocalizedString(@"DETAIL", nil)];
  36. // This method is called when watch view controller is about to be visible to user
  37. [super willActivate];
  38. }
  39. - (void)didDeactivate {
  40. // This method is called when watch view controller is no longer visible
  41. [super didDeactivate];
  42. }
  43. - (void)configureWithFile:(NSManagedObject *)managedObject {
  44. self.managedObject = managedObject;
  45. float playbackProgress = 0.0;
  46. if ([managedObject isKindOfClass:[MLShowEpisode class]]) {
  47. [self.titleLabel setText:((MLShowEpisode *)managedObject).name];
  48. } else if ([managedObject isKindOfClass:[MLFile class]]) {
  49. MLFile *file = (MLFile *)managedObject;
  50. self.durationLabel.text = [VLCTime timeWithNumber:file.duration].stringValue;
  51. playbackProgress = file.lastPosition.floatValue;
  52. [self.titleLabel setText:((MLFile *)file).title];
  53. } else if ([managedObject isKindOfClass:[MLAlbumTrack class]]) {
  54. [self.titleLabel setText:((MLAlbumTrack *)managedObject).title];
  55. } else {
  56. NSAssert(NO, @"check what filetype we try to show here and add it above");
  57. }
  58. BOOL playEnabled = managedObject != nil;
  59. self.playNowButton.enabled = playEnabled;
  60. [self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
  61. /* do not block the main thread */
  62. [self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];
  63. }
  64. - (void)loadThumbnailForManagedObject:(NSManagedObject *)managedObject
  65. {
  66. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:managedObject];
  67. if (thumbnail) {
  68. [self.group setBackgroundImage:thumbnail];
  69. }
  70. }
  71. - (IBAction)playNow {
  72. NSDictionary *dict = @{@"name":@"playFile",
  73. @"userInfo":@{
  74. @"URIRepresentation": self.managedObject.objectID.URIRepresentation.absoluteString,
  75. }
  76. };
  77. [self updateUserActivity:@"org.videolan.vlc-ios.playing" userInfo:@{@"playingmedia":self.managedObject.objectID.URIRepresentation} webpageURL:nil];
  78. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  79. [self showNowPlaying:nil];
  80. }];
  81. }
  82. @end