VLCPlaylistViewController.m 19 KB

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