VLCPlaylistViewController.m 20 KB

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