VLCLocalPlexFolderListViewController.m 21 KB

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