VLCSidebarController.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*****************************************************************************
  2. * VLCSidebarController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCSidebarController.h"
  13. #import "GHRevealViewController.h"
  14. #import "VLCMenuTableViewController.h"
  15. @interface VLCSidebarController()
  16. {
  17. GHRevealViewController *_revealController;
  18. VLCMenuTableViewController *_menuViewController;
  19. UIViewController *_contentViewController;
  20. }
  21. @end
  22. @implementation VLCSidebarController
  23. + (instancetype)sharedInstance
  24. {
  25. static VLCSidebarController *sharedInstance = nil;
  26. static dispatch_once_t pred;
  27. dispatch_once(&pred, ^{
  28. sharedInstance = [VLCSidebarController new];
  29. });
  30. return sharedInstance;
  31. }
  32. - (instancetype)init
  33. {
  34. self = [super init];
  35. if (!self)
  36. return self;
  37. _revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
  38. _revealController.extendedLayoutIncludesOpaqueBars = YES;
  39. _revealController.edgesForExtendedLayout = UIRectEdgeAll;
  40. _menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
  41. _revealController.sidebarViewController = _menuViewController;
  42. return self;
  43. }
  44. #pragma mark - VC handling
  45. - (UIViewController *)fullViewController
  46. {
  47. return _revealController;
  48. }
  49. - (void)setContentViewController:(UIViewController *)contentViewController
  50. {
  51. contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  52. _revealController.contentViewController = contentViewController;
  53. }
  54. - (UIViewController *)contentViewController
  55. {
  56. return _revealController.contentViewController;
  57. }
  58. #pragma mark - actual work
  59. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition
  60. {
  61. [_menuViewController selectRowAtIndexPath:indexPath
  62. animated:NO
  63. scrollPosition:scrollPosition];
  64. }
  65. - (void)hideSidebar
  66. {
  67. [_revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];
  68. }
  69. - (void)toggleSidebar
  70. {
  71. [_revealController toggleSidebar:!_revealController.sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  72. }
  73. @end