VLCLocalPlexFolderListViewController.m 23 KB

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