/***************************************************************************** * VLC for iOS ***************************************************************************** * Copyright (c) 2015 VideoLAN. All rights reserved. * $Id$ * * Authors: Tobias Conradi * * Refer to the COPYING file of the official project for license. *****************************************************************************/ #import "VLCServerBrowsingTVViewController.h" #import "VLCRemoteBrowsingTVCell.h" #import "VLCPlayerDisplayController.h" #import "VLCPlaybackController.h" #import "VLCServerBrowsingController.h" #import "VLCMaskView.h" @interface VLCServerBrowsingTVViewController () @property (nonatomic, readonly) idserverBrowser; @property (nonatomic) VLCServerBrowsingController *browsingController; @end @implementation VLCServerBrowsingTVViewController - (instancetype)initWithServerBrowser:(id)serverBrowser { self = [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil]; if (self) { _serverBrowser = serverBrowser; serverBrowser.delegate = self; _browsingController = [[VLCServerBrowsingController alloc] initWithViewController:self serverBrowser:serverBrowser]; self.title = serverBrowser.title; } return self; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self.serverBrowser update]; } #pragma mark - - (void)reloadData { [self.serverBrowser update]; } #pragma mark - - (void)networkServerBrowserDidUpdate:(id)networkBrowser { self.title = networkBrowser.title; [self.collectionView reloadData]; } - (void)networkServerBrowser:(id)networkBrowser requestDidFailWithError:(NSError *)error { [self vlc_showAlertWithTitle:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_TITLE", nil) message:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil) buttonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)]; } #pragma mark - - (void)didSelectItem:(id)item index:(NSUInteger)index singlePlayback:(BOOL)singlePlayback { if (item.isContainer) { VLCServerBrowsingTVViewController *targetViewController = [[VLCServerBrowsingTVViewController alloc] initWithServerBrowser:item.containerBrowser]; [self.navigationController pushViewController:targetViewController animated:YES]; } else { if (singlePlayback) { [self.browsingController streamFileForItem:item]; } else { VLCMediaList *mediaList = self.serverBrowser.mediaList; [self.browsingController configureSubtitlesInMediaList:mediaList]; [self.browsingController streamMediaList:mediaList startingAtIndex:index]; } } } #pragma mark - collection view data source - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.serverBrowser items].count; } - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { id item = self.serverBrowser.items[indexPath.row]; if ([cell conformsToProtocol:@protocol(VLCRemoteBrowsingCell)]) { [self.browsingController configureCell:(id)cell withItem:item]; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = indexPath.row; id item = self.serverBrowser.items[row]; // would make sence if item came from search which isn't // currently the case on the TV const BOOL singlePlayback = NO; [self didSelectItem:item index:row singlePlayback:singlePlayback]; } @end