VLCPlaylistViewController.m 19 KB

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