VLCPlaylistViewController.m 20 KB

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