VLCServerBrowsingTVViewController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCServerBrowsingTVViewController.h"
  12. #import "VLCRemoteBrowsingTVCell.h"
  13. #import "VLCPlayerDisplayController.h"
  14. #import "VLCPlaybackController.h"
  15. #import "VLCServerBrowsingController.h"
  16. #import "VLCMaskView.h"
  17. @interface VLCServerBrowsingTVViewController ()
  18. @property (nonatomic, readonly) id<VLCNetworkServerBrowser>serverBrowser;
  19. @property (nonatomic) VLCServerBrowsingController *browsingController;
  20. @end
  21. @implementation VLCServerBrowsingTVViewController
  22. - (instancetype)initWithServerBrowser:(id<VLCNetworkServerBrowser>)serverBrowser
  23. {
  24. self = [super initWithNibName:@"VLCRemoteBrowsingCollectionViewController" bundle:nil];
  25. if (self) {
  26. _serverBrowser = serverBrowser;
  27. serverBrowser.delegate = self;
  28. _browsingController = [[VLCServerBrowsingController alloc] initWithViewController:self serverBrowser:serverBrowser];
  29. self.title = serverBrowser.title;
  30. }
  31. return self;
  32. }
  33. - (void)viewDidAppear:(BOOL)animated
  34. {
  35. [super viewDidAppear:animated];
  36. [self.serverBrowser update];
  37. }
  38. #pragma mark -
  39. - (void)reloadData
  40. {
  41. [self.serverBrowser update];
  42. }
  43. #pragma mark -
  44. - (void)networkServerBrowserDidUpdate:(id<VLCNetworkServerBrowser>)networkBrowser
  45. {
  46. self.title = networkBrowser.title;
  47. [self.collectionView reloadData];
  48. }
  49. - (void)networkServerBrowser:(id<VLCNetworkServerBrowser>)networkBrowser requestDidFailWithError:(NSError *)error {
  50. [self vlc_showAlertWithTitle:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_TITLE", nil)
  51. message:NSLocalizedString(@"LOCAL_SERVER_CONNECTION_FAILED_MESSAGE", nil)
  52. buttonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)];
  53. }
  54. #pragma mark -
  55. - (void)didSelectItem:(id<VLCNetworkServerBrowserItem>)item index:(NSUInteger)index singlePlayback:(BOOL)singlePlayback
  56. {
  57. if (item.isContainer) {
  58. VLCServerBrowsingTVViewController *targetViewController = [[VLCServerBrowsingTVViewController alloc] initWithServerBrowser:item.containerBrowser];
  59. [self.navigationController pushViewController:targetViewController animated:YES];
  60. } else {
  61. if (singlePlayback) {
  62. [self.browsingController streamFileForItem:item];
  63. } else {
  64. VLCMediaList *mediaList = self.serverBrowser.mediaList;
  65. [self.browsingController configureSubtitlesInMediaList:mediaList];
  66. [self.browsingController streamMediaList:mediaList startingAtIndex:index];
  67. }
  68. }
  69. }
  70. #pragma mark - collection view data source
  71. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  72. {
  73. return [self.serverBrowser items].count;
  74. }
  75. - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[indexPath.row];
  78. if ([cell conformsToProtocol:@protocol(VLCRemoteBrowsingCell)]) {
  79. [self.browsingController configureCell:(id<VLCRemoteBrowsingCell>)cell withItem:item];
  80. }
  81. }
  82. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. NSInteger row = indexPath.row;
  85. id<VLCNetworkServerBrowserItem> item = self.serverBrowser.items[row];
  86. // would make sence if item came from search which isn't
  87. // currently the case on the TV
  88. const BOOL singlePlayback = NO;
  89. [self didSelectItem:item index:row singlePlayback:singlePlayback];
  90. }
  91. @end