VLCLocalPlexFolderListViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*****************************************************************************
  2. * VLCLocalPlexFolderListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014-2015 VideoLAN. All rights reserved.
  6. *
  7. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  8. * Pierre SAGASPE <pierre.sagaspe # me.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCLocalPlexFolderListViewController.h"
  13. #import "VLCPlexMediaInformationViewController.h"
  14. #import "VLCPlexParser.h"
  15. #import "VLCPlexWebAPI.h"
  16. #import "VLCNetworkListCell.h"
  17. #import "VLCPlaybackController.h"
  18. #import "VLCLibraryViewController.h"
  19. #import "VLCDownloadViewController.h"
  20. #import "NSString+SupportedMedia.h"
  21. #import "VLCStatusLabel.h"
  22. #import "UIDevice+VLC.h"
  23. @interface VLCLocalPlexFolderListViewController () <UITableViewDataSource, UITableViewDelegate, VLCNetworkListCellDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
  24. {
  25. NSArray *_globalObjectList;
  26. NSCache *_imageCache;
  27. NSString *_PlexServerName;
  28. NSString *_PlexServerAddress;
  29. NSString *_PlexServerPort;
  30. NSString *_PlexServerPath;
  31. NSString *_PlexAuthentification;
  32. VLCPlexParser *_PlexParser;
  33. VLCPlexWebAPI *_PlexWebAPI;
  34. NSMutableArray *_searchData;
  35. UISearchBar *_searchBar;
  36. UISearchDisplayController *_searchDisplayController;
  37. UIRefreshControl *_refreshControl;
  38. UIBarButtonItem *_menuButton;
  39. UITapGestureRecognizer *_tapTwiceGestureRecognizer;
  40. }
  41. @end
  42. @implementation VLCLocalPlexFolderListViewController
  43. - (void)dealloc
  44. {
  45. [_tapTwiceGestureRecognizer removeTarget:self action:NULL];
  46. }
  47. - (void)loadView
  48. {
  49. _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
  50. _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  51. CGRect frame = _tableView.bounds;
  52. frame.origin.y = -frame.size.height;
  53. UIView *topView = [[UIView alloc] initWithFrame:frame];
  54. topView.backgroundColor = [UIColor VLCDarkBackgroundColor];
  55. [_tableView addSubview:topView];
  56. _tableView.delegate = self;
  57. _tableView.dataSource = self;
  58. _tableView.rowHeight = [VLCNetworkListCell heightOfCell];
  59. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  60. _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  61. self.view = _tableView;
  62. }
  63. - (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth
  64. {
  65. self = [super init];
  66. if (self) {
  67. _PlexServerName = serverName;
  68. _PlexServerAddress = serverAddress;
  69. _PlexServerPort = portNumber;
  70. _PlexServerPath = path;
  71. _PlexAuthentification = auth;
  72. _globalObjectList = [[NSArray alloc] init];
  73. _imageCache = [[NSCache alloc] init];
  74. [_imageCache setCountLimit:50];
  75. _PlexParser = [[VLCPlexParser alloc] init];
  76. }
  77. return self;
  78. }
  79. - (void)viewDidLoad
  80. {
  81. [super viewDidLoad];
  82. self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
  83. self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  84. _PlexWebAPI = [[VLCPlexWebAPI alloc] init];
  85. self.title = _PlexServerName;
  86. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  87. UINavigationBar *navBar = self.navigationController.navigationBar;
  88. _searchBar.barTintColor = navBar.barTintColor;
  89. _searchBar.tintColor = navBar.tintColor;
  90. _searchBar.translucent = navBar.translucent;
  91. _searchBar.opaque = navBar.opaque;
  92. _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  93. _searchDisplayController.delegate = self;
  94. _searchDisplayController.searchResultsDataSource = self;
  95. _searchDisplayController.searchResultsDelegate = self;
  96. _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
  97. _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  98. _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  99. _searchBar.delegate = self;
  100. _searchBar.hidden = YES;
  101. //self.tableView.tableHeaderView = _searchBar;
  102. //self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(_searchBar.frame)); // -> hide search bar to load
  103. _tapTwiceGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
  104. [_tapTwiceGestureRecognizer setNumberOfTapsRequired:2];
  105. [self.navigationController.navigationBar addGestureRecognizer:_tapTwiceGestureRecognizer];
  106. // Active le Pull down to refresh
  107. _refreshControl = [[UIRefreshControl alloc] init];
  108. _refreshControl.backgroundColor = [UIColor VLCDarkBackgroundColor];
  109. _refreshControl.tintColor = [UIColor whiteColor];
  110. // Call the refresh function
  111. [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
  112. [self.tableView addSubview:_refreshControl];
  113. _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)];
  114. self.navigationItem.rightBarButtonItem = _menuButton;
  115. _globalObjectList = [[NSArray alloc] init];
  116. _searchData = [[NSMutableArray alloc] init];
  117. [self performSelectorInBackground:@selector(loadContents) withObject:nil];
  118. }
  119. - (void)loadContents
  120. {
  121. _globalObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
  122. NSDictionary *firstObject = [_globalObjectList firstObject];
  123. if (_globalObjectList.count == 0 || firstObject == nil)
  124. _PlexAuthentification = @"";
  125. else
  126. _PlexAuthentification = [firstObject objectForKey:@"authentification"];
  127. NSString *titleValue;
  128. if ([_PlexServerPath isEqualToString:@""] || _globalObjectList.count == 0 || firstObject == nil)
  129. titleValue = _PlexServerName;
  130. else
  131. titleValue = [firstObject objectForKey:@"libTitle"];
  132. self.title = titleValue;
  133. [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
  134. }
  135. - (BOOL)shouldAutorotate
  136. {
  137. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  138. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
  139. return NO;
  140. return YES;
  141. }
  142. - (IBAction)menuButtonAction:(id)sender
  143. {
  144. [[VLCSidebarController sharedInstance] toggleSidebar];
  145. if (self.isEditing)
  146. [self setEditing:NO animated:YES];
  147. }
  148. #pragma mark - Table view data source
  149. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  150. {
  151. return 1;
  152. }
  153. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  154. {
  155. if (tableView == self.searchDisplayController.searchResultsTableView)
  156. return _searchData.count;
  157. else
  158. return _globalObjectList.count;
  159. }
  160. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  161. {
  162. static NSString *CellIdentifier = @"PlexCellDetail";
  163. VLCNetworkListCell *cell = (VLCNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  164. if (cell == nil)
  165. cell = [VLCNetworkListCell cellWithReuseIdentifier:CellIdentifier];
  166. NSDictionary *cellObject;
  167. if (tableView == self.searchDisplayController.searchResultsTableView)
  168. cellObject = _searchData[indexPath.row];
  169. else
  170. cellObject = _globalObjectList[indexPath.row];
  171. [cell setTitle:cellObject[@"title"]];
  172. [cell setIcon:[UIImage imageNamed:@"blank"]];
  173. NSString *thumbPath = cellObject[@"thumb"];
  174. if (thumbPath) {
  175. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
  176. dispatch_async(queue, ^{
  177. UIImage *img = [self getCachedImage:[self _urlAuth:thumbPath]];
  178. dispatch_async(dispatch_get_main_queue(), ^{
  179. if (!img)
  180. [cell setIcon:[UIImage imageNamed:@"blank"]];
  181. else
  182. [cell setIcon:img];
  183. });
  184. });
  185. }
  186. if ([cellObject[@"container"] isEqualToString:@"item"]) {
  187. UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGestureAction:)];
  188. [swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
  189. [cell addGestureRecognizer:swipeRight];
  190. UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
  191. [cell addGestureRecognizer:longPressGestureRecognizer];
  192. NSInteger size = [cellObject[@"size"] integerValue];
  193. NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
  194. NSString *durationInSeconds = cellObject[@"duration"];
  195. [cell setIsDirectory:NO];
  196. [cell setSubtitle:[NSString stringWithFormat:@"%@ (%@)", mediaSize, durationInSeconds]];
  197. [cell setIsDownloadable:YES];
  198. [cell setDelegate:self];
  199. } else {
  200. [cell setIsDirectory:YES];
  201. if (!thumbPath)
  202. [cell setIcon:[UIImage imageNamed:@"folder"]];
  203. }
  204. return cell;
  205. }
  206. - (UIImage *)getCachedImage:(NSString *)url
  207. {
  208. UIImage *image = [_imageCache objectForKey:url];
  209. if ((image != nil) && [image isKindOfClass:[UIImage class]]) {
  210. return image;
  211. } else {
  212. NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
  213. if (imageData) {
  214. image = [[UIImage alloc] initWithData:imageData];
  215. if (image)
  216. [_imageCache setObject:image forKey:url];
  217. }
  218. return image;
  219. }
  220. }
  221. #pragma mark - Table view delegate
  222. - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  223. {
  224. UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
  225. cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
  226. }
  227. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  228. {
  229. NSArray *objectList;
  230. NSString *newPath = nil;
  231. if (tableView == self.searchDisplayController.searchResultsTableView)
  232. objectList = [_searchData copy];
  233. else
  234. objectList = _globalObjectList;
  235. NSDictionary *rowObject = objectList[indexPath.row];
  236. NSString *keyValue = [rowObject objectForKey:@"key"];
  237. if ([keyValue rangeOfString:@"library"].location == NSNotFound)
  238. newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
  239. else
  240. newPath = keyValue;
  241. if ([rowObject[@"container"] isEqualToString:@"item"]) {
  242. objectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
  243. NSString *URLofSubtitle = nil;
  244. NSDictionary *firstObject = [objectList firstObject];
  245. if (!firstObject)
  246. return;
  247. if ([firstObject objectForKey:@"keySubtitle"])
  248. URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:YES];
  249. NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:firstObject[@"keyMedia"]]];
  250. if (itemURL) {
  251. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  252. [vpc playURL:itemURL subtitlesFilePath:URLofSubtitle];
  253. }
  254. } else {
  255. VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:_PlexServerName serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:newPath authentification:_PlexAuthentification];
  256. [[self navigationController] pushViewController:targetViewController animated:YES];
  257. }
  258. [tableView deselectRowAtIndexPath:indexPath animated:NO];
  259. }
  260. #pragma mark - Specifics
  261. - (NSString *)_urlAuth:(NSString *)url
  262. {
  263. return [_PlexWebAPI urlAuth:url autentification:_PlexAuthentification];
  264. }
  265. - (void)_playMediaItem:(NSDictionary *)mediaObject
  266. {
  267. NSString *newPath = nil;
  268. NSString *keyValue = [mediaObject objectForKey:@"key"];
  269. if ([keyValue rangeOfString:@"library"].location == NSNotFound)
  270. newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
  271. else
  272. newPath = keyValue;
  273. if ([[mediaObject objectForKey:@"container"] isEqualToString:@"item"]) {
  274. NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
  275. NSString *URLofSubtitle = nil;
  276. NSDictionary *firstObject = [mediaList firstObject];
  277. if (!firstObject)
  278. return;
  279. if ([firstObject objectForKey:@"keySubtitle"])
  280. URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:YES];
  281. NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[firstObject objectForKey:@"keyMedia"]]];
  282. if (itemURL) {
  283. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  284. [vpc playURL:itemURL subtitlesFilePath:URLofSubtitle];
  285. }
  286. }
  287. }
  288. - (void)_downloadFileFromMediaItem:(NSDictionary *)mediaObject
  289. {
  290. if (!mediaObject)
  291. return;
  292. NSURL *itemURL = [NSURL URLWithString:[mediaObject objectForKey:@"keyMedia"]];
  293. if (![[itemURL absoluteString] isSupportedFormat]) {
  294. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
  295. message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [itemURL absoluteString]]
  296. delegate:self
  297. cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
  298. otherButtonTitles:nil];
  299. [alert show];
  300. } else if (itemURL) {
  301. NSString *fileName = [mediaObject objectForKey:@"namefile"];
  302. [[VLCDownloadViewController sharedInstance] addURLToDownloadList:itemURL fileNameOfMedia:fileName];
  303. }
  304. }
  305. - (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
  306. {
  307. NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
  308. UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
  309. VLCNetworkListCell *cell = (VLCNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
  310. NSDictionary *cellObject = _globalObjectList[[self.tableView indexPathForCell:swipedCell].row];
  311. NSString *ratingKey = cellObject[@"ratingKey"];
  312. NSString *tag = cellObject[@"state"];
  313. NSString *cellStatusLbl = nil;
  314. NSInteger status = [_PlexWebAPI MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
  315. if (status == 200) {
  316. if ([tag isEqualToString:@"watched"]) {
  317. tag = @"unwatched";
  318. cellStatusLbl = NSLocalizedString(@"PLEX_UNWATCHED", nil);
  319. } else if ([tag isEqualToString:@"unwatched"]) {
  320. tag = @"watched";
  321. cellStatusLbl = NSLocalizedString(@"PLEX_WATCHED", nil);
  322. }
  323. } else
  324. cellStatusLbl = NSLocalizedString(@"PLEX_ERROR_MARK", nil);
  325. [cell.statusLabel showStatusMessage:cellStatusLbl];
  326. [_globalObjectList[[self.tableView indexPathForCell:swipedCell].row] setObject:tag forKey:@"state"];
  327. }
  328. - (void)reloadTableViewPlex
  329. {
  330. _globalObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
  331. [self.tableView reloadData];
  332. }
  333. #pragma mark - VLCNetworkListCell delegation
  334. - (void)triggerDownloadForCell:(VLCNetworkListCell *)cell
  335. {
  336. NSDictionary *cellObject;
  337. if ([self.searchDisplayController isActive])
  338. cellObject = _searchData[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row];
  339. else
  340. cellObject = _globalObjectList[[self.tableView indexPathForCell:cell].row];
  341. NSString *path = cellObject[@"key"];
  342. NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:_PlexAuthentification];
  343. NSDictionary *firstObject = [mediaList firstObject];
  344. NSInteger size = [[firstObject objectForKey:@"size"] integerValue];
  345. if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
  346. if ([firstObject objectForKey:@"keySubtitle"])
  347. [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:NO];
  348. [self _downloadFileFromMediaItem:firstObject];
  349. [cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", nil)];
  350. } else {
  351. VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
  352. message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), [firstObject objectForKey:@"title"], [[UIDevice currentDevice] model]]
  353. delegate:self
  354. cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
  355. otherButtonTitles:nil];
  356. [alert show];
  357. }
  358. }
  359. #pragma mark - Search Display Controller Delegate
  360. - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  361. {
  362. [_searchData removeAllObjects];
  363. NSUInteger count = _globalObjectList.count;
  364. for (NSUInteger i = 0; i < count; i++) {
  365. NSRange nameRange;
  366. nameRange = [[_globalObjectList[i] objectForKey:@"title"] rangeOfString:searchString options:NSCaseInsensitiveSearch];
  367. if (nameRange.location != NSNotFound)
  368. [_searchData addObject:_globalObjectList[i]];
  369. }
  370. return YES;
  371. }
  372. - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
  373. {
  374. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
  375. tableView.rowHeight = 80.0f;
  376. else
  377. tableView.rowHeight = 68.0f;
  378. tableView.backgroundColor = [UIColor blackColor];
  379. }
  380. #pragma mark - Refresh
  381. -(void)handleRefresh
  382. {
  383. //set the title while refreshing
  384. _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"LOCAL_SERVER_REFRESH", nil)];
  385. //set the date and time of refreshing
  386. NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
  387. [formattedDate setDateFormat:@"MMM d, h:mm a"];
  388. NSString *lastupdated = [NSString stringWithFormat:NSLocalizedString(@"LOCAL_SERVER_LAST_UPDATE", nil),[formattedDate stringFromDate:[NSDate date]]];
  389. NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
  390. _refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastupdated attributes:attrsDictionary];
  391. //end the refreshing
  392. [_refreshControl endRefreshing];
  393. [self performSelector:@selector(reloadTableViewPlex) withObject:nil];
  394. }
  395. #pragma mark - Gesture Action
  396. - (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
  397. {
  398. _searchBar.hidden = !_searchBar.hidden;
  399. if (_searchBar.hidden)
  400. self.tableView.tableHeaderView = nil;
  401. else
  402. self.tableView.tableHeaderView = _searchBar;
  403. [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
  404. }
  405. - (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
  406. {
  407. if (recognizer.state == UIGestureRecognizerStateBegan) {
  408. NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
  409. UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
  410. NSDictionary *cellObject = _globalObjectList[[self.tableView indexPathForCell:swipedCell].row];
  411. VLCPlexMediaInformationViewController *targetViewController = [[VLCPlexMediaInformationViewController alloc] initPlexMediaInformation:cellObject serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:_PlexServerPath authentification:_PlexAuthentification];
  412. [[self navigationController] pushViewController:targetViewController animated:YES];
  413. }
  414. }
  415. @end