VLCPlaylistViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*****************************************************************************
  2. * VLCPlaylistViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Tamas Timar <ttimar.vlc # gmail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCPlaylistViewController.h"
  15. #import "VLCMovieViewController.h"
  16. #import "VLCPlaylistTableViewCell.h"
  17. #import "VLCPlaylistCollectionViewCell.h"
  18. #import "UINavigationController+Theme.h"
  19. #import "NSString+SupportedMedia.h"
  20. #import "VLCBugreporter.h"
  21. #import "VLCAppDelegate.h"
  22. #import "UIBarButtonItem+Theme.h"
  23. #ifndef UIStatusBarStyleLightContent
  24. #define UIStatusBarStyleLightContent 1
  25. #endif
  26. @implementation EmptyLibraryView
  27. @end
  28. @interface VLCPlaylistViewController () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UITableViewDataSource, UITableViewDelegate, MLMediaLibrary> {
  29. NSMutableArray *_foundMedia;
  30. VLCLibraryMode _libraryMode;
  31. UIBarButtonItem *_menuButton;
  32. }
  33. @property (nonatomic, strong) UITableView *tableView;
  34. @property (nonatomic, strong) UICollectionView *collectionView;
  35. @property (nonatomic, strong) EmptyLibraryView *emptyLibraryView;
  36. @end
  37. @implementation VLCPlaylistViewController
  38. - (void)loadView {
  39. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  40. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  41. _tableView.backgroundColor = [UIColor colorWithWhite:.122 alpha:1.];
  42. _tableView.rowHeight = [VLCPlaylistTableViewCell heightOfCell];
  43. _tableView.separatorColor = [UIColor colorWithWhite:.122 alpha:1.];
  44. _tableView.delegate = self;
  45. _tableView.dataSource = self;
  46. self.view = _tableView;
  47. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  48. UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableViewLongTouchGestureAction:)];
  49. [self.view addGestureRecognizer:gestureRecognizer];
  50. }
  51. } else {
  52. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  53. _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
  54. _collectionView.alwaysBounceVertical = YES;
  55. _collectionView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  56. _collectionView.delegate = self;
  57. _collectionView.dataSource = self;
  58. self.view = _collectionView;
  59. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  60. [_collectionView registerNib:[UINib nibWithNibName:@"VLCFuturePlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
  61. self.view.backgroundColor = [UIColor colorWithWhite:.125 alpha:1.];
  62. } else {
  63. [_collectionView registerNib:[UINib nibWithNibName:@"VLCPlaylistCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PlaylistCell"];
  64. self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"libraryBackground"]];
  65. }
  66. }
  67. _libraryMode = VLCLibraryModeAllFiles;
  68. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  69. self.emptyLibraryView = [[[NSBundle mainBundle] loadNibNamed:@"VLCEmptyLibraryView" owner:self options:nil] lastObject];
  70. _emptyLibraryView.emptyLibraryLongDescriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
  71. _emptyLibraryView.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
  72. }
  73. #pragma mark -
  74. - (void)viewDidLoad
  75. {
  76. [super viewDidLoad];
  77. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  78. _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(leftButtonAction:)];
  79. /* After day 354 of the year, the usual VLC cone is replaced by another cone
  80. * wearing a Father Xmas hat.
  81. * Note: this icon doesn't represent an endorsement of The Coca-Cola Company
  82. * and should not be confused with the idea of religious statements or propagation there off
  83. */
  84. NSCalendar *gregorian =
  85. [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  86. NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
  87. if (dayOfYear >= 354)
  88. _menuButton.image = [UIImage imageNamed:@"vlc-xmas"];
  89. self.navigationItem.leftBarButtonItem = _menuButton;
  90. if (SYSTEM_RUNS_IOS7_OR_LATER)
  91. self.editButtonItem.tintColor = [UIColor whiteColor];
  92. else {
  93. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"button"]
  94. forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  95. [self.editButtonItem setBackgroundImage:[UIImage imageNamed:@"buttonHighlight"]
  96. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  97. }
  98. _emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  99. _emptyLibraryView.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
  100. [_emptyLibraryView.emptyLibraryLongDescriptionLabel sizeToFit];
  101. if (SYSTEM_RUNS_IOS7_OR_LATER)
  102. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  103. }
  104. - (void)viewWillAppear:(BOOL)animated
  105. {
  106. [super viewWillAppear:animated];
  107. [self _displayEmptyLibraryViewIfNeeded];
  108. }
  109. - (void)viewDidAppear:(BOOL)animated
  110. {
  111. [super viewDidAppear:animated];
  112. if ([[MLMediaLibrary sharedMediaLibrary] libraryNeedsUpgrade]) {
  113. self.navigationItem.rightBarButtonItem = nil;
  114. self.navigationItem.leftBarButtonItem = nil;
  115. self.title = @"";
  116. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"UPGRADING_LIBRARY", @"");
  117. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = YES;
  118. [self.emptyLibraryView.activityIndicator startAnimating];
  119. self.emptyLibraryView.frame = self.view.bounds;
  120. [self.view addSubview:self.emptyLibraryView];
  121. [[MLMediaLibrary sharedMediaLibrary] setDelegate: self];
  122. [[MLMediaLibrary sharedMediaLibrary] performSelectorInBackground:@selector(upgradeLibrary) withObject:nil];
  123. return;
  124. }
  125. if (_foundMedia.count < 1)
  126. [self updateViewContents];
  127. [[MLMediaLibrary sharedMediaLibrary] performSelector:@selector(libraryDidAppear) withObject:nil afterDelay:1.];
  128. }
  129. - (void)viewDidDisappear:(BOOL)animated
  130. {
  131. [super viewDidDisappear:animated];
  132. [[MLMediaLibrary sharedMediaLibrary] libraryDidDisappear];
  133. }
  134. - (BOOL)canBecomeFirstResponder
  135. {
  136. return YES;
  137. }
  138. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
  139. {
  140. if (motion == UIEventSubtypeMotionShake)
  141. [[VLCBugreporter sharedInstance] handleBugreportRequest];
  142. }
  143. - (void)openMediaObject:(NSManagedObject *)mediaObject
  144. {
  145. if ([mediaObject isKindOfClass:[MLAlbum class]]) {
  146. _foundMedia = [NSMutableArray arrayWithArray:[[(MLAlbum *)mediaObject tracks] allObjects]];
  147. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  148. if (_libraryMode == VLCLibraryModeAllFiles)
  149. self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", @"");
  150. else
  151. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_MUSIC", @"")];
  152. self.title = [(MLAlbum*)mediaObject name];
  153. [self reloadViews];
  154. } else if ([mediaObject isKindOfClass:[MLShow class]]) {
  155. _foundMedia = [NSMutableArray arrayWithArray:[[(MLShow *)mediaObject episodes] allObjects]];
  156. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedBackButtonWithTarget:self andSelector:@selector(backToAllItems:)];
  157. if (_libraryMode == VLCLibraryModeAllFiles)
  158. self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"BUTTON_BACK", @"");
  159. else
  160. [self.navigationItem.leftBarButtonItem setTitle:NSLocalizedString(@"LIBRARY_SERIES", @"")];
  161. self.title = [(MLShow*)mediaObject name];
  162. [self reloadViews];
  163. } else
  164. [(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaFromManagedObject:mediaObject];
  165. }
  166. - (void)removeMediaObject:(MLFile *)mediaObject
  167. {
  168. NSFileManager *fileManager = [NSFileManager defaultManager];
  169. NSString *folderLocation = [[[NSURL URLWithString:mediaObject.url] path] stringByDeletingLastPathComponent];
  170. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  171. NSString *fileName = [[[[NSURL URLWithString:mediaObject.url] path] lastPathComponent] stringByDeletingPathExtension];
  172. NSIndexSet *indexSet = [allfiles indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
  173. return ([obj rangeOfString:fileName].location != NSNotFound);
  174. }];
  175. unsigned int count = indexSet.count;
  176. NSString *additionalFilePath;
  177. NSUInteger currentIndex = [indexSet firstIndex];
  178. for (unsigned int x = 0; x < count; x++) {
  179. additionalFilePath = allfiles[currentIndex];
  180. if ([additionalFilePath isSupportedSubtitleFormat])
  181. [fileManager removeItemAtPath:[folderLocation stringByAppendingPathComponent:additionalFilePath] error:nil];
  182. currentIndex = [indexSet indexGreaterThanIndex:currentIndex];
  183. }
  184. [fileManager removeItemAtPath:[[NSURL URLWithString:mediaObject.url] path] error:nil];
  185. [[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
  186. [self updateViewContents];
  187. }
  188. - (void)_displayEmptyLibraryViewIfNeeded
  189. {
  190. if (self.emptyLibraryView.superview)
  191. [self.emptyLibraryView removeFromSuperview];
  192. if (_foundMedia.count == 0) {
  193. self.emptyLibraryView.frame = self.view.bounds;
  194. [self.view addSubview:self.emptyLibraryView];
  195. }
  196. if (_libraryMode == VLCLibraryModeAllFiles && _foundMedia.count > 0)
  197. self.navigationItem.rightBarButtonItem = self.editButtonItem;
  198. else
  199. self.navigationItem.rightBarButtonItem = nil;
  200. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  201. _tableView.separatorStyle = (_foundMedia.count > 0)? UITableViewCellSeparatorStyleSingleLine:
  202. UITableViewCellSeparatorStyleNone;
  203. }
  204. }
  205. - (void)libraryUpgradeComplete
  206. {
  207. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  208. self.navigationItem.leftBarButtonItem = _menuButton;
  209. self.emptyLibraryView.emptyLibraryLongDescriptionLabel.hidden = NO;
  210. self.emptyLibraryView.emptyLibraryLabel.text = NSLocalizedString(@"EMPTY_LIBRARY", @"");
  211. [self.emptyLibraryView.activityIndicator stopAnimating];
  212. [self.emptyLibraryView removeFromSuperview];
  213. [self updateViewContents];
  214. }
  215. - (void)libraryWasUpdated
  216. {
  217. [self updateViewContents];
  218. }
  219. - (void)updateViewContents
  220. {
  221. _foundMedia = [[NSMutableArray alloc] init];
  222. /* add all albums */
  223. if (_libraryMode != VLCLibraryModeAllSeries) {
  224. NSArray *rawAlbums = [MLAlbum allAlbums];
  225. for (MLAlbum *album in rawAlbums) {
  226. if (album.name.length > 0 && album.tracks.count > 0)
  227. [_foundMedia addObject:album];
  228. }
  229. }
  230. if (_libraryMode == VLCLibraryModeAllAlbums) {
  231. [self reloadViews];
  232. return;
  233. }
  234. /* add all shows */
  235. NSArray *rawShows = [MLShow allShows];
  236. for (MLShow *show in rawShows) {
  237. if (show.name.length > 0 && show.episodes.count > 0)
  238. [_foundMedia addObject:show];
  239. }
  240. if (_libraryMode == VLCLibraryModeAllSeries) {
  241. [self reloadViews];
  242. return;
  243. }
  244. /* add all remaining files */
  245. NSArray *allFiles = [MLFile allFiles];
  246. for (MLFile *file in allFiles) {
  247. if (!file.isShowEpisode && !file.isAlbumTrack)
  248. [_foundMedia addObject:file];
  249. else if (file.isShowEpisode) {
  250. if (file.showEpisode.show.episodes.count < 2)
  251. [_foundMedia addObject:file];
  252. } else if (file.isAlbumTrack) {
  253. if (file.albumTrack.album.tracks.count < 2)
  254. [_foundMedia addObject:file];
  255. }
  256. }
  257. [self reloadViews];
  258. }
  259. - (void)reloadViews
  260. {
  261. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  262. [self.tableView reloadData];
  263. else
  264. [self.collectionView reloadData];
  265. [self _displayEmptyLibraryViewIfNeeded];
  266. }
  267. #pragma mark - Table View
  268. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  269. {
  270. return 1;
  271. }
  272. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  273. {
  274. return _foundMedia.count;
  275. }
  276. // Customize the appearance of table view cells.
  277. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  278. {
  279. static NSString *CellIdentifier = @"PlaylistCell";
  280. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  281. if (cell == nil)
  282. cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
  283. NSInteger row = indexPath.row;
  284. cell.mediaObject = _foundMedia[row];
  285. return cell;
  286. }
  287. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  288. {
  289. cell.backgroundColor = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor colorWithWhite:.122 alpha:1.];
  290. }
  291. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  292. {
  293. return YES;
  294. }
  295. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  296. {
  297. if (editingStyle == UITableViewCellEditingStyleDelete)
  298. [self removeMediaObject: _foundMedia[indexPath.row]];
  299. }
  300. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  301. {
  302. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  303. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  304. [self openMediaObject:selectedObject];
  305. }
  306. #pragma mark - table view gestures
  307. - (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
  308. {
  309. NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
  310. UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];
  311. CGRect frame = cell.frame;
  312. if (frame.size.height > 90.)
  313. frame.size.height = 90.;
  314. else if (recognizer.state == UIGestureRecognizerStateBegan)
  315. frame.size.height = 180;
  316. void (^animationBlock)() = ^() {
  317. cell.frame = frame;
  318. };
  319. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  320. cell.frame = frame;
  321. [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
  322. };
  323. NSTimeInterval animationDuration = .2;
  324. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  325. }
  326. #pragma mark - Collection View
  327. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  328. {
  329. return _foundMedia.count;
  330. }
  331. - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  332. {
  333. VLCPlaylistCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlaylistCell" forIndexPath:indexPath];
  334. cell.mediaObject = _foundMedia[indexPath.row];
  335. cell.collectionView = _collectionView;
  336. [cell setEditing:self.editing animated:NO];
  337. return cell;
  338. }
  339. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  340. {
  341. if (SYSTEM_RUNS_IOS7_OR_LATER) {
  342. if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
  343. return CGSizeMake(341., 190.);
  344. else
  345. return CGSizeMake(384., 216.);
  346. }
  347. return CGSizeMake(298.0, 220.0);
  348. }
  349. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  350. {
  351. if (SYSTEM_RUNS_IOS7_OR_LATER)
  352. return UIEdgeInsetsMake(0., 0., 0., 0.);
  353. return UIEdgeInsetsMake(0.0, 34.0, 0.0, 34.0);
  354. }
  355. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  356. {
  357. if (SYSTEM_RUNS_IOS7_OR_LATER)
  358. return 0.;
  359. return 10.0;
  360. }
  361. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  362. {
  363. if (SYSTEM_RUNS_IOS7_OR_LATER)
  364. return 0.;
  365. return 10.0;
  366. }
  367. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  368. {
  369. NSManagedObject *selectedObject = _foundMedia[indexPath.row];
  370. [self openMediaObject:selectedObject];
  371. }
  372. #pragma mark - UI implementation
  373. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  374. {
  375. if (_libraryMode != VLCLibraryModeAllFiles)
  376. return;
  377. [super setEditing:editing animated:animated];
  378. UIBarButtonItem *editButton = self.editButtonItem;
  379. NSString *editImage = editing? @"doneButton": @"button";
  380. NSString *editImageHighlight = editing? @"doneButtonHighlight": @"buttonHighlight";
  381. if (SYSTEM_RUNS_IOS7_OR_LATER)
  382. editButton.tintColor = [UIColor whiteColor];
  383. else {
  384. [editButton setBackgroundImage:[UIImage imageNamed:editImage] forState:UIControlStateNormal
  385. barMetrics:UIBarMetricsDefault];
  386. [editButton setBackgroundImage:[UIImage imageNamed:editImageHighlight]
  387. forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
  388. [editButton setTitleTextAttributes: editing ? @{UITextAttributeTextShadowColor : [UIColor whiteColor], UITextAttributeTextColor : [UIColor blackColor]} : @{UITextAttributeTextShadowColor : [UIColor colorWithWhite:0. alpha:.37], UITextAttributeTextColor : [UIColor whiteColor]} forState:UIControlStateNormal];
  389. }
  390. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  391. NSArray *visibleCells = self.collectionView.visibleCells;
  392. [visibleCells enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  393. VLCPlaylistCollectionViewCell *aCell = (VLCPlaylistCollectionViewCell*)obj;
  394. [aCell setEditing:editing animated:animated];
  395. }];
  396. } else
  397. [self.tableView setEditing:editing animated:YES];
  398. }
  399. - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  400. {
  401. if (_libraryMode != VLCLibraryModeAllFiles)
  402. return UITableViewCellEditingStyleNone;
  403. return UITableViewCellEditingStyleDelete;
  404. }
  405. - (IBAction)leftButtonAction:(id)sender
  406. {
  407. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  408. if (self.isEditing)
  409. [self setEditing:NO animated:YES];
  410. }
  411. - (IBAction)backToAllItems:(id)sender
  412. {
  413. self.navigationItem.leftBarButtonItem = _menuButton;
  414. [self setLibraryMode:_libraryMode];
  415. }
  416. #pragma mark - coin coin
  417. - (void)setLibraryMode:(VLCLibraryMode)mode
  418. {
  419. _libraryMode = mode;
  420. if (_libraryMode == VLCLibraryModeAllAlbums)
  421. self.title = NSLocalizedString(@"LIBRARY_MUSIC", @"");
  422. else if( _libraryMode == VLCLibraryModeAllSeries)
  423. self.title = NSLocalizedString(@"LIBRARY_SERIES", @"");
  424. else
  425. self.title = NSLocalizedString(@"LIBRARY_ALL_FILES", @"");
  426. [self updateViewContents];
  427. }
  428. #pragma mark - autorotation
  429. // RootController is responsible for supporting interface orientation(iOS6.0+), i.e. navigation controller
  430. // so this will not work as intended without "voodoo magic"(UINavigationController category, subclassing, etc)
  431. /* introduced in iOS 6 */
  432. - (NSUInteger)supportedInterfaceOrientations {
  433. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  434. return UIInterfaceOrientationMaskAll;
  435. return (_foundMedia.count > 0)? UIInterfaceOrientationMaskAllButUpsideDown:
  436. UIInterfaceOrientationMaskPortrait;
  437. }
  438. /* introduced in iOS 6 */
  439. - (BOOL)shouldAutorotate {
  440. return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (_foundMedia.count > 0);
  441. }
  442. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  443. [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  444. [self.collectionView.collectionViewLayout invalidateLayout];
  445. }
  446. @end