VLCPlaylistViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. //
  2. // VLCMasterViewController.m
  3. // AspenProject
  4. //
  5. // Created by Felix Paul Kühne on 27.02.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCPlaylistViewController.h"
  11. #import "VLCMovieViewController.h"
  12. #import "VLCPlaylistTableViewCell.h"
  13. #import "VLCPlaylistCollectionViewCell.h"
  14. #import "UINavigationController+Theme.h"
  15. #import "NSString+SupportedMedia.h"
  16. #import "VLCBugreporter.h"
  17. #import "VLCAppDelegate.h"
  18. #import "UIBarButtonItem+Theme.h"
  19. #ifndef UIStatusBarStyleLightContent
  20. #define UIStatusBarStyleLightContent 1
  21. #endif
  22. @implementation EmptyLibraryView
  23. @end
  24. @interface VLCPlaylistViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> {
  25. NSMutableArray *_foundMedia;
  26. VLCLibraryMode _libraryMode;
  27. UIBarButtonItem *_menuButton;
  28. }
  29. @property (nonatomic, strong) UITableView *tableView;
  30. @property (nonatomic, strong) UICollectionView *collectionView;
  31. @property (nonatomic, strong) EmptyLibraryView *emptyLibraryView;
  32. @end
  33. @implementation VLCPlaylistViewController
  34. - (void)loadView {
  35. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  36. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  37. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  38. _tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  39. _tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  40. _tableView.delegate = self;
  41. _tableView.dataSource = self;
  42. self.view = _tableView;
  43. if (SYSTEM_RUNS_IN_THE_FUTURE) {
  44. UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableViewLongTouchGestureAction:)];
  45. [self.view addGestureRecognizer:gestureRecognizer];
  46. }
  47. } else {
  48. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  49. _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
  50. _collectionView.alwaysBounceVertical = YES;
  51. _collectionView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  52. _collectionView.delegate = self;
  53. _collectionView.dataSource = self;
  54. self.view = _collectionView;
  55. if (SYSTEM_RUNS_IN_THE_FUTURE)
  56. [_collectionView registerNib:[UINib nibWithNibName:@"VLCFuturePlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
  57. else
  58. [_collectionView registerNib:[UINib nibWithNibName:@"VLCPlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
  59. self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"libraryBackground"]];
  60. }
  61. _libraryMode = VLCLibraryModeAllFiles;
  62. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  63. self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
  64. _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
  65. _emptyLibraryView.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
  66. }
  67. #pragma mark -
  68. - (void)viewDidLoad
  69. {
  70. [super viewDidLoad];
  71. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  72. _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(leftButtonAction:)];
  73. /* After day 354 of the year, the usual VLC cone is replaced by another cone
  74. * wearing a Father Xmas hat.
  75. * Note: this icon doesn't represent an endorsement of The Coca-Cola Company
  76. * and should not be confused with the idea of religious statements or propagation there off
  77. */
  78. NSCalendar *gregorian =
  79. [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  80. NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
  81. if (dayOfYear >= 354)
  82. _menuButton.image = [UIImage imageNamed:@"vlc-xmas"];
  83. self.navigationItem.leftBarButtonItem = _menuButton;
  84. if (SYSTEM_RUNS_IN_THE_FUTURE)
  85. self.editButtonItem.tintColor = [UIColor whiteColor];
  86. else {
  87. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"button"]
  88. forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  89. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"]
  90. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  91. }
  92. _emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  93. _emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
  94. [_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
  95. }
  96. - (void)viewWillAppear:(BOOL)animated
  97. {
  98. [super viewWillAppear:animated];
  99. [self _displayEmptyLibraryViewIfNeeded];
  100. }
  101. - (void)viewDidAppear:(BOOL)animated
  102. {
  103. [super viewDidAppear:animated];
  104. if ([[MLMediaLibrary sharedMediaLibrary] libraryNeedsUpgrade]) {
  105. self.navigationItem.rightBarButtonItem = nil;
  106. self.navigationItem.leftBarButtonItem = nil;
  107. self.title = @"";
  108. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"UPGRADING_LIBRARY", @"");
  109. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = YES;
  110. [self.emptyLibraryView.activityIndicator startAnimating];
  111. self.emptyLibraryView.frame = self.view.bounds;
  112. [self.view addSubview:self.emptyLibraryView];
  113. [[MLMediaLibrary sharedMediaLibrary] setDelegate: self];
  114. [[MLMediaLibrary sharedMediaLibrary] performSelectorInBackground:@selector(upgradeLibrary) withObject:nil];
  115. return;
  116. }
  117. if (_foundMedia.count < 1)
  118. [self updateViewContents];
  119. [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
  120. if (SYSTEM_RUNS_IN_THE_FUTURE)
  121. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  122. }
  123. - (void)viewDidDisappear:(BOOL)animated
  124. {
  125. [super viewDidDisappear:animated];
  126. [[MLMediaLibrary sharedMediaLibrary] libraryDidDisappear];
  127. }
  128. - (BOOL)canBecomeFirstResponder
  129. {
  130. return YES;
  131. }
  132. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
  133. {
  134. if (motion == UIEventSubtypeMotionShake)
  135. [[VLCBugreporter sharedInstance] handleBugreportRequest];
  136. }
  137. - (void)openMediaObject:(NSManagedObject *)mediaObject
  138. {
  139. if ([mediaObject isKindOfClass:[MLAlbum class]]) {
  140. _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)mediaObject tracks] allObjects]];
  141. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  142. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
  143. self.title = [(MLAlbum*)mediaObject name];
  144. [self reloadViews];
  145. } else if ([mediaObject isKindOfClass:[MLShow class]]) {
  146. _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)mediaObject episodes] allObjects]];
  147. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  148. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
  149. self.title = [(MLShow*)mediaObject name];
  150. [self reloadViews];
  151. } else {
  152. if (!self.movieViewController)
  153. self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
  154. if ([mediaObject isKindOfClass:[MLFile class]])
  155. self.movieViewController.mediaItem = (MLFile *)mediaObject;
  156. else if ([mediaObject isKindOfClass:[MLAlbumTrack class]])
  157. self.movieViewController.mediaItem = [(MLAlbumTrack*)mediaObject files].anyObject;
  158. else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
  159. self.movieViewController.mediaItem = [(MLShowEpisode*)mediaObject files].anyObject;
  160. [self.navigationController pushViewController:self.movieViewController animated:YES];
  161. }
  162. }
  163. - (void)removeMediaObject:(MLFile *)mediaObject
  164. {
  165. NSFileManager *fileManager = [NSFileManager defaultManager];
  166. NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
  167. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  168. NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
  169. NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
  170. return ([obj rangeOfString:fileName].location != NSNotFound);
  171. }];
  172. unsigned int count = indexSet.count;
  173. NSString *additionalFilePath;
  174. NSUInteger currentIndex = [indexSet firstIndex];
  175. for (unsigned int x = 0; x < count; x++) {
  176. additionalFilePath = allfiles[currentIndex];
  177. if ([additionalFilePath isSupportedSubtitleFormat])
  178. [fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
  179. currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
  180. }
  181. [fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
  182. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  183. [self updateViewContents];
  184. }
  185. - (void)_displayEmptyLibraryViewIfNeeded
  186. {
  187. if (self.emptyLibraryView.superview)
  188. [self.emptyLibraryView removeFromSuperview];
  189. if (_foundMedia.count == 0) {
  190. self.emptyLibraryView.frame = self.view.bounds;
  191. [self.view addSubview:self.emptyLibraryView];
  192. }
  193. if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
  194. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  195. else
  196. self.navigationItem.rightBarButtonItem = nil;
  197. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  198. _tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine:
  199. UITableViewCellSeparatorStyleNone;
  200. }
  201. }
  202. - (void)libraryUpgradeComplete
  203. {
  204. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  205. self.navigationItem.leftBarButtonItem = _menuButton;
  206. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
  207. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  208. [self.emptyLibraryView.activityIndicator stopAnimating];
  209. [self.emptyLibraryView removeFromSuperview];
  210. [self updateViewContents];
  211. }
  212. - (void)libraryWasUpdated
  213. {
  214. NSLog(@"libraryWasUpdated");
  215. [self updateViewContents];
  216. }
  217. - (void)updateViewContents
  218. {
  219. if (_libraryMode == VLCLibraryModeAllAlbums) {
  220. NSArray *rawAlbums = [MLAlbum allAlbums];
  221. _foundMedia = [[NSMutableArray alloc] init];
  222. for (MLAlbum *album in rawAlbums) {
  223. if (album.name.length > 0 && album.tracks.count > 0)
  224. [_foundMedia addObject:album];
  225. }
  226. } else if (_libraryMode == VLCLibraryModeAllSeries) {
  227. NSArray *rawShows = [MLShow allShows];
  228. _foundMedia = [[NSMutableArray alloc] init];
  229. for (MLShow *show in rawShows) {
  230. if (show.name.length > 0 && show.episodes.count > 0)
  231. [_foundMedia addObject:show];
  232. }
  233. } else
  234. _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];
  235. [self reloadViews];
  236. }
  237. - (void)reloadViews
  238. {
  239. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  240. [self.tableView reloadData];
  241. else
  242. [self.collectionView reloadData];
  243. [self _displayEmptyLibraryViewIfNeeded];
  244. }
  245. #pragma mark - Table View
  246. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  247. {
  248. return 1;
  249. }
  250. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  251. {
  252. return _foundMedia.count;
  253. }
  254. // Customize the appearance of table view cells.
  255. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  256. {
  257. static NSString *CellIdentifier = @"PlaylistCell";
  258. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  259. if (cell == nil)
  260. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  261. NSInteger row = indexPath.row;
  262. cell.mediaObject = _foundMedia[row];
  263. return cell;
  264. }
  265. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  266. {
  267. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  268. }
  269. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  270. {
  271. return YES;
  272. }
  273. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  274. {
  275. if (editingStyle == UITableViewCellEditingStyleDelete)
  276. [self removeMediaObject: _foundMedia[indexPath.row]];
  277. }
  278. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  279. {
  280. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  281. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  282. [self openMediaObject:selectedObject];
  283. }
  284. #pragma mark - table view gestures
  285. - (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
  286. {
  287. NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
  288. UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];
  289. CGRect frame = cell.frame;
  290. if (frame.size.height > 90.)
  291. frame.size.height = 90.;
  292. else
  293. frame.size.height = 180;
  294. void (^animationBlock)() = ^() {
  295. cell.frame = frame;
  296. };
  297. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  298. cell.frame = frame;
  299. };
  300. NSTimeInterval animationDuration = .2;
  301. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  302. }
  303. #pragma mark - Collection View
  304. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  305. {
  306. return _foundMedia.count;
  307. }
  308. - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  309. {
  310. VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
  311. cell.mediaObject = _foundMedia[indexPath.row];
  312. cell.collectionView = _collectionView;
  313. [cell setEditing:self.editing animated:NO];
  314. return cell;
  315. }
  316. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  317. {
  318. if (SYSTEM_RUNS_IN_THE_FUTURE)
  319. return CGSizeMake(334.0, 191.0);
  320. return CGSizeMake(298.0, 220.0);
  321. }
  322. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  323. {
  324. if (SYSTEM_RUNS_IN_THE_FUTURE)
  325. return UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
  326. return UIEdgeInsetsMake(0.0, 34.0, 0.0, 34.0);
  327. }
  328. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  329. {
  330. if (SYSTEM_RUNS_IN_THE_FUTURE)
  331. return 0.0;
  332. return 10.0;
  333. }
  334. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  335. {
  336. if (SYSTEM_RUNS_IN_THE_FUTURE)
  337. return 0.0;
  338. return 10.0;
  339. }
  340. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  341. {
  342. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  343. [self openMediaObject:selectedObject];
  344. }
  345. #pragma mark - UI implementation
  346. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  347. {
  348. if (_libraryMode != VLCLibraryModeAllFiles)
  349. return;
  350. [super setEditing:editing animated:animated];
  351. UIBarButtonItem *editButton = self.editButtonItem;
  352. NSString *editImage = editing? @"doneButton": @"button";
  353. NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
  354. if (SYSTEM_RUNS_IN_THE_FUTURE)
  355. editButton.tintColor = [UIColor whiteColor];
  356. else {
  357. [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
  358. barMetrics:UIBarMetricsDefault];
  359. [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
  360. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  361. [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
  362. }
  363. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  364. NSArray *visibleCells = self.collectionView.visibleCells;
  365. [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  366. VLCPlaylistCollectionViewCell *aCell = (VLCPlaylistCollectionViewCell*)obj;
  367. [aCell setEditing:editing animated:animated];
  368. }];
  369. } else
  370. [self.tableView setEditing:editing animated:YES];
  371. }
  372. - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  373. {
  374. if (_libraryMode != VLCLibraryModeAllFiles)
  375. return UITableViewCellEditingStyleNone;
  376. return UITableViewCellEditingStyleDelete;
  377. }
  378. - (IBAction)leftButtonAction:(id)sender
  379. {
  380. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  381. }
  382. - (IBAction)backToAllItems:(id)sender
  383. {
  384. self.navigationItem.leftBarButtonItem = _menuButton;
  385. [self setLibraryMode:_libraryMode];
  386. }
  387. #pragma mark - coin coin
  388. - (void)openMovieFromURL:(NSURL *)url
  389. {
  390. if (!self.movieViewController)
  391. self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
  392. if (self.navigationController.topViewController != self.movieViewController)
  393. [self.navigationController pushViewController:self.movieViewController animated:YES];
  394. self.movieViewController.url = url;
  395. }
  396. - (void)setLibraryMode:(VLCLibraryMode)mode
  397. {
  398. _libraryMode = mode;
  399. if (_libraryMode == VLCLibraryModeAllAlbums)
  400. self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
  401. else if( _libraryMode == VLCLibraryModeAllSeries)
  402. self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
  403. else
  404. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  405. [self updateViewContents];
  406. }
  407. #pragma mark - autorotation
  408. /* deprecated in iOS 6 */
  409. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  410. {
  411. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  412. return YES;
  413. return (_foundMedia.count > 0) || toInterfaceOrientation == UIInterfaceOrientationPortrait;
  414. }
  415. // RootController is responsible for supporting interface orientation(iOS6.0+), i.e. navigation controller
  416. // so this will not work as intended without "voodoo magic"(UINavigationController category, subclassing, etc)
  417. /* introduced in iOS 6 */
  418. - (NSUInteger)supportedInterfaceOrientations {
  419. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  420. return UIInterfaceOrientationMaskAll;
  421. return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
  422. UIInterfaceOrientationMaskPortrait;
  423. }
  424. /* introduced in iOS 6 */
  425. - (BOOL)shouldAutorotate {
  426. return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (_foundMedia.count > 0);
  427. }
  428. @end