VLCPlaylistViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. if (_libraryMode == VLCLibraryModeAllAlbums) {
  213. NSArray *rawAlbums = [MLAlbum allAlbums];
  214. _foundMedia = [[NSMutableArray alloc] init];
  215. for (MLAlbum *album in rawAlbums) {
  216. if (album.name.length > 0 && album.tracks.count > 0)
  217. [_foundMedia addObject:album];
  218. }
  219. } else if (_libraryMode == VLCLibraryModeAllSeries) {
  220. NSArray *rawShows = [MLShow allShows];
  221. _foundMedia = [[NSMutableArray alloc] init];
  222. for (MLShow *show in rawShows) {
  223. if (show.name.length > 0 && show.episodes.count > 0)
  224. [_foundMedia addObject:show];
  225. }
  226. } else
  227. _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];
  228. [self reloadViews];
  229. }
  230. - (void)reloadViews
  231. {
  232. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  233. [self.tableView reloadData];
  234. else
  235. [self.collectionView reloadData];
  236. [self _displayEmptyLibraryViewIfNeeded];
  237. }
  238. #pragma mark - Table View
  239. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  240. {
  241. return 1;
  242. }
  243. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  244. {
  245. return _foundMedia.count;
  246. }
  247. // Customize the appearance of table view cells.
  248. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  249. {
  250. static NSString *CellIdentifier = @"PlaylistCell";
  251. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  252. if (cell == nil)
  253. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  254. NSInteger row = indexPath.row;
  255. cell.mediaObject = _foundMedia[row];
  256. return cell;
  257. }
  258. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  259. {
  260. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  261. }
  262. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  263. {
  264. return YES;
  265. }
  266. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  267. {
  268. if (editingStyle == UITableViewCellEditingStyleDelete)
  269. [self removeMediaObject: _foundMedia[indexPath.row]];
  270. }
  271. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  272. {
  273. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  274. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  275. [self openMediaObject:selectedObject];
  276. }
  277. #pragma mark - table view gestures
  278. - (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
  279. {
  280. NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
  281. UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];
  282. CGRect frame = cell.frame;
  283. if (frame.size.height > 90.)
  284. frame.size.height = 90.;
  285. else if (recognizer.state == UIGestureRecognizerStateBegan)
  286. frame.size.height = 180;
  287. void (^animationBlock)() = ^() {
  288. cell.frame = frame;
  289. };
  290. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  291. cell.frame = frame;
  292. [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
  293. };
  294. NSTimeInterval animationDuration = .2;
  295. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  296. }
  297. #pragma mark - Collection View
  298. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  299. {
  300. return _foundMedia.count;
  301. }
  302. - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  303. {
  304. VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
  305. cell.mediaObject = _foundMedia[indexPath.row];
  306. cell.collectionView = _collectionView;
  307. [cell setEditing:self.editing animated:NO];
  308. return cell;
  309. }
  310. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  311. {
  312. if (SYSTEM_RUNS_IOS7_OR_LATER)
  313. return CGSizeMake(308.0, 174.0);
  314. return CGSizeMake(298.0, 220.0);
  315. }
  316. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  317. {
  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. return 10.0;
  323. }
  324. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  325. {
  326. return 10.0;
  327. }
  328. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  329. {
  330. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  331. [self openMediaObject:selectedObject];
  332. }
  333. #pragma mark - UI implementation
  334. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  335. {
  336. if (_libraryMode != VLCLibraryModeAllFiles)
  337. return;
  338. [super setEditing:editing animated:animated];
  339. UIBarButtonItem *editButton = self.editButtonItem;
  340. NSString *editImage = editing? @"doneButton": @"button";
  341. NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
  342. if (SYSTEM_RUNS_IOS7_OR_LATER)
  343. editButton.tintColor = [UIColor whiteColor];
  344. else {
  345. [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
  346. barMetrics:UIBarMetricsDefault];
  347. [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
  348. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  349. [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
  350. }
  351. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  352. NSArray *visibleCells = self.collectionView.visibleCells;
  353. [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  354. VLCPlaylistCollectionViewCell *aCell = (VLCPlaylistCollectionViewCell*)obj;
  355. [aCell setEditing:editing animated:animated];
  356. }];
  357. } else
  358. [self.tableView setEditing:editing animated:YES];
  359. }
  360. - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  361. {
  362. if (_libraryMode != VLCLibraryModeAllFiles)
  363. return UITableViewCellEditingStyleNone;
  364. return UITableViewCellEditingStyleDelete;
  365. }
  366. - (IBAction)leftButtonAction:(id)sender
  367. {
  368. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  369. if (self.isEditing)
  370. [self setEditing:NO animated:YES];
  371. }
  372. - (IBAction)backToAllItems:(id)sender
  373. {
  374. self.navigationItem.leftBarButtonItem = _menuButton;
  375. [self setLibraryMode:_libraryMode];
  376. }
  377. #pragma mark - coin coin
  378. - (void)setLibraryMode:(VLCLibraryMode)mode
  379. {
  380. _libraryMode = mode;
  381. if (_libraryMode == VLCLibraryModeAllAlbums)
  382. self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
  383. else if( _libraryMode == VLCLibraryModeAllSeries)
  384. self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
  385. else
  386. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  387. [self updateViewContents];
  388. }
  389. #pragma mark - autorotation
  390. // RootController is responsible for supporting interface orientation(iOS6.0+), i.e. navigation controller
  391. // so this will not work as intended without "voodoo magic"(UINavigationController category, subclassing, etc)
  392. /* introduced in iOS 6 */
  393. - (NSUInteger)supportedInterfaceOrientations {
  394. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  395. return UIInterfaceOrientationMaskAll;
  396. return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
  397. UIInterfaceOrientationMaskPortrait;
  398. }
  399. /* introduced in iOS 6 */
  400. - (BOOL)shouldAutorotate {
  401. return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (_foundMedia.count > 0);
  402. }
  403. @end