VLCDetailInterfaceController.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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)updateData {
  44. [super updateData];
  45. NSManagedObject *managedObject = self.managedObject;
  46. [managedObject.managedObjectContext refreshObject:managedObject mergeChanges:NO];
  47. [self configureWithFile:managedObject];
  48. }
  49. - (void)configureWithFile:(NSManagedObject *)managedObject {
  50. self.managedObject = managedObject;
  51. float playbackProgress = 0.0;
  52. if ([managedObject isKindOfClass:[MLShowEpisode class]]) {
  53. [self.titleLabel setText:((MLShowEpisode *)managedObject).name];
  54. } else if ([managedObject isKindOfClass:[MLFile class]]) {
  55. MLFile *file = (MLFile *)managedObject;
  56. self.durationLabel.text = [VLCTime timeWithNumber:file.duration].stringValue;
  57. playbackProgress = file.lastPosition.floatValue;
  58. [self.titleLabel setText:((MLFile *)file).title];
  59. } else if ([managedObject isKindOfClass:[MLAlbumTrack class]]) {
  60. [self.titleLabel setText:((MLAlbumTrack *)managedObject).title];
  61. } else {
  62. NSAssert(NO, @"check what filetype we try to show here and add it above");
  63. }
  64. BOOL playEnabled = managedObject != nil;
  65. self.playNowButton.enabled = playEnabled;
  66. [self.progressObject vlc_setProgress:playbackProgress hideForNoProgress:YES];
  67. /* do not block the main thread */
  68. [self performSelectorInBackground:@selector(loadThumbnailForManagedObject:) withObject:managedObject];
  69. }
  70. - (void)loadThumbnailForManagedObject:(NSManagedObject *)managedObject
  71. {
  72. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:managedObject];
  73. if (thumbnail) {
  74. [self.group performSelectorOnMainThread:@selector(setBackgroundImage:) withObject:thumbnail waitUntilDone:NO];
  75. }
  76. }
  77. - (IBAction)playNow {
  78. NSDictionary *dict = @{@"name":@"playFile",
  79. @"userInfo":@{
  80. @"URIRepresentation": self.managedObject.objectID.URIRepresentation.absoluteString,
  81. }
  82. };
  83. [self updateUserActivity:@"org.videolan.vlc-ios.playing" userInfo:@{@"playingmedia":self.managedObject.objectID.URIRepresentation} webpageURL:nil];
  84. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  85. [self showNowPlaying:nil];
  86. }];
  87. }
  88. @end