VLCPlaylistInterfaceController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*****************************************************************************
  2. * VLCPlaylistInterfaceController.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. * Carola Nitz <caro # videolan.org>
  10. * Felix Paul Kühne <fkuehne # videolan.org>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCPlaylistInterfaceController.h"
  15. #import "VLCRowController.h"
  16. #import "VLCWatchTableController.h"
  17. #import "MLMediaLibrary+playlist.h"
  18. #import <WatchConnectivity/WatchConnectivity.h>
  19. #import "VLCWatchMessage.h"
  20. static NSString *const rowType = @"mediaRow";
  21. @interface VLCPlaylistInterfaceController()
  22. {
  23. CGRect _thumbnailSize;
  24. CGFloat _rowWidth;
  25. }
  26. @property (nonatomic, strong) VLCWatchTableController *tableController;
  27. @property (nonatomic) VLCLibraryMode libraryMode;
  28. @property (nonatomic) id groupObject;
  29. @end
  30. @implementation VLCPlaylistInterfaceController
  31. - (void)awakeWithContext:(id)context {
  32. [super awakeWithContext:context];
  33. if (context == nil) {
  34. self.libraryMode = VLCLibraryModeAllFiles;
  35. [self setupMenuButtons];
  36. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
  37. self.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", nil);
  38. } else {
  39. self.groupObject = context;
  40. self.title = [self.groupObject name];
  41. self.libraryMode = VLCLibraryModeFolder;
  42. }
  43. [self addNowPlayingMenu];
  44. /* setup table view controller */
  45. VLCWatchTableController *tableController = [[VLCWatchTableController alloc] init];
  46. tableController.table = self.table;
  47. tableController.previousPageButton = self.previousButton;
  48. tableController.nextPageButton = self.nextButton;
  49. tableController.emptyLibraryInterfaceObjects = self.emptyLibraryGroup;
  50. tableController.pageSize = 20;
  51. tableController.rowType = rowType;
  52. tableController.identifierKeyPath = @"objectID.URIRepresentation";
  53. tableController.configureRowControllerWithObjectBlock = ^(id controller, id object) {
  54. if ([controller respondsToSelector:@selector(configureWithMediaLibraryObject:)]) {
  55. [controller configureWithMediaLibraryObject:object];
  56. }
  57. };
  58. self.tableController = tableController;
  59. [self updateData];
  60. if (self.tableController.objects.count == 0) {
  61. NSDictionary *dict = [VLCWatchMessage messageDictionaryForName:VLCWatchMessageNameRequestDB];
  62. [[WCSession defaultSession] sendMessage:dict
  63. replyHandler:nil
  64. errorHandler:nil];
  65. }
  66. }
  67. - (void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
  68. id object = self.tableController.displayedObjects[rowIndex];
  69. if ([object isKindOfClass:[MLAlbum class]] || [object isKindOfClass:[MLLabel class]] || [object isKindOfClass:[MLShow class]]) {
  70. [self pushControllerWithName:@"tableViewController" context:object];
  71. NSString *folderRepresentation = [((NSManagedObject *)object).objectID.URIRepresentation absoluteString];
  72. NSDictionary *userDict = @{@"state" : @(self.libraryMode),
  73. @"folder" : folderRepresentation};
  74. [self invalidateUserActivity];
  75. [self updateUserActivity:@"org.videolan.vlc-ios.libraryselection"
  76. userInfo:userDict
  77. webpageURL:nil];
  78. } else {
  79. [self pushControllerWithName:@"detailInfo" context:object];
  80. }
  81. }
  82. - (IBAction)nextPagePressed {
  83. [self.tableController nextPageButtonPressed];
  84. }
  85. - (IBAction)previousPagePressed {
  86. [self.tableController previousPageButtonPressed];
  87. }
  88. - (void)setupMenuButtons {
  89. [self addMenuItemWithImageNamed:@"AllFiles" title: NSLocalizedString(@"LIBRARY_ALL_FILES", nil) action:@selector(switchToAllFiles)];
  90. [self addMenuItemWithImageNamed:@"MusicAlbums" title: NSLocalizedString(@"LIBRARY_MUSIC", nil) action:@selector(switchToMusic)];
  91. [self addMenuItemWithImageNamed:@"TVShows" title: NSLocalizedString(@"LIBRARY_SERIES", nil) action:@selector(switchToSeries)];
  92. }
  93. - (void)switchToAllFiles{
  94. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
  95. self.libraryMode = VLCLibraryModeAllFiles;
  96. [self updateData];
  97. }
  98. - (void)switchToMusic{
  99. self.title = NSLocalizedString(@"LIBRARY_MUSIC", nil);
  100. self.libraryMode = VLCLibraryModeAllAlbums;
  101. [self updateData];
  102. }
  103. - (void)switchToSeries{
  104. self.title = NSLocalizedString(@"LIBRARY_SERIES", nil);
  105. self.libraryMode = VLCLibraryModeAllSeries;
  106. [self updateData];
  107. }
  108. #pragma mark - data handling
  109. - (void)updateData {
  110. [super updateData];
  111. NSManagedObjectContext *moc = [(NSManagedObject *)self.tableController.objects.firstObject managedObjectContext];
  112. [moc refreshAllObjects];
  113. self.tableController.objects = [self mediaArray];
  114. }
  115. - (void)setLibraryMode:(VLCLibraryMode)libraryMode
  116. {
  117. //should also handle diving into a folder
  118. [self invalidateUserActivity];
  119. [self updateUserActivity:@"org.videolan.vlc-ios.librarymode" userInfo:@{@"state" : @(libraryMode)} webpageURL:nil];
  120. _libraryMode = libraryMode;
  121. }
  122. - (NSArray *)mediaArray
  123. {
  124. id groupObject = self.groupObject;
  125. if (groupObject) {
  126. return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForGroupObject:groupObject];
  127. } else {
  128. return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForLibraryMode:self.libraryMode];
  129. }
  130. }
  131. @end