VLCPlaylistViewController.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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 "VLCPlaylistGridView.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. #import "AQGridView.h"
  20. #ifndef UIStatusBarStyleLightContent
  21. #define UIStatusBarStyleLightContent 1
  22. #endif
  23. @implementation EmptyLibraryView
  24. @end
  25. @interface VLCPlaylistViewController () <AQGridViewDataSource, AQGridViewDelegate, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> {
  26. NSMutableArray *_foundMedia;
  27. VLCLibraryMode _libraryMode;
  28. UIBarButtonItem *_menuButton;
  29. }
  30. @end
  31. @implementation VLCPlaylistViewController
  32. - (void)loadView {
  33. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  34. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  35. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  36. _tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  37. _tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  38. _tableView.delegate = self;
  39. _tableView.dataSource = self;
  40. self.view = _tableView;
  41. } else {
  42. _gridView = [[AQGridView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  43. _gridView.separatorStyle = AQGridViewCellSeparatorStyleEmptySpace;
  44. _gridView.alwaysBounceVertical = YES;
  45. _gridView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  46. _gridView.delegate = self;
  47. _gridView.dataSource = self;
  48. _gridView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"libraryBackground"]];
  49. self.view = _gridView;
  50. }
  51. _libraryMode = VLCLibraryModeAllFiles;
  52. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  53. self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
  54. _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = UILineBreakModeWordWrap;
  55. _emptyLibraryView.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
  56. }
  57. #pragma mark -
  58. - (void)viewDidLoad
  59. {
  60. [super viewDidLoad];
  61. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  62. _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(leftButtonAction:)];
  63. /* After day 354 of the year, the usual VLC cone is replaced by another cone
  64. * wearing a Father Xmas hat.
  65. * Note: this icon doesn't represent an endorsement of The Coca-Cola Company
  66. * and should not be confused with the idea of religious statements or propagation there off
  67. */
  68. NSCalendar *gregorian =
  69. [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  70. NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
  71. if (dayOfYear >= 354)
  72. _menuButton.image = [UIImage imageNamed:@"vlc-xmas"];
  73. self.navigationItem.leftBarButtonItem = _menuButton;
  74. if (SYSTEM_RUNS_IN_THE_FUTURE)
  75. self.editButtonItem.tintColor = [UIColor whiteColor];
  76. else {
  77. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"button"]
  78. forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  79. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"]
  80. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  81. }
  82. _emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  83. _emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
  84. [_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
  85. }
  86. - (void)viewWillAppear:(BOOL)animated
  87. {
  88. [super viewWillAppear:animated];
  89. [self _displayEmptyLibraryViewIfNeeded];
  90. }
  91. - (void)viewDidAppear:(BOOL)animated
  92. {
  93. [super viewDidAppear:animated];
  94. if ([[MLMediaLibrary sharedMediaLibrary] libraryNeedsUpgrade]) {
  95. self.navigationItem.rightBarButtonItem = nil;
  96. self.navigationItem.leftBarButtonItem = nil;
  97. self.title = @"";
  98. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"UPGRADING_LIBRARY", @"");
  99. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = YES;
  100. [self.emptyLibraryView.activityIndicator startAnimating];
  101. self.emptyLibraryView.frame = self.view.bounds;
  102. [self.view addSubview:self.emptyLibraryView];
  103. [[MLMediaLibrary sharedMediaLibrary] setDelegate: self];
  104. [[MLMediaLibrary sharedMediaLibrary] performSelectorInBackground:@selector(upgradeLibrary) withObject:nil];
  105. return;
  106. }
  107. if (_foundMedia.count < 1)
  108. [self updateViewContents];
  109. [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
  110. if (SYSTEM_RUNS_IN_THE_FUTURE)
  111. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  112. }
  113. - (void)viewDidDisappear:(BOOL)animated
  114. {
  115. [super viewDidDisappear:animated];
  116. [[MLMediaLibrary sharedMediaLibrary] libraryDidDisappear];
  117. }
  118. - (BOOL)canBecomeFirstResponder
  119. {
  120. return YES;
  121. }
  122. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
  123. {
  124. if (motion == UIEventSubtypeMotionShake)
  125. [[VLCBugreporter sharedInstance] handleBugreportRequest];
  126. }
  127. - (void)removeMediaObject:(MLFile *)mediaObject
  128. {
  129. NSFileManager *fileManager = [NSFileManager defaultManager];
  130. NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
  131. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  132. NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
  133. NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
  134. return ([obj rangeOfString:fileName].location != NSNotFound);
  135. }];
  136. unsigned int count = indexSet.count;
  137. NSString *additionalFilePath;
  138. NSUInteger currentIndex = [indexSet firstIndex];
  139. for (unsigned int x = 0; x < count; x++) {
  140. additionalFilePath = allfiles[currentIndex];
  141. if ([additionalFilePath isSupportedSubtitleFormat])
  142. [fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
  143. currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
  144. }
  145. [fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
  146. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  147. [self updateViewContents];
  148. }
  149. - (void)_displayEmptyLibraryViewIfNeeded
  150. {
  151. if (self.emptyLibraryView.superview)
  152. [self.emptyLibraryView removeFromSuperview];
  153. if (_foundMedia.count == 0) {
  154. self.emptyLibraryView.frame = self.view.bounds;
  155. [self.view addSubview:self.emptyLibraryView];
  156. }
  157. if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
  158. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  159. else
  160. self.navigationItem.rightBarButtonItem = nil;
  161. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  162. _tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine:
  163. UITableViewCellSeparatorStyleNone;
  164. }
  165. }
  166. - (void)libraryUpgradeComplete
  167. {
  168. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  169. self.navigationItem.leftBarButtonItem = _menuButton;
  170. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
  171. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  172. [self.emptyLibraryView.activityIndicator stopAnimating];
  173. [self.emptyLibraryView removeFromSuperview];
  174. [self updateViewContents];
  175. }
  176. - (void)libraryWasUpdated
  177. {
  178. NSLog(@"libraryWasUpdated");
  179. [self updateViewContents];
  180. }
  181. - (void)updateViewContents
  182. {
  183. if (_libraryMode == VLCLibraryModeAllAlbums) {
  184. NSArray *rawAlbums = [MLAlbum allAlbums];
  185. _foundMedia = [[NSMutableArray alloc] init];
  186. for (MLAlbum *album in rawAlbums) {
  187. if (album.name.length > 0 && album.tracks.count > 0)
  188. [_foundMedia addObject:album];
  189. }
  190. } else if (_libraryMode == VLCLibraryModeAllSeries) {
  191. NSArray *rawShows = [MLShow allShows];
  192. _foundMedia = [[NSMutableArray alloc] init];
  193. for (MLShow *show in rawShows) {
  194. if (show.name.length > 0 && show.episodes.count > 0)
  195. [_foundMedia addObject:show];
  196. }
  197. } else
  198. _foundMedia = [NSMutableArray arrayWithArray:[MLFile allFiles]];
  199. [self reloadViews];
  200. }
  201. - (void)reloadViews
  202. {
  203. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  204. [self.tableView reloadData];
  205. else {
  206. [self.gridView reloadData];
  207. [self.gridView performSelector:@selector(reloadData) withObject:nil afterDelay:2.];
  208. }
  209. [self _displayEmptyLibraryViewIfNeeded];
  210. }
  211. #pragma mark - Table View
  212. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  213. {
  214. return 1;
  215. }
  216. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  217. {
  218. return _foundMedia.count;
  219. }
  220. // Customize the appearance of table view cells.
  221. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  222. {
  223. static NSString *CellIdentifier = @"PlaylistCell";
  224. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  225. if (cell == nil)
  226. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  227. NSInteger row = indexPath.row;
  228. cell.mediaObject = _foundMedia[row];
  229. return cell;
  230. }
  231. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  232. {
  233. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  234. }
  235. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  236. {
  237. return YES;
  238. }
  239. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  240. {
  241. if (editingStyle == UITableViewCellEditingStyleDelete)
  242. [self removeMediaObject: _foundMedia[indexPath.row]];
  243. }
  244. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  245. {
  246. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  247. NSManagedObject *currentObject = _foundMedia[indexPath.row];
  248. if ([currentObject isKindOfClass:[MLAlbum class]]) {
  249. _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)currentObject tracks] allObjects]];
  250. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  251. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
  252. self.title = [(MLAlbum*)currentObject name];
  253. [self reloadViews];
  254. } else if ([currentObject isKindOfClass:[MLShow class]]) {
  255. _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)currentObject episodes] allObjects]];
  256. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  257. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
  258. self.title = [(MLShow*)currentObject name];
  259. [self reloadViews];
  260. } else {
  261. if (!self.movieViewController)
  262. self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
  263. if ([currentObject isKindOfClass:[MLFile class]])
  264. self.movieViewController.mediaItem = (MLFile *)currentObject;
  265. else if ([currentObject isKindOfClass:[MLAlbumTrack class]])
  266. self.movieViewController.mediaItem = [(MLAlbumTrack*)currentObject files].anyObject;
  267. else if ([currentObject isKindOfClass:[MLShowEpisode class]])
  268. self.movieViewController.mediaItem = [(MLShowEpisode*)currentObject files].anyObject;
  269. [self.navigationController pushViewController:self.movieViewController animated:YES];
  270. }
  271. }
  272. #pragma mark - AQGridView
  273. - (NSUInteger)numberOfItemsInGridView:(AQGridView *)gridView
  274. {
  275. return _foundMedia.count;
  276. }
  277. - (AQGridViewCell *)gridView:(AQGridView *)gridView cellForItemAtIndex:(NSUInteger)index
  278. {
  279. static NSString *AQCellIdentifier = @"AQPlaylistCell";
  280. VLCPlaylistGridView *cell = (VLCPlaylistGridView *)[gridView dequeueReusableCellWithIdentifier:AQCellIdentifier];
  281. if (cell == nil) {
  282. cell = [[[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistGridView" owner:self options:nil] lastObject];
  283. cell.selectionStyle = AQGridViewCellSelectionStyleNone;
  284. cell.gridView = gridView;
  285. }
  286. cell.mediaObject = _foundMedia[index];
  287. return cell;
  288. }
  289. - (CGSize)portraitGridCellSizeForGridView:(AQGridView *)gridView
  290. {
  291. return [VLCPlaylistGridView preferredSize];
  292. }
  293. - (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index
  294. {
  295. [self.gridView deselectItemAtIndex:index animated:YES];
  296. NSManagedObject *currentObject = _foundMedia[index];
  297. if ([currentObject isKindOfClass:[MLAlbum class]]) {
  298. _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)currentObject tracks] allObjects]];
  299. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  300. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
  301. self.title = [(MLAlbum*)currentObject name];
  302. [self reloadViews];
  303. } else if ([currentObject isKindOfClass:[MLShow class]]) {
  304. _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)currentObject episodes] allObjects]];
  305. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  306. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
  307. self.title = [(MLShow*)currentObject name];
  308. [self reloadViews];
  309. } else {
  310. if (!self.movieViewController)
  311. self.movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
  312. if ([currentObject isKindOfClass:[MLFile class]])
  313. self.movieViewController.mediaItem = (MLFile *)currentObject;
  314. else if ([currentObject isKindOfClass:[MLAlbumTrack class]])
  315. self.movieViewController.mediaItem = [(MLAlbumTrack*)currentObject files].anyObject;
  316. else if ([currentObject isKindOfClass:[MLShowEpisode class]])
  317. self.movieViewController.mediaItem = [(MLShowEpisode*)currentObject files].anyObject;
  318. [self.navigationController pushViewController:self.movieViewController animated:YES];
  319. }
  320. }
  321. - (void)gridView:(AQGridView *)aGridView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndex:(NSUInteger)index
  322. {
  323. if (editingStyle == UITableViewCellEditingStyleDelete)
  324. [self removeMediaObject: _foundMedia[index]];
  325. }
  326. #pragma mark - UI implementation
  327. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  328. {
  329. if (_libraryMode != VLCLibraryModeAllFiles)
  330. return;
  331. [super setEditing:editing animated:animated];
  332. UIBarButtonItem *editButton = self.editButtonItem;
  333. NSString *editImage = editing? @"doneButton": @"button";
  334. NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
  335. if (SYSTEM_RUNS_IN_THE_FUTURE)
  336. editButton.tintColor = [UIColor whiteColor];
  337. else {
  338. [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
  339. barMetrics:UIBarMetricsDefault];
  340. [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
  341. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  342. [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
  343. }
  344. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  345. [self.gridView setEditing:editing];
  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