VLCPlaylistInterfaceController.m 5.1 KB

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