VLCPlaylistInterfaceController.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <MediaLibraryKit/MediaLibraryKit.h>
  16. #import "VLCRowController.h"
  17. #import <MobileVLCKit/VLCTime.h>
  18. #import "VLCNotificationRelay.h"
  19. #import "VLCWatchTableController.h"
  20. #import "NSManagedObjectContext+refreshAll.h"
  21. #import "MLMediaLibrary+playlist.h"
  22. static NSString *const rowType = @"mediaRow";
  23. static NSString *const VLCDBUpdateNotification = @"VLCUpdateDataBase";
  24. static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.dbupdate";
  25. @interface VLCPlaylistInterfaceController()
  26. {
  27. CGRect _thumbnailSize;
  28. CGFloat _rowWidth;
  29. }
  30. @property (nonatomic, strong) VLCWatchTableController *tableController;
  31. @property (nonatomic) VLCLibraryMode libraryMode;
  32. @property (nonatomic) id groupObject;
  33. @end
  34. @implementation VLCPlaylistInterfaceController
  35. - (void)awakeWithContext:(id)context {
  36. [super awakeWithContext:context];
  37. MLMediaLibrary *mediaLibrary = [MLMediaLibrary sharedMediaLibrary];
  38. mediaLibrary.additionalPersitentStoreOptions = @{NSReadOnlyPersistentStoreOption : @YES};
  39. if (context == nil) {
  40. self.libraryMode = VLCLibraryModeAllFiles;
  41. [self setupMenuButtons];
  42. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
  43. self.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", nil);
  44. } else {
  45. self.groupObject = context;
  46. self.title = [self.groupObject name];
  47. self.libraryMode = VLCLibraryModeFolder;
  48. }
  49. [self addNowPlayingMenu];
  50. [[VLCNotificationRelay sharedRelay] addRelayRemoteName:VLCDBUpdateNotificationRemote toLocalName:VLCDBUpdateNotification];
  51. /* setup table view controller */
  52. VLCWatchTableController *tableController = [[VLCWatchTableController alloc] init];
  53. tableController.table = self.table;
  54. tableController.previousPageButton = self.previousButton;
  55. tableController.nextPageButton = self.nextButton;
  56. tableController.emptyLibraryInterfaceObjects = self.emptyLibraryGroup;
  57. tableController.pageSize = 20;
  58. tableController.rowType = rowType;
  59. tableController.configureRowControllerWithObjectBlock = ^(id controller, id object) {
  60. if ([controller respondsToSelector:@selector(configureWithMediaLibraryObject:)]) {
  61. [controller configureWithMediaLibraryObject:object];
  62. }
  63. };
  64. self.tableController = tableController;
  65. [self updateData];
  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. NSLog(@"we have class %@", [object class]);
  71. [self pushControllerWithName:@"tableViewController" context:object];
  72. [self updateUserActivity:@"org.videolan.vlc-ios.librarymode"
  73. userInfo:@{@"state" : @(self.libraryMode), @"folder":((NSManagedObject *)object).objectID.URIRepresentation}
  74. webpageURL:nil];
  75. } else {
  76. [self pushControllerWithName:@"detailInfo" context:object];
  77. }
  78. }
  79. - (IBAction)nextPagePressed {
  80. [self.tableController nextPageButtonPressed];
  81. }
  82. - (IBAction)previousPagePressed {
  83. [self.tableController previousPageButtonPressed];
  84. }
  85. - (void)setupMenuButtons {
  86. [self addMenuItemWithImageNamed:@"AllFiles" title: NSLocalizedString(@"LIBRARY_ALL_FILES", nil) action:@selector(switchToAllFiles)];
  87. [self addMenuItemWithImageNamed:@"MusicAlbums" title: NSLocalizedString(@"LIBRARY_MUSIC", nil) action:@selector(switchToMusic)];
  88. [self addMenuItemWithImageNamed:@"TVShows" title: NSLocalizedString(@"LIBRARY_SERIES", nil) action:@selector(switchToSeries)];
  89. }
  90. - (void)switchToAllFiles{
  91. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", nil);
  92. self.libraryMode = VLCLibraryModeAllFiles;
  93. [self updateData];
  94. }
  95. - (void)switchToMusic{
  96. self.title = NSLocalizedString(@"LIBRARY_MUSIC", nil);
  97. self.libraryMode = VLCLibraryModeAllAlbums;
  98. [self updateData];
  99. }
  100. - (void)switchToSeries{
  101. self.title = NSLocalizedString(@"LIBRARY_SERIES", nil);
  102. self.libraryMode = VLCLibraryModeAllSeries;
  103. [self updateData];
  104. }
  105. #pragma mark - data handling
  106. - (void)updateData {
  107. [super updateData];
  108. NSManagedObjectContext *moc = [(NSManagedObject *)self.tableController.objects.firstObject managedObjectContext];
  109. [moc vlc_refreshAllObjectsMerge:NO];
  110. self.tableController.objects = [self mediaArray];
  111. }
  112. - (void)setLibraryMode:(VLCLibraryMode)libraryMode
  113. {
  114. //should also handle diving into a folder
  115. [self updateUserActivity:@"org.videolan.vlc-ios.librarymode" userInfo:@{@"state" : @(libraryMode)} webpageURL:nil];
  116. _libraryMode = libraryMode;
  117. }
  118. - (NSArray *)mediaArray
  119. {
  120. id groupObject = self.groupObject;
  121. if (groupObject) {
  122. return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForGroupObject:groupObject];
  123. } else {
  124. return [[MLMediaLibrary sharedMediaLibrary] playlistArrayForLibraryMode:self.libraryMode];
  125. }
  126. }
  127. @end