123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- /*****************************************************************************
- * VLCLocalPlexFolderListViewController.m
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2014 VideoLAN. All rights reserved.
- *
- * Authors: Felix Paul Kühne <fkuehne # videolan.org>
- * Pierre SAGASPE <pierre.sagaspe # me.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- #import "VLCLocalPlexFolderListViewController.h"
- #import "VLCPlexParser.h"
- #import "VLCLocalNetworkListCell.h"
- #import "VLCAppDelegate.h"
- #import "VLCPlaylistViewController.h"
- #import "UINavigationController+Theme.h"
- #import "VLCDownloadViewController.h"
- #import "NSString+SupportedMedia.h"
- #import "VLCStatusLabel.h"
- #import "VLCAlertView.h"
- #import "UIBarButtonItem+Theme.h"
- #import "UIDevice+VLC.h"
- @interface VLCLocalPlexFolderListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalNetworkListCell, UISearchBarDelegate, UISearchDisplayDelegate>
- {
- NSMutableArray *_mutableObjectList;
- NSCache *_imageCache;
- NSString *_PlexServerName;
- NSString *_PlexServerAddress;
- NSString *_PlexServerPort;
- NSString *_PlexServerPath;
- VLCPlexParser *_PlexParser;
- NSMutableArray *_searchData;
- UISearchBar *_searchBar;
- UISearchDisplayController *_searchDisplayController;
- UIRefreshControl *_refreshControl;
- UIBarButtonItem *_menuButton;
- }
- @end
- @implementation VLCLocalPlexFolderListViewController
- - (void)loadView
- {
- _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
- _tableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.rowHeight = [VLCLocalNetworkListCell heightOfCell];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
- self.view = _tableView;
- }
- - (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path
- {
- self = [super init];
- if (self) {
- _PlexServerName = serverName;
- _PlexServerAddress = serverAddress;
- _PlexServerPort = portNumber;
- _PlexServerPath = path;
- _mutableObjectList = [[NSMutableArray alloc] init];
- _imageCache = [[NSCache alloc] init];
- [_imageCache setCountLimit:50];
- _PlexParser = [[VLCPlexParser alloc] init];
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [_mutableObjectList removeAllObjects];
- _mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath];
- self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
- self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
- NSString *titleValue;
- if ([_PlexServerPath isEqualToString:@""] || _mutableObjectList.count == 0)
- titleValue = _PlexServerName;
- else
- titleValue = [_mutableObjectList[0] objectForKey:@"libTitle"];
- self.title = titleValue;
- _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
- UINavigationBar *navBar = self.navigationController.navigationBar;
- if (SYSTEM_RUNS_IOS7_OR_LATER)
- _searchBar.barTintColor = navBar.barTintColor;
- _searchBar.tintColor = navBar.tintColor;
- _searchBar.translucent = navBar.translucent;
- _searchBar.opaque = navBar.opaque;
- _searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
- _searchDisplayController.delegate = self;
- _searchDisplayController.searchResultsDataSource = self;
- _searchDisplayController.searchResultsDelegate = self;
- if (SYSTEM_RUNS_IOS7_OR_LATER)
- _searchDisplayController.searchBar.searchBarStyle = UIBarStyleBlack;
- _searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _searchDisplayController.searchResultsTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
- _searchBar.delegate = self;
- _searchBar.hidden = YES;
- //self.tableView.tableHeaderView = _searchBar;
- //self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(_searchBar.frame)); // -> hide search bar to load
- UITapGestureRecognizer *tapTwiceGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwiceGestureAction:)];
- [tapTwiceGesture setNumberOfTapsRequired:2];
- [self.navigationController.navigationBar addGestureRecognizer:tapTwiceGesture];
- // Active le Pull down to refresh
- _refreshControl = [[UIRefreshControl alloc] init];
- _refreshControl.backgroundColor = [UIColor VLCDarkBackgroundColor];
- _refreshControl.tintColor = [UIColor whiteColor];
- // Call the refresh function
- [_refreshControl addTarget:self action:@selector(handleRefresh) forControlEvents:UIControlEventValueChanged];
- [self.tableView addSubview:_refreshControl];
- _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)];
- self.navigationItem.rightBarButtonItem = _menuButton;
- _searchData = [[NSMutableArray alloc] init];
- [_searchData removeAllObjects];
- }
- - (BOOL)shouldAutorotate
- {
- UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
- return NO;
- return YES;
- }
- - (IBAction)menuButtonAction:(id)sender
- {
- [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
- if (self.isEditing)
- [self setEditing:NO animated:YES];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (tableView == self.searchDisplayController.searchResultsTableView)
- return _searchData.count;
- else
- return _mutableObjectList.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"PlexCellDetail";
- VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
- NSMutableArray *ObjList = [[NSMutableArray alloc] init];
- [ObjList removeAllObjects];
- if (tableView == self.searchDisplayController.searchResultsTableView)
- [ObjList addObjectsFromArray:_searchData];
- else
- [ObjList addObjectsFromArray:_mutableObjectList];
- [cell setTitle:[[ObjList objectAtIndex:indexPath.row] objectForKey:@"title"]];
- [cell setIcon:[UIImage imageNamed:@"blank"]];
- NSString *thumbPath = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"thumb"];
- if (thumbPath) {
- dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
- dispatch_async(queue, ^{
- UIImage *img = [self getCachedImage:thumbPath];
- dispatch_async(dispatch_get_main_queue(), ^{
- if (!img)
- [cell setIcon:[UIImage imageNamed:@"blank"]];
- else
- [cell setIcon:img];
- });
- });
- }
- if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
- UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGestureAction:)];
- [swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
- [cell addGestureRecognizer:swipeRight];
- if (SYSTEM_RUNS_IOS7_OR_LATER) {
- UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
- [cell addGestureRecognizer:longPressGestureRecognizer];
- }
- NSInteger size = [[[ObjList objectAtIndex:indexPath.row] objectForKey:@"size"] integerValue];
- NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
- NSString *durationInSeconds = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"duration"];
- [cell setIsDirectory:NO];
- [cell setSubtitle:[NSString stringWithFormat:@"%@ (%@)", mediaSize, durationInSeconds]];
- [cell setIsDownloadable:YES];
- [cell setDelegate:self];
- } else {
- [cell setIsDirectory:YES];
- if (!thumbPath)
- [cell setIcon:[UIImage imageNamed:@"folder"]];
- }
- return cell;
- }
- - (UIImage *)getCachedImage:(NSString *)url
- {
- UIImage *image = [_imageCache objectForKey:url];
- if ((image != nil) && [image isKindOfClass:[UIImage class]]) {
- return image;
- } else {
- NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
- if (imageData) {
- image = [[UIImage alloc] initWithData:imageData];
- [_imageCache setObject:image forKey:url];
- }
- return image;
- }
- }
- #pragma mark - Table view delegate
- - (void)tableView:(UITableView *)tableView willDisplayCell:(VLCLocalNetworkListCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UIColor *color = (indexPath.row % 2 == 0)? [UIColor blackColor]: [UIColor VLCDarkBackgroundColor];
- cell.contentView.backgroundColor = cell.titleLabel.backgroundColor = cell.folderTitleLabel.backgroundColor = cell.subtitleLabel.backgroundColor = color;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSMutableArray *ObjList = [[NSMutableArray alloc] init];
- [ObjList removeAllObjects];
- NSString *newPath = nil;
- if (tableView == self.searchDisplayController.searchResultsTableView)
- [ObjList addObjectsFromArray:_searchData];
- else
- [ObjList addObjectsFromArray:_mutableObjectList];
- NSString *keyValue = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"key"];
- if ([keyValue rangeOfString:@"library"].location == NSNotFound)
- newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
- else
- newPath = keyValue;
- if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
- [ObjList removeAllObjects];
- ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath];
- NSString *URLofSubtitle = nil;
- if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
- URLofSubtitle = [self _getFileSubtitleFromPlexServer:ObjList modeStream:YES];
- NSURL *itemURL = [NSURL URLWithString:[[ObjList objectAtIndex:0] objectForKey:@"keyMedia"]];
- if (itemURL) {
- VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
- [appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
- }
- } else {
- VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:_PlexServerName serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:newPath];
- [[self navigationController] pushViewController:targetViewController animated:YES];
- }
- [tableView deselectRowAtIndexPath:indexPath animated:NO];
- }
- #pragma mark - Specifics
- - (void)_playMediaItem:(NSMutableArray *)mutableMediaObject
- {
- NSString *newPath = nil;
- NSString *keyValue = [[mutableMediaObject objectAtIndex:0] objectForKey:@"key"];
- if ([keyValue rangeOfString:@"library"].location == NSNotFound)
- newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
- else
- newPath = keyValue;
- if ([[[mutableMediaObject objectAtIndex:0] objectForKey:@"container"] isEqualToString:@"item"]) {
- [mutableMediaObject removeAllObjects];
- mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath];
- NSString *URLofSubtitle = nil;
- if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
- URLofSubtitle = [self _getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
- NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
- if (itemURL) {
- VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
- [appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
- }
- }
- }
- - (void)_downloadFileFromMediaItem:(NSMutableArray *)mutableMediaObject
- {
- NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
- if (![[itemURL absoluteString] isSupportedFormat]) {
- 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];
- [alert show];
- } else if (itemURL) {
- NSString *fileName = [[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"];
- [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:itemURL fileNameOfMedia:fileName];
- }
- }
- - (NSString *)_getFileSubtitleFromPlexServer:(NSMutableArray *)mutableMediaObject modeStream:(BOOL)modeStream
- {
- NSURL *url = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"]];
- NSString *receivedSub = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
- NSArray *searchPaths = nil;
- if (modeStream)
- searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- else
- searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *directoryPath = [searchPaths objectAtIndex:0];
- NSString *FileSubtitlePath = [[directoryPath stringByAppendingPathComponent:[[[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"] stringByDeletingPathExtension]] stringByAppendingPathExtension:[[mutableMediaObject objectAtIndex:0] objectForKey:@"codecSubtitle"]];
- NSFileManager *fileManager = [NSFileManager defaultManager];
- if (![fileManager fileExistsAtPath:FileSubtitlePath]) {
- [fileManager createFileAtPath:FileSubtitlePath contents:nil attributes:nil];
- if (![fileManager fileExistsAtPath:FileSubtitlePath])
- APLog(@"file creation failed, no data was saved");
- }
- [receivedSub writeToFile:FileSubtitlePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
- return FileSubtitlePath;
- }
- - (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
- {
- NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
- UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
- VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
- NSMutableArray *ObjList = [[NSMutableArray alloc] init];
- [ObjList removeAllObjects];
- [ObjList addObject:_mutableObjectList[[self.tableView indexPathForCell:swipedCell].row]];
- NSString *ratingKey = [[ObjList objectAtIndex:0] objectForKey:@"ratingKey"];
- NSString *tag = [[ObjList objectAtIndex:0] objectForKey:@"state"];
- NSString *cellStatusLbl = nil;
- NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag];
- if (status == 200) {
- if ([tag isEqualToString:@"watched"]) {
- tag = @"unwatched";
- cellStatusLbl = NSLocalizedString(@"PLEX_UNWATCHED", nil);
- } else if ([tag isEqualToString:@"unwatched"]) {
- tag = @"watched";
- cellStatusLbl = NSLocalizedString(@"PLEX_WATCHED", nil);
- }
- } else
- cellStatusLbl = NSLocalizedString(@"PLEX_ERROR_MARK", nil);
- [cell.statusLabel showStatusMessage:cellStatusLbl];
- [[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row] setObject:tag forKey:@"state"];
- }
- - (void)reloadTableViewPlex
- {
- [_mutableObjectList removeAllObjects];
- _mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath];
- [self.tableView reloadData];
- }
- #pragma mark - VLCLocalNetworkListCell delegation
- - (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
- {
- NSMutableArray *ObjList = [[NSMutableArray alloc] init];
- [ObjList removeAllObjects];
- if ([self.searchDisplayController isActive])
- [ObjList addObject:_searchData[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row]];
- else
- [ObjList addObject:_mutableObjectList[[self.tableView indexPathForCell:cell].row]];
- NSString *path = [[ObjList objectAtIndex:0] objectForKey:@"key"];
- [ObjList removeAllObjects];
- ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path];
- NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
- if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
- if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
- [self _getFileSubtitleFromPlexServer:ObjList modeStream:NO];
- [self _downloadFileFromMediaItem:ObjList];
- [cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", nil)];
- } else {
- 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];
- [alert show];
- }
- }
- #pragma mark - Search Display Controller Delegate
- - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
- {
- [_searchData removeAllObjects];
- for (int i = 0; i < [_mutableObjectList count]; i++) {
- NSRange nameRange;
- nameRange = [[[_mutableObjectList objectAtIndex:i] objectForKey:@"title"] rangeOfString:searchString options:NSCaseInsensitiveSearch];
- if (nameRange.location != NSNotFound)
- [_searchData addObject:_mutableObjectList[i]];
- }
- return YES;
- }
- - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
- {
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
- tableView.rowHeight = 80.0f;
- else
- tableView.rowHeight = 68.0f;
- tableView.backgroundColor = [UIColor blackColor];
- }
- #pragma mark - Refresh
- -(void)handleRefresh
- {
- //set the title while refreshing
- _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"LOCAL_SERVER_REFRESH", nil)];
- //set the date and time of refreshing
- NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
- [formattedDate setDateFormat:@"MMM d, h:mm a"];
- NSString *lastupdated = [NSString stringWithFormat:NSLocalizedString(@"LOCAL_SERVER_LAST_UPDATE", nil),[formattedDate stringFromDate:[NSDate date]]];
- NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
- _refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastupdated attributes:attrsDictionary];
- //end the refreshing
- [_refreshControl endRefreshing];
- [self performSelector:@selector(reloadTableViewPlex) withObject:nil];
- }
- #pragma mark - Gesture Action
- - (void)tapTwiceGestureAction:(UIGestureRecognizer *)recognizer
- {
- _searchBar.hidden = !_searchBar.hidden;
- if (_searchBar.hidden)
- self.tableView.tableHeaderView = nil;
- else
- self.tableView.tableHeaderView = _searchBar;
- [self.tableView setContentOffset:CGPointMake(0.0f, -self.tableView.contentInset.top) animated:NO];
- }
- - (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
- {
- if (recognizer.state == UIGestureRecognizerStateBegan) {
- NSMutableArray *ObjList = [[NSMutableArray alloc] init];
- [ObjList removeAllObjects];
- NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
- UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
- VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
- [ObjList addObject:[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row]];
- NSString *title = [[ObjList objectAtIndex:0] objectForKey:@"title"];
- NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
- NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
- NSString *durationInSeconds = [[ObjList objectAtIndex:0] objectForKey:@"duration"];
- NSString *message = [NSString stringWithFormat:@"%@ (%@)", mediaSize, durationInSeconds];
- NSString *summary = [NSString stringWithFormat:@"%@", [[ObjList objectAtIndex:0] objectForKey:@"summary"]];
- VLCAlertView *alertView = [[VLCAlertView alloc] initWithTitle:title message:message cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) otherButtonTitles:@[NSLocalizedString(@"BUTTON_PLAY", nil), NSLocalizedString(@"BUTTON_DOWNLOAD", nil)]];
- if (![summary isEqualToString:@""]) {
- UITextView *textView = [[UITextView alloc] initWithFrame:alertView.bounds];
- textView.text = summary;
- textView.editable = NO;
- [alertView setValue:textView forKey:@"accessoryView"];
- }
- alertView.completion = ^(BOOL cancelled, NSInteger buttonIndex) {
- if (!cancelled) {
- if (buttonIndex == 2)
- [self triggerDownloadForCell:cell];
- else
- [self _playMediaItem:ObjList];
- }
- };
- [alertView show];
- }
- }
- @end
|