VLCSidebarController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "VLCMenuTableViewController.h"
  14. #import "UIViewController+RESideMenu.h"
  15. #import "RESideMenu.h"
  16. #import "UIDevice+VLC.h"
  17. @interface VLCSidebarController() <RESideMenuDelegate>
  18. {
  19. RESideMenu *_sideMenuViewController;
  20. VLCMenuTableViewController *_menuViewController;
  21. UIViewController *_contentViewController;
  22. BOOL _menuVisible;
  23. }
  24. @end
  25. @implementation VLCSidebarController
  26. + (instancetype)sharedInstance
  27. {
  28. static VLCSidebarController *sharedInstance = nil;
  29. static dispatch_once_t pred;
  30. dispatch_once(&pred, ^{
  31. sharedInstance = [VLCSidebarController new];
  32. });
  33. return sharedInstance;
  34. }
  35. - (instancetype)init
  36. {
  37. self = [super init];
  38. if (!self)
  39. return self;
  40. _menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
  41. if ([UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionLeftToRight) {
  42. _sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:nil
  43. leftMenuViewController:_menuViewController
  44. rightMenuViewController:nil];
  45. } else {
  46. _sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:nil
  47. leftMenuViewController:nil
  48. rightMenuViewController:_menuViewController];
  49. }
  50. _sideMenuViewController.backgroundImage = [UIImage imageNamed:@"menu-background"];
  51. _sideMenuViewController.delegate = self;
  52. return self;
  53. }
  54. #pragma mark - VC handling
  55. - (UIViewController *)fullViewController
  56. {
  57. return _sideMenuViewController;
  58. }
  59. - (void)setContentViewController:(UIViewController *)contentViewController
  60. {
  61. contentViewController.view.backgroundColor = [UIColor VLCMenuBackgroundColor];
  62. _sideMenuViewController.contentViewController = contentViewController;
  63. }
  64. - (UIViewController *)contentViewController
  65. {
  66. return _sideMenuViewController.contentViewController;
  67. }
  68. #pragma mark - actual work
  69. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition
  70. {
  71. [_menuViewController selectRowAtIndexPath:indexPath
  72. animated:NO
  73. scrollPosition:scrollPosition];
  74. }
  75. - (void)hideSidebar
  76. {
  77. _menuVisible = NO;
  78. [_sideMenuViewController hideMenuViewController];
  79. }
  80. - (void)toggleSidebar
  81. {
  82. _menuVisible = YES;
  83. if ([UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionLeftToRight) {
  84. [_sideMenuViewController presentLeftMenuViewController];
  85. } else {
  86. [_sideMenuViewController presentRightMenuViewController];
  87. }
  88. }
  89. - (void)resizeContentView
  90. {
  91. if (_menuVisible) {
  92. [self hideSidebar];
  93. [self toggleSidebar];
  94. }
  95. }
  96. - (void)performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem
  97. {
  98. NSString *itemType = shortcutItem.type;
  99. if ([itemType isEqualToString:kVLCApplicationShortcutLocalLibrary]) {
  100. [self selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] scrollPosition:UITableViewScrollPositionNone];
  101. } else if ([itemType isEqualToString:kVLCApplicationShortcutLocalServers]) {
  102. [self selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] scrollPosition:UITableViewScrollPositionNone];
  103. } else if ([itemType isEqualToString:kVLCApplicationShortcutOpenNetworkStream]) {
  104. [self selectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:1] scrollPosition:UITableViewScrollPositionNone];
  105. } else if ([itemType isEqualToString:kVLCApplicationShortcutClouds]) {
  106. [self selectRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:1] scrollPosition:UITableViewScrollPositionNone];
  107. }
  108. }
  109. #pragma mark - RESideMenu Delegate
  110. - (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController
  111. {
  112. _menuVisible = NO;
  113. }
  114. @end