VLCDetailInterfaceController.m 3.5 KB

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