VLCDetailInterfaceController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 *file;
  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 *)file {
  43. self.file = file;
  44. if ([file isKindOfClass:[MLShowEpisode class]]) {
  45. [self.titleLabel setText:((MLShowEpisode *)file).name];
  46. } else if ([file isKindOfClass:[MLFile class]]) {
  47. self.durationLabel.text = [VLCTime timeWithNumber:((MLFile *)file).duration].stringValue;
  48. [self.titleLabel setText:((MLFile *)file).title];
  49. } else if ([file isKindOfClass:[MLAlbumTrack class]]) {
  50. [self.titleLabel setText:((MLAlbumTrack *)file).title];
  51. } else {
  52. NSAssert(NO, @"check what filetype we try to show here and add it above");
  53. }
  54. BOOL playEnabled = file != nil;
  55. self.playNowButton.enabled = playEnabled;
  56. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:file];
  57. if (thumbnail) {
  58. [self.group setBackgroundImage:thumbnail];
  59. }
  60. }
  61. - (IBAction)playNow {
  62. NSDictionary *dict = @{@"name":@"playFile",
  63. @"userInfo":@{
  64. @"URIRepresentation": self.file.objectID.URIRepresentation.absoluteString,
  65. }
  66. };
  67. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  68. [self showNowPlaying:nil];
  69. }];
  70. }
  71. @end