VLCLocalPlexFolderListViewController.m 23 KB

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