VLCLocalPlexFolderListViewController.m 23 KB

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