VLCLocalPlexFolderListViewController.m 22 KB

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