VLCMenuTableViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*****************************************************************************
  2. * VLCMenuTableViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Jean-Romain Prévost <jr # 3on.fr>
  11. * Carola Nitz <nitz.carola # googlemail.com>
  12. * Tamas Timar <ttimar.vlc # gmail.com>
  13. * Pierre Sagaspe <pierre.sagaspe # me.com>
  14. *
  15. * Refer to the COPYING file of the official project for license.
  16. *****************************************************************************/
  17. #import "VLCMenuTableViewController.h"
  18. #import "VLCSidebarViewCell.h"
  19. #import <QuartzCore/QuartzCore.h>
  20. #import "VLCWiFiUploadTableViewCell.h"
  21. #import "VLCAppDelegate.h"
  22. #import "IASKAppSettingsViewController.h"
  23. #import "VLCServerListViewController.h"
  24. #import "VLCOpenNetworkStreamViewController.h"
  25. #import "VLCSettingsController.h"
  26. #import "VLCAboutViewController.h"
  27. #import "VLCLibraryViewController.h"
  28. #import "VLCBugreporter.h"
  29. #import "VLCCloudServicesTableViewController.h"
  30. #import "VLCNavigationController.h"
  31. #import "GHRevealViewController.h"
  32. #define ROW_HEIGHT 50
  33. static NSString *CellIdentifier = @"VLCMenuCell";
  34. static NSString *WiFiCellIdentifier = @"VLCMenuWiFiCell";
  35. @interface VLCMenuTableViewController () <UITableViewDataSource, UITableViewDelegate>
  36. {
  37. NSArray *_sectionHeaderTexts;
  38. NSArray *_menuItemsSectionOne;
  39. NSArray *_menuItemsSectionTwo;
  40. NSArray *_menuItemsSectionThree;
  41. NSMutableSet *_hiddenSettingKeys;
  42. }
  43. @end
  44. @implementation VLCMenuTableViewController
  45. - (void)dealloc
  46. {
  47. [[NSNotificationCenter defaultCenter] removeObserver:self];
  48. }
  49. - (void)viewDidLoad
  50. {
  51. [super viewDidLoad];
  52. self.view.frame = CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds));
  53. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  54. _sectionHeaderTexts = @[@"SECTION_HEADER_LIBRARY", @"SECTION_HEADER_NETWORK", @"Settings"];
  55. _menuItemsSectionOne = @[@"LIBRARY_ALL_FILES", @"LIBRARY_MUSIC", @"LIBRARY_SERIES"];
  56. _menuItemsSectionTwo = @[@"LOCAL_NETWORK", @"OPEN_NETWORK", @"DOWNLOAD_FROM_HTTP", @"WEBINTF_TITLE", @"CLOUD_SERVICES"];
  57. _menuItemsSectionThree = @[@"Settings", @"ABOUT_APP"];
  58. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0f, 44.0f + 20.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds) - (44.0f + 20.0f)) style:UITableViewStylePlain];
  59. _tableView.delegate = self;
  60. _tableView.dataSource = self;
  61. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  62. _tableView.backgroundColor = [UIColor colorWithRed:(43.0f/255.0f) green:(43.0f/255.0f) blue:(43.0f/255.0f) alpha:1.0f];
  63. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  65. _tableView.rowHeight = ROW_HEIGHT;
  66. _tableView.scrollsToTop = NO;
  67. [_tableView registerClass:[VLCWiFiUploadTableViewCell class] forCellReuseIdentifier:WiFiCellIdentifier];
  68. self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds))];
  69. self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
  70. [self.view addSubview:_tableView];
  71. UIView *brandingBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, 64.0f)];
  72. brandingBackgroundView.backgroundColor = [UIColor colorWithRed:0.1608 green:0.1608 blue:0.1608 alpha:1.0000];
  73. [self.view addSubview:brandingBackgroundView];
  74. UIImageView *brandingImageView;
  75. brandingImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, kGHRevealSidebarWidth, 44.0f + 40.0f)];
  76. brandingImageView.contentMode = UIViewContentModeCenter;
  77. brandingImageView.image = [UIImage imageNamed:@"title"];
  78. [self.view addSubview:brandingImageView];
  79. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
  80. }
  81. - (void)viewWillAppear:(BOOL)animated
  82. {
  83. [super viewWillAppear:animated];
  84. self.view.frame = CGRectMake(0.0f, 0.0f,kGHRevealSidebarWidth, CGRectGetHeight(self.view.bounds));
  85. }
  86. - (BOOL)shouldAutorotate
  87. {
  88. UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  89. return (orientation == UIInterfaceOrientationPortraitUpsideDown) ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) : YES;
  90. }
  91. - (BOOL)canBecomeFirstResponder
  92. {
  93. return YES;
  94. }
  95. #pragma mark - table view data source
  96. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  97. {
  98. return 3;
  99. }
  100. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  101. {
  102. if (section == 0) // media
  103. return _menuItemsSectionOne.count;
  104. else if (section == 1) // network
  105. return _menuItemsSectionTwo.count;
  106. else if (section == 2) // settings & co
  107. return _menuItemsSectionThree.count;
  108. else
  109. return 0;
  110. }
  111. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  112. {
  113. NSString *rawTitle;
  114. NSUInteger section = indexPath.section;
  115. if (section == 0)
  116. rawTitle = _menuItemsSectionOne[indexPath.row];
  117. else if(section == 1)
  118. rawTitle = _menuItemsSectionTwo[indexPath.row];
  119. else if(section == 2)
  120. rawTitle = _menuItemsSectionThree[indexPath.row];
  121. UITableViewCell *cell;
  122. if ([rawTitle isEqualToString:@"WEBINTF_TITLE"]) {
  123. cell = (VLCWiFiUploadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:WiFiCellIdentifier];
  124. } else {
  125. cell = (VLCSidebarViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  126. if (cell == nil)
  127. cell = [[VLCSidebarViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  128. }
  129. if (section == 0) {
  130. if ([rawTitle isEqualToString:@"LIBRARY_ALL_FILES"])
  131. cell.imageView.image = [UIImage imageNamed:@"AllFiles"];
  132. else if ([rawTitle isEqualToString:@"LIBRARY_MUSIC"])
  133. cell.imageView.image = [UIImage imageNamed:@"MusicAlbums"];
  134. else if ([rawTitle isEqualToString:@"LIBRARY_SERIES"])
  135. cell.imageView.image = [UIImage imageNamed:@"TVShowsIcon"];
  136. } else if (section == 1) {
  137. if ([rawTitle isEqualToString:@"LOCAL_NETWORK"])
  138. cell.imageView.image = [UIImage imageNamed:@"Local"];
  139. else if ([rawTitle isEqualToString:@"OPEN_NETWORK"])
  140. cell.imageView.image = [UIImage imageNamed:@"OpenNetStream"];
  141. else if ([rawTitle isEqualToString:@"DOWNLOAD_FROM_HTTP"])
  142. cell.imageView.image = [UIImage imageNamed:@"Downloads"];
  143. else if ([rawTitle isEqualToString:@"CLOUD_SERVICES"])
  144. cell.imageView.image = [UIImage imageNamed:@"iCloudIcon"];
  145. } else if (section == 2) {
  146. if ([rawTitle isEqualToString:@"Settings"])
  147. cell.imageView.image = [UIImage imageNamed:@"Settings"];
  148. else
  149. cell.imageView.image = [UIImage imageNamed:@"menuCone"];
  150. }
  151. if (![rawTitle isEqualToString:@"WEBINTF_TITLE"])
  152. cell.textLabel.text = NSLocalizedString(rawTitle, nil);
  153. return cell;
  154. }
  155. #pragma mark - table view delegation
  156. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  157. {
  158. if (section < 3)
  159. return 21.f;
  160. return 0.;
  161. }
  162. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  163. {
  164. NSObject *headerText = NSLocalizedString(_sectionHeaderTexts[section], nil);
  165. UIView *headerView = nil;
  166. if (headerText != [NSNull null]) {
  167. headerView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 21.0f)];
  168. headerView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  169. UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 12.0f, 5.0f)];
  170. textLabel.text = (NSString *) headerText;
  171. textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:([UIFont systemFontSize] * 0.8f)];
  172. textLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
  173. textLabel.shadowColor = [UIColor VLCDarkTextShadowColor];
  174. textLabel.textColor = [UIColor colorWithRed:(118.0f/255.0f) green:(118.0f/255.0f) blue:(118.0f/255.0f) alpha:1.0f];
  175. textLabel.backgroundColor = [UIColor clearColor];
  176. [headerView addSubview:textLabel];
  177. UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  178. topLine.backgroundColor = [UIColor colorWithRed:(95.0f/255.0f) green:(95.0f/255.0f) blue:(95.0f/255.0f) alpha:1.0f];
  179. [headerView addSubview:topLine];
  180. UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 21.0f, [UIScreen mainScreen].bounds.size.height, 1.0f)];
  181. bottomLine.backgroundColor = [UIColor colorWithRed:(16.0f/255.0f) green:(16.0f/255.0f) blue:(16.0f/255.0f) alpha:1.0f];
  182. [headerView addSubview:bottomLine];
  183. }
  184. return headerView;
  185. }
  186. #pragma mark - menu implementation
  187. - (void)_revealItem:(NSUInteger)itemIndex inSection:(NSUInteger)sectionNumber
  188. {
  189. UIViewController *viewController;
  190. VLCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
  191. if (sectionNumber == 1) {
  192. if (itemIndex == 0)
  193. viewController = [[VLCServerListViewController alloc] init];
  194. else if (itemIndex == 1) {
  195. viewController = [[VLCOpenNetworkStreamViewController alloc] initWithNibName:@"VLCOpenNetworkStreamViewController" bundle:nil];
  196. } else if (itemIndex == 2)
  197. viewController = [VLCDownloadViewController sharedInstance];
  198. else if (itemIndex == 3)
  199. [((VLCWiFiUploadTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:itemIndex inSection:sectionNumber]]) toggleHTTPServer];
  200. else if (itemIndex == 4)
  201. viewController = [[VLCCloudServicesTableViewController alloc] initWithNibName:@"VLCCloudServicesTableViewController" bundle:nil];
  202. } else if (sectionNumber == 2) {
  203. if (itemIndex == 0) {
  204. if (!self.settingsController)
  205. self.settingsController = [[VLCSettingsController alloc] init];
  206. VLCSettingsController *settingsController = self.settingsController;
  207. if (!self.settingsViewController) {
  208. self.settingsViewController = [[IASKAppSettingsViewController alloc] initWithStyle:UITableViewStyleGrouped];
  209. settingsController.viewController = self.settingsViewController;
  210. self.settingsViewController.navigationItem.leftBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self.settingsController.viewController andSelector:@selector(dismiss:)];
  211. }
  212. _hiddenSettingKeys = [[NSMutableSet alloc] init];
  213. IASKAppSettingsViewController *settingsVC = self.settingsViewController;
  214. settingsVC.modalPresentationStyle = UIModalPresentationFormSheet;
  215. settingsVC.delegate = self.settingsController;
  216. settingsVC.showDoneButton = NO;
  217. settingsVC.showCreditsFooter = NO;
  218. if (![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPlaybackGestures] boolValue])
  219. [_hiddenSettingKeys addObject:@"EnableVariableJumpDuration"];
  220. [self.settingsController.viewController setHiddenKeys:_hiddenSettingKeys];
  221. viewController = settingsVC;
  222. } else if (itemIndex == 1)
  223. viewController = [[VLCAboutViewController alloc] init];
  224. } else {
  225. viewController = appDelegate.libraryViewController;
  226. [(VLCLibraryViewController *)viewController setLibraryMode:(int)itemIndex];
  227. }
  228. if (!viewController)
  229. return;
  230. VLCSidebarController *sidebarController = [VLCSidebarController sharedInstance];
  231. if ([sidebarController.contentViewController isKindOfClass:[UINavigationController class]]) {
  232. UINavigationController *navCon = (UINavigationController*)sidebarController.contentViewController;
  233. navCon.viewControllers = @[viewController];
  234. } else
  235. sidebarController.contentViewController = [[VLCNavigationController alloc] initWithRootViewController:viewController];
  236. [sidebarController hideSidebar];
  237. }
  238. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  239. {
  240. [self _revealItem:indexPath.row inSection:indexPath.section];
  241. }
  242. #pragma mark Public Methods
  243. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
  244. {
  245. UITableView *tableView = self.tableView;
  246. [tableView selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
  247. if (scrollPosition == UITableViewScrollPositionNone)
  248. [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
  249. [self _revealItem:indexPath.row inSection:indexPath.section];
  250. }
  251. #pragma mark - shake for support
  252. - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
  253. {
  254. if (motion == UIEventSubtypeMotionShake)
  255. [[VLCBugreporter sharedInstance] handleBugreportRequest];
  256. }
  257. @end