VLCDetailInterfaceController.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.playNowButton setTitle:NSLocalizedString(@"Play now", nil)];
  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.playNowButton setTitle:NSLocalizedString(@"PLAY_NOW", nil)];
  36. [self setTitle:NSLocalizedString(@"DETAIL", nil)];
  37. // This method is called when watch view controller is about to be visible to user
  38. [super willActivate];
  39. }
  40. - (void)didDeactivate {
  41. // This method is called when watch view controller is no longer visible
  42. [super didDeactivate];
  43. }
  44. - (void)configureWithFile:(NSManagedObject *)file {
  45. self.file = file;
  46. if ([file isKindOfClass:[MLShowEpisode class]]) {
  47. [self.titleLabel setText:((MLShowEpisode *)file).name];
  48. } else if ([file isKindOfClass:[MLFile class]]) {
  49. self.durationLabel.text = [VLCTime timeWithNumber:((MLFile *)file).duration].stringValue;
  50. [self.titleLabel setText:((MLFile *)file).title];
  51. } else if ([file isKindOfClass:[MLAlbumTrack class]]) {
  52. [self.titleLabel setText:((MLAlbumTrack *)file).title];
  53. } else {
  54. NSAssert(NO, @"check what filetype we try to show here and add it above");
  55. }
  56. BOOL playEnabled = file != nil;
  57. self.playNowButton.enabled = playEnabled;
  58. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:file];
  59. self.imageView.hidden = thumbnail == nil;
  60. if (thumbnail) {
  61. self.imageView.image = thumbnail;
  62. }
  63. }
  64. - (IBAction)playNow {
  65. NSDictionary *dict = @{@"name":@"playFile",
  66. @"userInfo":@{
  67. @"URIRepresentation": self.file.objectID.URIRepresentation.absoluteString,
  68. }
  69. };
  70. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  71. [self showNowPlaying:nil];
  72. }];
  73. }
  74. @end