VLCPlaylistViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. //
  2. // VLCPlaylistViewController.m
  3. // VLC for iOS
  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. if (_libraryMode == VLCLibraryModeAllFiles)
  145. self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", @"");
  146. else
  147. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
  148. self.title = [(MLAlbum*)mediaObject name];
  149. [self reloadViews];
  150. } else if ([mediaObject isKindOfClass:[MLShow class]]) {
  151. _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)mediaObject episodes] allObjects]];
  152. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  153. if (_libraryMode == VLCLibraryModeAllFiles)
  154. self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", @"");
  155. else
  156. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
  157. self.title = [(MLShow*)mediaObject name];
  158. [self reloadViews];
  159. } else
  160. [(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaFromManagedObject:mediaObject];
  161. }
  162. - (void)removeMediaObject:(MLFile *)mediaObject
  163. {
  164. NSFileManager *fileManager = [NSFileManager defaultManager];
  165. NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
  166. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  167. NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
  168. NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
  169. return ([obj rangeOfString:fileName].location != NSNotFound);
  170. }];
  171. unsigned int count = indexSet.count;
  172. NSString *additionalFilePath;
  173. NSUInteger currentIndex = [indexSet firstIndex];
  174. for (unsigned int x = 0; x < count; x++) {
  175. additionalFilePath = allfiles[currentIndex];
  176. if ([additionalFilePath isSupportedSubtitleFormat])
  177. [fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
  178. currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
  179. }
  180. [fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
  181. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  182. [self updateViewContents];
  183. }
  184. - (void)_displayEmptyLibraryViewIfNeeded
  185. {
  186. if (self.emptyLibraryView.superview)
  187. [self.emptyLibraryView removeFromSuperview];
  188. if (_foundMedia.count == 0) {
  189. self.emptyLibraryView.frame = self.view.bounds;
  190. [self.view addSubview:self.emptyLibraryView];
  191. }
  192. if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
  193. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  194. else
  195. self.navigationItem.rightBarButtonItem = nil;
  196. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  197. _tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine:
  198. UITableViewCellSeparatorStyleNone;
  199. }
  200. }
  201. - (void)libraryUpgradeComplete
  202. {
  203. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  204. self.navigationItem.leftBarButtonItem = _menuButton;
  205. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
  206. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  207. [self.emptyLibraryView.activityIndicator stopAnimating];
  208. [self.emptyLibraryView removeFromSuperview];
  209. [self updateViewContents];
  210. }
  211. - (void)libraryWasUpdated
  212. {
  213. [self updateViewContents];
  214. }
  215. - (void)updateViewContents
  216. {
  217. _foundMedia = [[NSMutableArray alloc] init];
  218. /* add all albums */
  219. if (_libraryMode != VLCLibraryModeAllSeries) {
  220. NSArray *rawAlbums = [MLAlbum allAlbums];
  221. for (MLAlbum *album in rawAlbums) {
  222. if (album.name.length > 0 && album.tracks.count > 0)
  223. [_foundMedia addObject:album];
  224. }
  225. }
  226. if (_libraryMode == VLCLibraryModeAllAlbums) {
  227. [self reloadViews];
  228. return;
  229. }
  230. /* add all shows */
  231. NSArray *rawShows = [MLShow allShows];
  232. for (MLShow *show in rawShows) {
  233. if (show.name.length > 0 && show.episodes.count > 0)
  234. [_foundMedia addObject:show];
  235. }
  236. if (_libraryMode == VLCLibraryModeAllSeries) {
  237. [self reloadViews];
  238. return;
  239. }
  240. /* add all remaining files */
  241. NSArray *allFiles = [MLFile allFiles];
  242. for (MLFile *file in allFiles) {
  243. if (!file.isShowEpisode && !file.isAlbumTrack)
  244. [_foundMedia addObject:file];
  245. }
  246. [self reloadViews];
  247. }
  248. - (void)reloadViews
  249. {
  250. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  251. [self.tableView reloadData];
  252. else
  253. [self.collectionView reloadData];
  254. [self _displayEmptyLibraryViewIfNeeded];
  255. }
  256. #pragma mark - Table View
  257. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  258. {
  259. return 1;
  260. }
  261. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  262. {
  263. return _foundMedia.count;
  264. }
  265. // Customize the appearance of table view cells.
  266. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  267. {
  268. static NSString *CellIdentifier = @"PlaylistCell";
  269. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  270. if (cell == nil)
  271. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  272. NSInteger row = indexPath.row;
  273. cell.mediaObject = _foundMedia[row];
  274. return cell;
  275. }
  276. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  277. {
  278. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  279. }
  280. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  281. {
  282. return YES;
  283. }
  284. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  285. {
  286. if (editingStyle == UITableViewCellEditingStyleDelete)
  287. [self removeMediaObject: _foundMedia[indexPath.row]];
  288. }
  289. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  290. {
  291. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  292. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  293. [self openMediaObject:selectedObject];
  294. }
  295. #pragma mark - table view gestures
  296. - (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
  297. {
  298. NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
  299. UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];
  300. CGRect frame = cell.frame;
  301. if (frame.size.height > 90.)
  302. frame.size.height = 90.;
  303. else if (recognizer.state == UIGestureRecognizerStateBegan)
  304. frame.size.height = 180;
  305. void (^animationBlock)() = ^() {
  306. cell.frame = frame;
  307. };
  308. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  309. cell.frame = frame;
  310. [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
  311. };
  312. NSTimeInterval animationDuration = .2;
  313. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  314. }
  315. #pragma mark - Collection View
  316. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  317. {
  318. return _foundMedia.count;
  319. }
  320. - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  321. {
  322. VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
  323. cell.mediaObject = _foundMedia[indexPath.row];
  324. cell.collectionView = _collectionView;
  325. [cell setEditing:self.editing animated:NO];
  326. return cell;
  327. }
  328. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  329. {
  330. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  331. if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
  332. return CGSizeMake(341., 190.);
  333. else
  334. return CGSizeMake(384., 216.);
  335. }
  336. return CGSizeMake(298.0, 220.0);
  337. }
  338. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  339. {
  340. if (SYSTEM_RUNS_IOS7_OR_LATER)
  341. return UIEdgeInsetsMake(0., 0., 0., 0.);
  342. return UIEdgeInsetsMake(0.0, 34.0, 0.0, 34.0);
  343. }
  344. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  345. {
  346. if (SYSTEM_RUNS_IOS7_OR_LATER)
  347. return 0.;
  348. return 10.0;
  349. }
  350. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  351. {
  352. if (SYSTEM_RUNS_IOS7_OR_LATER)
  353. return 0.;
  354. return 10.0;
  355. }
  356. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  357. {
  358. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  359. [self openMediaObject:selectedObject];
  360. }
  361. #pragma mark - UI implementation
  362. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  363. {
  364. if (_libraryMode != VLCLibraryModeAllFiles)
  365. return;
  366. [super setEditing:editing animated:animated];
  367. UIBarButtonItem *editButton = self.editButtonItem;
  368. NSString *editImage = editing? @"doneButton": @"button";
  369. NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
  370. if (SYSTEM_RUNS_IOS7_OR_LATER)
  371. editButton.tintColor = [UIColor whiteColor];
  372. else {
  373. [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
  374. barMetrics:UIBarMetricsDefault];
  375. [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
  376. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  377. [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
  378. }
  379. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  380. NSArray *visibleCells = self.collectionView.visibleCells;
  381. [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  382. VLCPlaylistCollectionViewCell *aCell = (VLCPlaylistCollectionViewCell*)obj;
  383. [aCell setEditing:editing animated:animated];
  384. }];
  385. } else
  386. [self.tableView setEditing:editing animated:YES];
  387. }
  388. - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  389. {
  390. if (_libraryMode != VLCLibraryModeAllFiles)
  391. return UITableViewCellEditingStyleNone;
  392. return UITableViewCellEditingStyleDelete;
  393. }
  394. - (IBAction)leftButtonAction:(id)sender
  395. {
  396. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  397. if (self.isEditing)
  398. [self setEditing:NO animated:YES];
  399. }
  400. - (IBAction)backToAllItems:(id)sender
  401. {
  402. self.navigationItem.leftBarButtonItem = _menuButton;
  403. [self setLibraryMode:_libraryMode];
  404. }
  405. #pragma mark - coin coin
  406. - (void)setLibraryMode:(VLCLibraryMode)mode
  407. {
  408. _libraryMode = mode;
  409. if (_libraryMode == VLCLibraryModeAllAlbums)
  410. self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
  411. else if( _libraryMode == VLCLibraryModeAllSeries)
  412. self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
  413. else
  414. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  415. [self updateViewContents];
  416. }
  417. #pragma mark - autorotation
  418. // RootController is responsible for supporting interface orientation(iOS6.0+), i.e. navigation controller
  419. // so this will not work as intended without "voodoo magic"(UINavigationController category, subclassing, etc)
  420. /* introduced in iOS 6 */
  421. - (NSUInteger)supportedInterfaceOrientations {
  422. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  423. return UIInterfaceOrientationMaskAll;
  424. return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
  425. UIInterfaceOrientationMaskPortrait;
  426. }
  427. /* introduced in iOS 6 */
  428. - (BOOL)shouldAutorotate {
  429. return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (_foundMedia.count > 0);
  430. }
  431. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  432. [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  433. [self.collectionView.collectionViewLayout invalidateLayout];
  434. }
  435. @end