VLCDetailInterfaceController.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. UIImage *thumbnail = [VLCThumbnailsCache thumbnailForManagedObject:managedObject];
  60. if (thumbnail) {
  61. [self.group setBackgroundImage:thumbnail];
  62. }
  63. BOOL noProgress = (playbackProgress == 0.0 || playbackProgress == 1.0);
  64. self.progressSeparator.hidden = noProgress;
  65. self.progressSeparator.width = floor(playbackProgress * CGRectGetWidth([WKInterfaceDevice currentDevice].screenBounds));
  66. }
  67. - (IBAction)playNow {
  68. NSDictionary *dict = @{@"name":@"playFile",
  69. @"userInfo":@{
  70. @"URIRepresentation": self.managedObject.objectID.URIRepresentation.absoluteString,
  71. }
  72. };
  73. [WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
  74. [self showNowPlaying:nil];
  75. }];
  76. }
  77. @end