VLCPlaylistInterfaceController.m 5.3 KB

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