VLCLocalPlexFolderListViewController.m 23 KB

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