VLCDiscoveryListViewController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*****************************************************************************
  2. * VLCDiscoveryListViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCDiscoveryListViewController.h"
  13. #import "VLCNetworkListCell.h"
  14. #import "VLCPlaybackController.h"
  15. @interface VLCDiscoveryListViewController () <UITableViewDataSource, UITableViewDelegate, VLCMediaListDelegate>
  16. {
  17. VLCMediaList *_mediaList;
  18. VLCMedia *_rootMedia;
  19. NSDictionary *_mediaOptions;
  20. }
  21. @end
  22. @implementation VLCDiscoveryListViewController
  23. - (instancetype)initWithMedia:(VLCMedia *)media options:(NSDictionary *)options
  24. {
  25. self = [super init];
  26. if (!self)
  27. return self;
  28. _rootMedia = media;
  29. [_rootMedia parseWithOptions:VLCMediaParseNetwork];
  30. _mediaList = [_rootMedia subitems];
  31. _mediaList.delegate = self;
  32. self.title = [_rootMedia metadataForKey:VLCMetaInformationTitle];
  33. return self;
  34. }
  35. - (void)viewWillAppear:(BOOL)animated
  36. {
  37. [self.tableView reloadData];
  38. }
  39. #pragma mark - media list delegate
  40. - (void)mediaList:(VLCMediaList *)aMediaList mediaAdded:(VLCMedia *)media atIndex:(NSInteger)index
  41. {
  42. [media parseWithOptions:VLCMediaParseNetwork];
  43. [self.tableView reloadData];
  44. }
  45. - (void)mediaList:(VLCMediaList *)aMediaList mediaRemovedAtIndex:(NSInteger)index
  46. {
  47. [self.tableView reloadData];
  48. }
  49. #pragma mark - table view data source, for more see super
  50. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  51. {
  52. return _mediaList.count;
  53. }
  54. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  55. {
  56. VLCNetworkListCell *cell = (VLCNetworkListCell *)[tableView dequeueReusableCellWithIdentifier:VLCNetworkListCellIdentifier];
  57. if (cell == nil)
  58. cell = [VLCNetworkListCell cellWithReuseIdentifier:VLCNetworkListCellIdentifier];
  59. VLCMedia *cellObject = [_mediaList mediaAtIndex:indexPath.row];
  60. if (cellObject.mediaType == VLCMediaTypeDirectory) {
  61. cell.isDirectory = YES;
  62. cell.icon = [UIImage imageNamed:@"folder"];
  63. } else {
  64. cell.isDirectory = NO;
  65. cell.icon = [UIImage imageNamed:@"blank"];
  66. }
  67. cell.isDownloadable = NO;
  68. NSString *title = [cellObject metadataForKey:VLCMetaInformationTitle];
  69. if (!title)
  70. title = cellObject.url.lastPathComponent;
  71. if (!title)
  72. title = cellObject.url.absoluteString;
  73. cell.title = [cellObject metadataForKey:VLCMetaInformationTitle];
  74. cell.subtitle = cellObject.url.absoluteString;
  75. return cell;
  76. }
  77. #pragma mark - table view delegation
  78. - (void)tableView:(nonnull UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  79. {
  80. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  81. NSInteger row = indexPath.row;
  82. VLCMedia *cellMedia = [_mediaList mediaAtIndex:row];
  83. if (cellMedia.mediaType == VLCMediaTypeDirectory) {
  84. [cellMedia parseWithOptions:VLCMediaParseNetwork];
  85. [cellMedia addOptions:_mediaOptions];
  86. VLCDiscoveryListViewController *targetViewController = [[VLCDiscoveryListViewController alloc]
  87. initWithMedia:cellMedia
  88. options:_mediaOptions];
  89. [[self navigationController] pushViewController:targetViewController animated:YES];
  90. } else {
  91. VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
  92. [vpc playMediaList:_mediaList firstIndex:(int)row];
  93. }
  94. }
  95. @end