VLCLocalPlexFolderListViewController.m 22 KB

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